From 19c3f44d9a803f47e2455340578b40e0e2e3f3c9 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Tue, 14 Mar 2023 11:55:36 +0900 Subject: [PATCH] Header --- front/packages/ui/src/browse/header.tsx | 143 ++++++++++--------- front/packages/ui/src/browse/index.tsx | 19 +-- front/packages/ui/src/fetch-infinite.tsx | 2 +- front/packages/ui/src/fetch-infinite.web.tsx | 12 +- 4 files changed, 100 insertions(+), 76 deletions(-) diff --git a/front/packages/ui/src/browse/header.tsx b/front/packages/ui/src/browse/header.tsx index 1bba9361..3211daf1 100644 --- a/front/packages/ui/src/browse/header.tsx +++ b/front/packages/ui/src/browse/header.tsx @@ -18,7 +18,13 @@ * along with Kyoo. If not, see . */ -export {} +import { IconButton, tooltip, ts } from "@kyoo/primitives"; +import { View } from "moti"; +import { useTranslation } from "react-i18next"; +import { useYoshiki } from "yoshiki/native"; +import GridView from "@material-symbols/svg-400/rounded/grid_view.svg"; +import ViewList from "@material-symbols/svg-400/rounded/view_list.svg"; +import { Layout, SortBy, SortOrd } from "./types"; // const SortByMenu = ({ // sortKey, @@ -37,7 +43,7 @@ export {} // }) => { // const router = useRouter(); // const { t } = useTranslation("browse"); - +// // return ( // void; -// sortOrd: SortOrd; -// setSortOrd: (sort: SortOrd) => void; -// layout: Layout; -// setLayout: (layout: Layout) => void; -// }) => { -// const [sortAnchor, setSortAnchor] = useState(null); -// const { t } = useTranslation("browse"); +export const BrowseSettings = ({ + sortKey, + setSort, + sortOrd, + setSortOrd, + layout, + setLayout, +}: { + sortKey: SortBy; + setSort: (sort: SortBy) => void; + sortOrd: SortOrd; + setSortOrd: (sort: SortOrd) => void; + layout: Layout; + setLayout: (layout: Layout) => void; +}) => { + // const [sortAnchor, setSortAnchor] = useState(null); + const { css } = useYoshiki(); + const { t } = useTranslation(); -// const switchViewTitle = -// layout === Layout.Grid ? t("browse.switchToList") : t("browse.switchToGrid"); + return ( + + setLayout(Layout.Grid)} + {...tooltip(t("browse.switchToGrid"))} + {...css({ paddingX: ts(.5) })} + /> + setLayout(Layout.List)} + {...tooltip(t("browse.switchToList"))} + {...css({ paddingX: ts(.5) })} + /> + + ); -// return ( -// <> -// -// -// -// -// -// -// -// -// -// -// -// {sortAnchor && ( -// setSortAnchor(null)} -// /> -// )} -// -// ); -// }; + // return ( + // <> + // + // + // + // + // + // + // + // + // {sortAnchor && ( + // setSortAnchor(null)} + // /> + // )} + // + // ); +}; diff --git a/front/packages/ui/src/browse/index.tsx b/front/packages/ui/src/browse/index.tsx index e668aca7..28f10635 100644 --- a/front/packages/ui/src/browse/index.tsx +++ b/front/packages/ui/src/browse/index.tsx @@ -33,6 +33,7 @@ import { InfiniteFetch } from "../fetch-infinite"; import { ItemGrid } from "./grid"; import { ItemList } from "./list"; import { SortBy, SortOrd, Layout } from "./types"; +import { BrowseSettings } from "./header"; export const itemMap = ( item: WithLoading, @@ -80,18 +81,20 @@ export const BrowsePage: QueryPage<{ slug?: string }> = ({ slug }) => { // TODO list header to seet sort things, filter and layout. return ( <> - {/* */} + } > {(item) => } diff --git a/front/packages/ui/src/fetch-infinite.tsx b/front/packages/ui/src/fetch-infinite.tsx index c34fcdb2..28b00826 100644 --- a/front/packages/ui/src/fetch-infinite.tsx +++ b/front/packages/ui/src/fetch-infinite.tsx @@ -47,7 +47,7 @@ export const InfiniteFetch = ({ empty?: string | JSX.Element; suspense?: boolean; divider?: boolean | ComponentType; - Header?: ComponentType<{ children: JSX.Element }>; + Header?: ComponentType<{ children: JSX.Element }> | ReactElement; }): JSX.Element | null => { if (!query.infinite) console.warn("A non infinite query was passed to an InfiniteFetch."); diff --git a/front/packages/ui/src/fetch-infinite.web.tsx b/front/packages/ui/src/fetch-infinite.web.tsx index 472e4ba4..0869b510 100644 --- a/front/packages/ui/src/fetch-infinite.web.tsx +++ b/front/packages/ui/src/fetch-infinite.web.tsx @@ -109,7 +109,7 @@ export const InfiniteFetch = ({ ) => ReactElement | null; empty?: string | JSX.Element; divider?: boolean | ComponentType; - Header?: ComponentType<{ children: JSX.Element }>; + Header?: ComponentType<{ children: JSX.Element }> | ReactElement; }): JSX.Element | null => { if (!query.infinite) console.warn("A non infinite query was passed to an InfiniteFetch."); @@ -148,5 +148,13 @@ export const InfiniteFetch = ({ ); - return Header ?
{list}
: list; + if (!Header) return list; + return typeof Header === "function" ? ( +
{list}
+ ) : ( + <> + {Header} + {list} + + ); };