feat: structure 2
This commit is contained in:
81
frontend/src/store/photoStore.ts
Normal file
81
frontend/src/store/photoStore.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import { create } from 'zustand'
|
||||
|
||||
interface Photo {
|
||||
id: string
|
||||
filename: string
|
||||
filepath: string
|
||||
media_type: string
|
||||
width?: number
|
||||
height?: number
|
||||
taken_at?: string
|
||||
thumb_small?: string
|
||||
thumb_medium?: string
|
||||
thumb_large?: string
|
||||
rating: number
|
||||
is_picked: boolean
|
||||
is_rejected: boolean
|
||||
}
|
||||
|
||||
interface PhotoStore {
|
||||
photos: Photo[]
|
||||
selectedPhotos: string[]
|
||||
activePhotoId: string | null
|
||||
lastSelectedIndex: number | null
|
||||
rangeStartIndex: number | null
|
||||
|
||||
setPhotos: (photos: Photo[]) => void
|
||||
selectPhoto: (id: string, index: number) => void
|
||||
togglePhotoSelection: (id: string, index: number) => void
|
||||
selectRange: (endIndex: number) => void
|
||||
deselectPhoto: (id: string) => void
|
||||
clearSelection: () => void
|
||||
setActivePhoto: (id: string | null) => void
|
||||
}
|
||||
|
||||
export const usePhotoStore = create<PhotoStore>((set) => ({
|
||||
photos: [],
|
||||
selectedPhotos: [],
|
||||
activePhotoId: null,
|
||||
lastSelectedIndex: null,
|
||||
rangeStartIndex: null,
|
||||
|
||||
setPhotos: (photos) => set({ photos }),
|
||||
|
||||
selectPhoto: (id, index) => set({
|
||||
selectedPhotos: [id],
|
||||
activePhotoId: id,
|
||||
lastSelectedIndex: index,
|
||||
rangeStartIndex: index,
|
||||
}),
|
||||
|
||||
togglePhotoSelection: (id, index) => set((state) => {
|
||||
const isSelected = state.selectedPhotos.includes(id)
|
||||
return {
|
||||
selectedPhotos: isSelected
|
||||
? state.selectedPhotos.filter(photoId => photoId !== id)
|
||||
: [...state.selectedPhotos, id],
|
||||
lastSelectedIndex: index,
|
||||
rangeStartIndex: isSelected ? state.rangeStartIndex : index,
|
||||
}
|
||||
}),
|
||||
|
||||
selectRange: (endIndex) => {
|
||||
// Note: The actual range selection logic should be handled in the Timeline component
|
||||
// which has access to the photos array
|
||||
set({
|
||||
lastSelectedIndex: endIndex,
|
||||
})
|
||||
},
|
||||
|
||||
deselectPhoto: (id) => set((state) => ({
|
||||
selectedPhotos: state.selectedPhotos.filter(photoId => photoId !== id)
|
||||
})),
|
||||
|
||||
clearSelection: () => set({
|
||||
selectedPhotos: [],
|
||||
lastSelectedIndex: null,
|
||||
rangeStartIndex: null,
|
||||
}),
|
||||
|
||||
setActivePhoto: (id) => set({ activePhotoId: id }),
|
||||
}))
|
||||
Reference in New Issue
Block a user