From 16c540181d15cb9af08227df6cde71b01700a635 Mon Sep 17 00:00:00 2001 From: DrMint Date: Sun, 22 May 2022 20:43:17 +0200 Subject: [PATCH] Improved the input for the pages --- src/components/Inputs/WithLabel.tsx | 25 ++++++++ src/pages/contents/index.tsx | 55 ++++++++--------- src/pages/library/index.tsx | 95 ++++++++++++++++------------- src/pages/news/index.tsx | 51 ++++++++++++++-- 4 files changed, 149 insertions(+), 77 deletions(-) create mode 100644 src/components/Inputs/WithLabel.tsx diff --git a/src/components/Inputs/WithLabel.tsx b/src/components/Inputs/WithLabel.tsx new file mode 100644 index 0000000..0b02bce --- /dev/null +++ b/src/components/Inputs/WithLabel.tsx @@ -0,0 +1,25 @@ +import { Immutable } from "helpers/types"; + +interface Props { + label: string | null | undefined; + input: JSX.Element; + disabled?: boolean; +} + +export function WithLabel(props: Immutable): JSX.Element { + const { label, input, disabled } = props; + return ( +
+ {label && ( +

+ {label}: +

+ )} + {input} +
+ ); +} diff --git a/src/pages/contents/index.tsx b/src/pages/contents/index.tsx index d7f9fbc..55d5f4c 100644 --- a/src/pages/contents/index.tsx +++ b/src/pages/contents/index.tsx @@ -17,6 +17,7 @@ import { Immutable } from "helpers/types"; import { GetStaticPropsContext } from "next"; import { Fragment, useEffect, useState } from "react"; import { Icon } from "components/Ico"; +import { WithLabel } from "components/Inputs/WithLabel"; interface Props extends AppStaticProps { contents: NonNullable["data"]; @@ -83,36 +84,34 @@ export default function Contents(props: Immutable): JSX.Element { }} /> -
-

{langui.group_by}:

- -
+ + } + /> -
-

{langui.order_by}:

- { + const input = event.target as HTMLInputElement; + setSearchName(input.value); + }} + /> + + } + /> ); @@ -47,7 +69,7 @@ export default function News(props: Immutable): JSX.Element { className="grid grid-cols-1 items-end gap-8 desktop:grid-cols-[repeat(auto-fill,_minmax(20rem,1fr))]" > - {posts.map((post) => ( + {filteredItems.map((post) => ( {post.attributes && ( ): JSX.Element { navTitle={langui.news} subPanel={subPanel} contentPanel={contentPanel} + subPanelIcon={Icon.Search} {...props} /> ); @@ -115,3 +138,19 @@ function sortPosts( .reverse(); return sortedPosts as Immutable; } + +function filterItems(posts: Immutable, searchName: string) { + return [...posts].filter((post) => { + if (searchName.length > 1) { + if ( + post.attributes?.translations?.[0]?.title + .toLowerCase() + .includes(searchName.toLowerCase()) + ) { + return true; + } + return false; + } + return true; + }); +}