mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-19 13:21:46 +00:00
13956804c2
- 5-table schema (journeys, entries, photos, trips, contributors) with migrations 87-91 - Trip-to-Journey sync engine with skeleton entries and photo sync - Full CRUD API for journeys, entries, photos with Immich/Synology integration - Timeline, Gallery and Map views with entry editor (markdown, mood, weather, pros/cons) - Journey frontpage with hero card, stats and trip suggestions - Public share links with token-based access and photo proxy - PDF photo book export (Polarsteps-inspired) - Dashboard redesign: mobile greeting, live trip hero, quick actions, unified card design - BottomNav profile sheet with settings/admin/logout - DayPlan mobile inline place picker - TripFormModal members management - Vacay calendar trip date indicator dots - Fix contributor photo access (403) for journey Immich/Synology photos - Trip deletion cleanup for journey skeleton entries - i18n: 231 new keys across all 14 languages (native translations, no fallbacks)
214 lines
5.5 KiB
TypeScript
214 lines
5.5 KiB
TypeScript
import { create } from 'zustand'
|
|
import { journeyApi } from '../api/client'
|
|
|
|
export interface Journey {
|
|
id: number
|
|
user_id: number
|
|
title: string
|
|
subtitle?: string | null
|
|
cover_gradient?: string | null
|
|
cover_image?: string | null
|
|
status: 'draft' | 'active' | 'completed'
|
|
created_at: number
|
|
updated_at: number
|
|
}
|
|
|
|
export interface JourneyEntry {
|
|
id: number
|
|
journey_id: number
|
|
source_trip_id?: number | null
|
|
source_place_id?: number | null
|
|
source_trip_name?: string | null
|
|
author_id: number
|
|
type: 'entry' | 'checkin' | 'skeleton'
|
|
title?: string | null
|
|
story?: string | null
|
|
entry_date: string
|
|
entry_time?: string | null
|
|
location_name?: string | null
|
|
location_lat?: number | null
|
|
location_lng?: number | null
|
|
mood?: string | null
|
|
weather?: string | null
|
|
tags?: string[]
|
|
pros_cons?: { pros: string[]; cons: string[] } | null
|
|
visibility: string
|
|
sort_order: number
|
|
photos: JourneyPhoto[]
|
|
created_at: number
|
|
updated_at: number
|
|
}
|
|
|
|
export interface JourneyPhoto {
|
|
id: number
|
|
entry_id: number
|
|
provider: 'local' | 'immich' | 'synologyphotos'
|
|
asset_id?: string | null
|
|
owner_id?: number | null
|
|
file_path?: string | null
|
|
thumbnail_path?: string | null
|
|
caption?: string | null
|
|
sort_order: number
|
|
width?: number | null
|
|
height?: number | null
|
|
shared: number
|
|
created_at: number
|
|
}
|
|
|
|
export interface JourneyTrip {
|
|
trip_id: number
|
|
added_at: number
|
|
title: string
|
|
start_date?: string | null
|
|
end_date?: string | null
|
|
cover_image?: string | null
|
|
currency?: string
|
|
place_count: number
|
|
}
|
|
|
|
export interface JourneyContributor {
|
|
journey_id: number
|
|
user_id: number
|
|
role: 'owner' | 'editor' | 'viewer'
|
|
added_at: number
|
|
username: string
|
|
avatar?: string | null
|
|
}
|
|
|
|
export interface JourneyDetail extends Journey {
|
|
entries: JourneyEntry[]
|
|
trips: JourneyTrip[]
|
|
contributors: JourneyContributor[]
|
|
stats: { entries: number; photos: number; cities: number }
|
|
}
|
|
|
|
interface JourneyState {
|
|
journeys: Journey[]
|
|
current: JourneyDetail | null
|
|
loading: boolean
|
|
|
|
loadJourneys: () => Promise<void>
|
|
loadJourney: (id: number) => Promise<void>
|
|
createJourney: (data: { title: string; subtitle?: string; trip_ids?: number[] }) => Promise<Journey>
|
|
updateJourney: (id: number, data: Record<string, unknown>) => Promise<void>
|
|
deleteJourney: (id: number) => Promise<void>
|
|
|
|
createEntry: (journeyId: number, data: Record<string, unknown>) => Promise<JourneyEntry>
|
|
updateEntry: (entryId: number, data: Record<string, unknown>) => Promise<void>
|
|
deleteEntry: (entryId: number) => Promise<void>
|
|
|
|
uploadPhotos: (entryId: number, formData: FormData) => Promise<JourneyPhoto[]>
|
|
deletePhoto: (photoId: number) => Promise<void>
|
|
|
|
clear: () => void
|
|
}
|
|
|
|
export const useJourneyStore = create<JourneyState>((set, get) => ({
|
|
journeys: [],
|
|
current: null,
|
|
loading: false,
|
|
|
|
loadJourneys: async () => {
|
|
set({ loading: true })
|
|
try {
|
|
const data = await journeyApi.list()
|
|
set({ journeys: data.journeys || [] })
|
|
} finally {
|
|
set({ loading: false })
|
|
}
|
|
},
|
|
|
|
loadJourney: async (id) => {
|
|
set({ loading: true })
|
|
try {
|
|
const data = await journeyApi.get(id)
|
|
set({ current: data })
|
|
} finally {
|
|
set({ loading: false })
|
|
}
|
|
},
|
|
|
|
createJourney: async (data) => {
|
|
const journey = await journeyApi.create(data)
|
|
set(s => ({ journeys: [journey, ...s.journeys] }))
|
|
return journey
|
|
},
|
|
|
|
updateJourney: async (id, data) => {
|
|
const updated = await journeyApi.update(id, data)
|
|
set(s => ({
|
|
journeys: s.journeys.map(j => j.id === id ? { ...j, ...updated } : j),
|
|
current: s.current?.id === id ? { ...s.current, ...updated } : s.current,
|
|
}))
|
|
},
|
|
|
|
deleteJourney: async (id) => {
|
|
await journeyApi.delete(id)
|
|
set(s => ({
|
|
journeys: s.journeys.filter(j => j.id !== id),
|
|
current: s.current?.id === id ? null : s.current,
|
|
}))
|
|
},
|
|
|
|
createEntry: async (journeyId, data) => {
|
|
const entry = await journeyApi.createEntry(journeyId, data)
|
|
entry.photos = entry.photos || []
|
|
set(s => {
|
|
if (s.current?.id !== journeyId) return s
|
|
return { current: { ...s.current, entries: [...s.current.entries, entry] } }
|
|
})
|
|
return entry
|
|
},
|
|
|
|
updateEntry: async (entryId, data) => {
|
|
const updated = await journeyApi.updateEntry(entryId, data)
|
|
set(s => {
|
|
if (!s.current) return s
|
|
return { current: { ...s.current, entries: s.current.entries.map(e => e.id === entryId ? { ...e, ...updated } : e) } }
|
|
})
|
|
},
|
|
|
|
deleteEntry: async (entryId) => {
|
|
await journeyApi.deleteEntry(entryId)
|
|
set(s => {
|
|
if (!s.current) return s
|
|
return { current: { ...s.current, entries: s.current.entries.filter(e => e.id !== entryId) } }
|
|
})
|
|
},
|
|
|
|
uploadPhotos: async (entryId, formData) => {
|
|
const data = await journeyApi.uploadPhotos(entryId, formData)
|
|
const photos = data.photos || []
|
|
set(s => {
|
|
if (!s.current) return s
|
|
return {
|
|
current: {
|
|
...s.current,
|
|
entries: s.current.entries.map(e =>
|
|
e.id === entryId ? { ...e, photos: [...(e.photos || []), ...photos] } : e
|
|
),
|
|
},
|
|
}
|
|
})
|
|
return photos
|
|
},
|
|
|
|
deletePhoto: async (photoId) => {
|
|
await journeyApi.deletePhoto(photoId)
|
|
set(s => {
|
|
if (!s.current) return s
|
|
return {
|
|
current: {
|
|
...s.current,
|
|
entries: s.current.entries.map(e => ({
|
|
...e,
|
|
photos: (e.photos || []).filter(p => p.id !== photoId),
|
|
})),
|
|
},
|
|
}
|
|
})
|
|
},
|
|
|
|
clear: () => set({ journeys: [], current: null, loading: false }),
|
|
}))
|