53 lines
1.7 KiB
TypeScript
Raw Permalink Normal View History

2023-07-30 21:43:09 +02:00
import { MainLayout } from "@components/layouts/main.tsx";
2023-08-01 17:50:00 +02:00
import { getAllMovies, Movie } from "@lib/resource/movies.ts";
2023-08-12 18:32:56 +02:00
import { ResourceCard } from "@components/Card.tsx";
2023-08-02 01:58:03 +02:00
import { Grid } from "@components/Grid.tsx";
2023-08-02 13:11:17 +02:00
import { IconArrowLeft } from "@components/icons.tsx";
import { KMenu } from "@islands/KMenu.tsx";
2023-08-07 14:44:04 +02:00
import { RedirectSearchHandler } from "@islands/Search.tsx";
2023-08-10 16:59:18 +02:00
import { parseResourceUrl, searchResource } from "@lib/search.ts";
2025-01-05 23:14:19 +01:00
import { GenericResource } from "@lib/types.ts";
2023-09-08 13:33:29 +02:00
import { PageProps } from "$fresh/server.ts";
2023-07-30 23:55:51 +02:00
2023-09-08 13:33:29 +02:00
export default async function Greet(
2025-01-05 23:14:19 +01:00
props: PageProps<
{ movies: Movie[] | null; searchResults: GenericResource[] }
>,
2023-08-10 16:59:18 +02:00
) {
2023-09-08 13:33:29 +02:00
const allMovies = await getAllMovies();
const searchParams = parseResourceUrl(props.url);
const searchResults = searchParams &&
2025-01-05 23:14:19 +01:00
await searchResource({ ...searchParams, types: ["movie"] });
2023-09-08 13:33:29 +02:00
const movies = allMovies.sort((a, b) =>
a?.meta?.rating > b?.meta?.rating ? -1 : 1
);
2023-08-10 16:59:18 +02:00
2023-07-30 21:43:09 +02:00
return (
2023-08-10 16:59:18 +02:00
<MainLayout
url={props.url}
title="Movies"
context={{ type: "movie" }}
searchResults={searchResults}
>
2023-08-07 14:44:04 +02:00
<RedirectSearchHandler />
<KMenu type="main" context={{ type: "movie" }} />
2023-07-30 21:43:09 +02:00
<header class="flex gap-4 items-center mb-5 md:hidden">
<a
class="px-4 ml-4 py-2 bg-gray-300 text-gray-800 rounded-lg flex items-center gap-1"
href="/"
>
<IconArrowLeft class="w-5 h-5" />
Back
</a>
2023-07-30 23:55:51 +02:00
<h3 class="text-2xl text-white font-light">🍿 Movies</h3>
2023-07-30 21:43:09 +02:00
</header>
2023-08-02 01:58:03 +02:00
<Grid>
2023-08-10 16:59:18 +02:00
{movies?.map((doc) => {
2023-08-12 18:32:56 +02:00
return <ResourceCard res={doc} />;
2023-07-30 21:43:09 +02:00
})}
2023-08-02 01:58:03 +02:00
</Grid>
2023-07-30 21:43:09 +02:00
</MainLayout>
);
}