From a1017b740f7329783b518a2bbfb0b070d8cf003b Mon Sep 17 00:00:00 2001 From: Max Richter Date: Mon, 28 Aug 2023 21:57:37 +0200 Subject: [PATCH] feat: sort movies by rating by default --- routes/movies/index.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/routes/movies/index.tsx b/routes/movies/index.tsx index 839a8c3..33e11d3 100644 --- a/routes/movies/index.tsx +++ b/routes/movies/index.tsx @@ -1,4 +1,4 @@ -import { Handlers, PageProps } from "$fresh/server.ts"; + import { MainLayout } from "@components/layouts/main.tsx"; import { getAllMovies, Movie } from "@lib/resource/movies.ts"; import { ResourceCard } from "@components/Card.tsx"; @@ -17,7 +17,10 @@ export const handler: Handlers< const searchParams = parseResourceUrl(req.url); const searchResults = searchParams && await searchResource({ ...searchParams, type: "movie" }); - return ctx.render({ movies, searchResults }); + return ctx.render({ + movies: movies.sort((a, b) => a?.meta?.rating > b?.meta?.rating ? -1 : 1), + searchResults, + }); }, };