feat: add initial recommendation data

This commit is contained in:
2023-09-08 13:33:29 +02:00
parent 517b1ba23d
commit cc112b7554
19 changed files with 289 additions and 170 deletions

View File

@ -1,4 +1,4 @@
import { Handlers, PageProps } from "$fresh/server.ts";
import { Handlers, PageProps, RouteContext } from "$fresh/server.ts";
import { MainLayout } from "@components/layouts/main.tsx";
import { getMovie, Movie } from "@lib/resource/movies.ts";
import { RecipeHero } from "@components/RecipeHero.tsx";
@ -7,17 +7,12 @@ import { renderMarkdown } from "@lib/documents.ts";
import { KMenu } from "@islands/KMenu.tsx";
import { RedirectSearchHandler } from "@islands/Search.tsx";
export const handler: Handlers<Movie | null> = {
async GET(_, ctx) {
const movie = await getMovie(ctx.params.name);
return ctx.render({ movie, session: ctx.state.session });
},
};
export default function Greet(
export default async function Greet(
props: PageProps<{ movie: Movie; session: Record<string, string> }>,
ctx: RouteContext,
) {
const { movie, session } = props.data;
const movie = await getMovie(ctx.params.name);
const session = ctx.state.session;
const { author = "", date = "" } = movie.meta;

View File

@ -1,4 +1,3 @@
import { MainLayout } from "@components/layouts/main.tsx";
import { getAllMovies, Movie } from "@lib/resource/movies.ts";
import { ResourceCard } from "@components/Card.tsx";
@ -8,26 +7,18 @@ import { KMenu } from "@islands/KMenu.tsx";
import { RedirectSearchHandler } from "@islands/Search.tsx";
import { parseResourceUrl, searchResource } from "@lib/search.ts";
import { SearchResult } from "@lib/types.ts";
import { PageProps } from "$fresh/server.ts";
export const handler: Handlers<
{ movies: Movie[] | null; searchResults?: SearchResult }
> = {
async GET(req, ctx) {
const movies = await getAllMovies();
const searchParams = parseResourceUrl(req.url);
const searchResults = searchParams &&
await searchResource({ ...searchParams, type: "movie" });
return ctx.render({
movies: movies.sort((a, b) => a?.meta?.rating > b?.meta?.rating ? -1 : 1),
searchResults,
});
},
};
export default function Greet(
export default async function Greet(
props: PageProps<{ movies: Movie[] | null; searchResults: SearchResult }>,
) {
const { movies, searchResults } = props.data;
const allMovies = await getAllMovies();
const searchParams = parseResourceUrl(props.url);
const searchResults = searchParams &&
await searchResource({ ...searchParams, type: "movie" });
const movies = allMovies.sort((a, b) =>
a?.meta?.rating > b?.meta?.rating ? -1 : 1
);
return (
<MainLayout