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