From 35c889d38943e386fc24bf2e2099e89b6c06a6c3 Mon Sep 17 00:00:00 2001 From: DrMint Date: Fri, 11 Mar 2022 01:06:20 +0100 Subject: [PATCH] Added grouping for Contents --- src/pages/contents/index.tsx | 123 ++++++++++++++++++++++++++++++++--- src/pages/library/index.tsx | 11 +++- 2 files changed, 122 insertions(+), 12 deletions(-) diff --git a/src/pages/contents/index.tsx b/src/pages/contents/index.tsx index d899665..be8b767 100644 --- a/src/pages/contents/index.tsx +++ b/src/pages/contents/index.tsx @@ -8,15 +8,30 @@ import { getContents } from "graphql/operations"; import PanelHeader from "components/PanelComponents/PanelHeader"; import AppLayout from "components/AppLayout"; import LibraryContentPreview from "components/Library/LibraryContentPreview"; -import { prettyinlineTitle } from "queries/helpers"; +import { prettyinlineTitle, prettySlug } from "queries/helpers"; import { AppStaticProps, getAppStaticProps } from "queries/getAppStaticProps"; +import Select from "components/Select"; +import { useEffect, useState } from "react"; -interface LibraryProps extends AppStaticProps { +interface ContentsProps extends AppStaticProps { contents: GetContentsQuery["contents"]["data"]; } -export default function Library(props: LibraryProps): JSX.Element { - const { langui } = props; +type GroupContentItems = Map; + +export default function Contents(props: ContentsProps): JSX.Element { + const { langui, contents } = props; + + const [groupingMethod, setGroupingMethod] = useState(-1); + + const [groups, setGroups] = useState( + getGroups(groupingMethod, contents) + ); + + useEffect(() => { + setGroups(getGroups(groupingMethod, contents)); + }, [langui, groupingMethod, contents]); + const subPanel = ( + +
+

{langui.group_by}:

+