Add cache keys to photos

This commit is contained in:
Sam Becker 2024-04-25 10:06:35 -05:00
parent 7df9f4c58c
commit 1e748e0d8a
4 changed files with 21 additions and 4 deletions

View File

@ -10,6 +10,7 @@ import { usePathname } from 'next/navigation';
import { BiTrash } from 'react-icons/bi';
import MoreMenu from '@/components/MoreMenu';
import { useAppState } from '@/state/AppState';
import { useSWRConfig } from 'swr';
export default function AdminPhotoMenuClient({
photo,
@ -24,6 +25,8 @@ export default function AdminPhotoMenuClient({
const shouldRedirectFav = isPathFavs(path) && isFav;
const shouldRedirectDelete = pathForPhoto(photo.id) === path;
const { mutate } = useSWRConfig();
return (
isUserSignedIn
? <MoreMenu {...{
@ -46,7 +49,9 @@ export default function AdminPhotoMenuClient({
action: () => toggleFavoritePhotoAction(
photo.id,
shouldRedirectFav,
),
).then(() => {
if (photo.cacheKey) { mutate( photo.cacheKey ); }
}),
}, {
label: 'Delete',
icon: <BiTrash

View File

@ -15,7 +15,7 @@ export default function InfinitePhotoScroll({
itemsPerPage = 12,
prefetch = true,
triggerOnView = true,
debug,
debug = true,
}: {
key?: string
initialOffset?: number
@ -34,6 +34,7 @@ export default function InfinitePhotoScroll({
return getPhotosAction(
initialOffset + offset * itemsPerPage,
itemsPerPage,
key,
);
}, [initialOffset, itemsPerPage, debug]);

View File

@ -220,5 +220,14 @@ export async function getPhotoItemsAction(query: string) {
: [];
}
export const getPhotosAction = async (offset: number, limit: number) =>
getPhotosCachedCached({ offset, limit });
export const getPhotosAction = async (
offset: number,
limit: number,
cacheKey: string,
) =>
getPhotosCachedCached({ offset, limit }).then(photos =>
photos.map(photo => ({
...photo,
cacheKey,
}))
);

View File

@ -64,6 +64,7 @@ export interface PhotoDbInsert extends PhotoExif {
hidden?: boolean
takenAt: string
takenAtNaive: string
cacheKey?: string
}
// Raw db response
@ -83,6 +84,7 @@ export interface Photo extends PhotoDb {
exposureTimeFormatted?: string
exposureCompensationFormatted?: string
takenAtNaiveFormatted: string
cacheKey?: string
}
export const parsePhotoFromDb = (photoDbRaw: PhotoDb): Photo => {