Added movie page. Added stash button to movies.
This commit is contained in:
60
pages/movies/@movieId/+onBeforeRender.js
Normal file
60
pages/movies/@movieId/+onBeforeRender.js
Normal file
@@ -0,0 +1,60 @@
|
||||
import { render } from 'vike/abort'; /* eslint-disable-line import/extensions */
|
||||
|
||||
import { fetchMoviesById } from '#/src/movies.js';
|
||||
import { fetchScenes } from '#/src/scenes.js';
|
||||
import { curateScenesQuery } from '#/src/web/scenes.js';
|
||||
|
||||
function getTitle(movie) {
|
||||
if (movie.title) {
|
||||
return movie.title;
|
||||
}
|
||||
|
||||
if (movie.actors.length > 0) {
|
||||
return `Movie with ${movie.actors.map((actor) => actor.name).join(', ')}`;
|
||||
}
|
||||
|
||||
return 'Movie';
|
||||
}
|
||||
|
||||
export async function onBeforeRender(pageContext) {
|
||||
const [[movie], movieScenes] = await Promise.all([
|
||||
fetchMoviesById([Number(pageContext.routeParams.movieId)], pageContext.user),
|
||||
fetchScenes(await curateScenesQuery({
|
||||
...pageContext.urlQuery,
|
||||
scope: pageContext.routeParams.scope || 'latest',
|
||||
movieId: Number(pageContext.routeParams.movieId),
|
||||
}), {
|
||||
page: Number(pageContext.routeParams.page) || 1,
|
||||
limit: Number(pageContext.urlParsed.search.limit) || 30,
|
||||
aggregate: true,
|
||||
}, pageContext.user),
|
||||
]);
|
||||
|
||||
if (!movie) {
|
||||
throw render(404, `Cannot find movie '${pageContext.routeParams.movieId}'.`);
|
||||
}
|
||||
|
||||
const {
|
||||
scenes,
|
||||
aggActors,
|
||||
aggTags,
|
||||
aggChannels,
|
||||
total,
|
||||
limit,
|
||||
} = movieScenes;
|
||||
|
||||
return {
|
||||
pageContext: {
|
||||
title: getTitle(movie),
|
||||
pageProps: {
|
||||
movie,
|
||||
scenes,
|
||||
aggActors,
|
||||
aggTags,
|
||||
aggChannels,
|
||||
total,
|
||||
limit,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user