memorium/routes/series/index.tsx

59 lines
1.8 KiB
TypeScript
Raw Normal View History

2023-08-07 14:44:04 +02:00
import { Handlers, PageProps } from "$fresh/server.ts";
import { MainLayout } from "@components/layouts/main.tsx";
import { Grid } from "@components/Grid.tsx";
import { IconArrowLeft } from "@components/icons.tsx";
import { getAllSeries, Series } from "@lib/resource/series.ts";
import { RedirectSearchHandler } from "@islands/Search.tsx";
import { KMenu } from "@islands/KMenu.tsx";
2023-08-12 18:32:56 +02:00
import { ResourceCard } from "@components/Card.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-08-07 14:44:04 +02:00
2023-08-12 18:32:56 +02:00
export const handler: Handlers<
2025-01-05 23:14:19 +01:00
{ series: Series[] | null; searchResults?: GenericResource[] }
2023-08-12 18:32:56 +02:00
> = {
2023-08-10 16:59:18 +02:00
async GET(req, ctx) {
const series = await getAllSeries();
const searchParams = parseResourceUrl(req.url);
const searchResults = searchParams &&
2025-01-05 23:14:19 +01:00
await searchResource({ ...searchParams, types: ["series"] });
2023-08-10 16:59:18 +02:00
return ctx.render({ series, searchResults });
2023-08-07 14:44:04 +02:00
},
};
2023-08-10 16:59:18 +02:00
export default function Greet(
2025-01-05 23:14:19 +01:00
props: PageProps<
{ series: Series[] | null; searchResults: GenericResource[] }
>,
2023-08-10 16:59:18 +02:00
) {
const { series, searchResults } = props.data;
2023-08-07 14:44:04 +02:00
return (
2023-08-10 16:59:18 +02:00
<MainLayout
url={props.url}
title="Series"
context={{ type: "series" }}
searchResults={searchResults}
>
2023-08-07 14:44:04 +02:00
<RedirectSearchHandler />
<KMenu type="main" context={{ type: "series" }} />
<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-08-08 11:18:54 +02:00
<h3 class="text-2xl text-white font-light">🎥 Series</h3>
2023-08-07 14:44:04 +02:00
</header>
<Grid>
2023-08-10 16:59:18 +02:00
{series?.map((doc) => {
2023-08-12 18:32:56 +02:00
return <ResourceCard sublink="series" res={doc} />;
2023-08-07 14:44:04 +02:00
})}
</Grid>
</MainLayout>
);
}