54 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			54 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import { MainLayout } from "@components/layouts/main.tsx";
 | |
| import { Movie } from "@lib/resource/movies.ts";
 | |
| import { ResourceCard } from "@components/Card.tsx";
 | |
| import { Grid } from "@components/Grid.tsx";
 | |
| import { IconArrowLeft } from "@components/icons.tsx";
 | |
| import { KMenu } from "@islands/KMenu.tsx";
 | |
| import { RedirectSearchHandler } from "@islands/Search.tsx";
 | |
| import { GenericResource } from "@lib/types.ts";
 | |
| import { PageProps } from "$fresh/server.ts";
 | |
| import { fetchResource } from "@lib/resources.ts";
 | |
| import { parseResourceUrl, searchResource } from "@lib/search.ts";
 | |
| 
 | |
| export default async function Greet(
 | |
|   props: PageProps<
 | |
|     { movies: Movie[] | null; searchResults: GenericResource[] }
 | |
|   >,
 | |
| ) {
 | |
|   const { content: allMovies } = await fetchResource("movies");
 | |
|   const searchParams = parseResourceUrl(props.url);
 | |
|   const searchResults = searchParams &&
 | |
|     await searchResource({ ...searchParams, types: ["movie"] });
 | |
|   const movies = allMovies.sort((a, b) =>
 | |
|     a?.content?.reviewRating?.ratingValue > b?.content?.reviewRating?.ratingValue ? -1 : 1
 | |
|   );
 | |
| 
 | |
|   return (
 | |
|     <MainLayout
 | |
|       url={props.url}
 | |
|       title="Movies"
 | |
|       context={{ type: "movie" }}
 | |
|       searchResults={searchResults}
 | |
|     >
 | |
|       <RedirectSearchHandler />
 | |
|       <KMenu type="main" context={{ type: "movie" }} />
 | |
|       <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>
 | |
| 
 | |
|         <h3 class="text-2xl text-white font-light">🍿 Movies</h3>
 | |
|       </header>
 | |
|       <Grid>
 | |
|         {movies?.map((doc) => {
 | |
|           return <ResourceCard res={doc} />;
 | |
|         })}
 | |
|       </Grid>
 | |
|     </MainLayout>
 | |
|   );
 | |
| }
 |