Refactor detail page for photos excluded from feeds
This commit is contained in:
parent
6e76207708
commit
8eeda8d84e
@ -11,20 +11,29 @@ import {
|
||||
absolutePathForPhotoImage,
|
||||
} from '@/app/paths';
|
||||
import PhotoDetailPage from '@/photo/PhotoDetailPage';
|
||||
import { getPhotosNearIdCached } from '@/photo/cache';
|
||||
import { getPhotoCached, getPhotosNearIdCached } from '@/photo/cache';
|
||||
import { cache } from 'react';
|
||||
import { staticallyGeneratePhotosIfConfigured } from '@/app/static';
|
||||
|
||||
export const maxDuration = 60;
|
||||
|
||||
const getPhotosNearIdCachedCached = cache((photoId: string) =>
|
||||
getPhotosNearIdCached(
|
||||
const getPhotosNearIdCachedCached = cache(async (photoId: string) => {
|
||||
const photo = await getPhotoCached(photoId);
|
||||
// Omit related photos when photo is excluded from feeds
|
||||
return photo?.excludeFromFeeds
|
||||
? {
|
||||
photo: photo,
|
||||
photos: [],
|
||||
photosGrid: [],
|
||||
indexNumber: 0,
|
||||
}
|
||||
:getPhotosNearIdCached(
|
||||
photoId, {
|
||||
limit: RELATED_GRID_PHOTOS_TO_SHOW + 2,
|
||||
excludeFromFeeds: true,
|
||||
},
|
||||
// Don't show photo in context when excluded from feeds
|
||||
true,
|
||||
));
|
||||
);
|
||||
});
|
||||
|
||||
export const generateStaticParams = staticallyGeneratePhotosIfConfigured(
|
||||
'page',
|
||||
|
||||
@ -179,15 +179,11 @@ export const getPhotosNearIdCached = (
|
||||
getPhotosNearId,
|
||||
[KEY_PHOTOS, ...getPhotosCacheKeys(args[1])],
|
||||
)(...args).then(({ photos, indexNumber }) => {
|
||||
const [photoId, { limit }, excludeFromFeeds] = args;
|
||||
const [photoId, { limit }] = args;
|
||||
const photo = photos.find(({ id }) => id === photoId);
|
||||
const isPhotoFirst = photos.findIndex(p => p.id === photoId) === 0;
|
||||
return {
|
||||
photo: photo ? parseCachedPhotoDates(photo) : undefined,
|
||||
// Don't show photo in context when excluded from feeds
|
||||
...excludeFromFeeds && photo?.excludeFromFeeds
|
||||
? { photos: [] }
|
||||
: {
|
||||
photos: parseCachedPhotosDates(photos),
|
||||
...limit && {
|
||||
photosGrid: photos.slice(
|
||||
@ -195,7 +191,6 @@ export const getPhotosNearIdCached = (
|
||||
isPhotoFirst ? limit - 1 : limit,
|
||||
),
|
||||
},
|
||||
},
|
||||
indexNumber,
|
||||
};
|
||||
});
|
||||
|
||||
@ -531,7 +531,6 @@ export const getPhotos = async (options: PhotoQueryOptions = {}) =>
|
||||
export const getPhotosNearId = async (
|
||||
photoId: string,
|
||||
options: PhotoQueryOptions,
|
||||
excludeFromFeeds?: boolean,
|
||||
) =>
|
||||
safelyQueryPhotos(async () => {
|
||||
const { limit } = options;
|
||||
@ -566,7 +565,6 @@ export const getPhotosNearId = async (
|
||||
return {
|
||||
photos: rows.map(parsePhotoFromDb),
|
||||
indexNumber,
|
||||
excludeFromFeeds,
|
||||
};
|
||||
});
|
||||
}, `getPhotosNearId: ${photoId}`);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user