This commit is contained in:
@ -33,14 +33,14 @@ export default function HomePage() {
|
|||||||
if (activeCategory === "all") {
|
if (activeCategory === "all") {
|
||||||
return photos
|
return photos
|
||||||
}
|
}
|
||||||
return photos.filter((photo) => photo.category === activeCategory)
|
return photos.filter((photo: Photo) => photo.category === activeCategory)
|
||||||
}, [photos, activeCategory])
|
}, [photos, activeCategory])
|
||||||
|
|
||||||
const handleFilter = (category: string) => {
|
const handleFilter = (category: string) => {
|
||||||
setActiveCategory(category)
|
setActiveCategory(category)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handlePhotoClick = (photo: any) => {
|
const handlePhotoClick = (photo: Photo) => {
|
||||||
setSelectedPhoto(photo)
|
setSelectedPhoto(photo)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ export default function HomePage() {
|
|||||||
const handlePrevPhoto = () => {
|
const handlePrevPhoto = () => {
|
||||||
if (!selectedPhoto) return
|
if (!selectedPhoto) return
|
||||||
const currentPhotos = activeTab === "gallery" ? filteredPhotos : photos
|
const currentPhotos = activeTab === "gallery" ? filteredPhotos : photos
|
||||||
const currentIndex = currentPhotos.findIndex((p) => p.id === selectedPhoto.id)
|
const currentIndex = currentPhotos.findIndex((p: Photo) => p.id === selectedPhoto.id)
|
||||||
const prevIndex = currentIndex > 0 ? currentIndex - 1 : currentPhotos.length - 1
|
const prevIndex = currentIndex > 0 ? currentIndex - 1 : currentPhotos.length - 1
|
||||||
setSelectedPhoto(currentPhotos[prevIndex])
|
setSelectedPhoto(currentPhotos[prevIndex])
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ export default function HomePage() {
|
|||||||
const handleNextPhoto = () => {
|
const handleNextPhoto = () => {
|
||||||
if (!selectedPhoto) return
|
if (!selectedPhoto) return
|
||||||
const currentPhotos = activeTab === "gallery" ? filteredPhotos : photos
|
const currentPhotos = activeTab === "gallery" ? filteredPhotos : photos
|
||||||
const currentIndex = currentPhotos.findIndex((p) => p.id === selectedPhoto.id)
|
const currentIndex = currentPhotos.findIndex((p: Photo) => p.id === selectedPhoto.id)
|
||||||
const nextIndex = currentIndex < currentPhotos.length - 1 ? currentIndex + 1 : 0
|
const nextIndex = currentIndex < currentPhotos.length - 1 ? currentIndex + 1 : 0
|
||||||
setSelectedPhoto(currentPhotos[nextIndex])
|
setSelectedPhoto(currentPhotos[nextIndex])
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,7 +29,7 @@ export const queryKeys = {
|
|||||||
export const usePhotos = () => {
|
export const usePhotos = () => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: queryKeys.photos,
|
queryKey: queryKeys.photos,
|
||||||
queryFn: () => api.get('/photos'),
|
queryFn: (): Promise<Photo[]> => api.get('/photos'),
|
||||||
staleTime: 5 * 60 * 1000, // 5分钟内不重新获取
|
staleTime: 5 * 60 * 1000, // 5分钟内不重新获取
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -38,7 +38,7 @@ export const usePhotos = () => {
|
|||||||
export const usePhoto = (id: number) => {
|
export const usePhoto = (id: number) => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: queryKeys.photo(id),
|
queryKey: queryKeys.photo(id),
|
||||||
queryFn: () => api.get(`/photos/${id}`),
|
queryFn: (): Promise<Photo> => api.get(`/photos/${id}`),
|
||||||
enabled: !!id,
|
enabled: !!id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@ export const usePhoto = (id: number) => {
|
|||||||
export const useCategories = () => {
|
export const useCategories = () => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: queryKeys.categories,
|
queryKey: queryKeys.categories,
|
||||||
queryFn: () => api.get('/categories'),
|
queryFn: (): Promise<string[]> => api.get('/categories'),
|
||||||
staleTime: 10 * 60 * 1000, // 10分钟内不重新获取
|
staleTime: 10 * 60 * 1000, // 10分钟内不重新获取
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user