feat: add initial recommendation data
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user