From 5dd001317dc6e88885b392f9fe5107e324593f99 Mon Sep 17 00:00:00 2001 From: JayZed Date: Mon, 19 Feb 2024 21:02:18 -0500 Subject: [PATCH] Added Expand All / Collapse All button for series seasons --- frontend/src/pages/Episodes/index.tsx | 32 ++++++++++++++++++++++++++- frontend/src/pages/Episodes/table.tsx | 23 ++++++++++++++++--- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/frontend/src/pages/Episodes/index.tsx b/frontend/src/pages/Episodes/index.tsx index 3aaee0729..7a50f40c6 100644 --- a/frontend/src/pages/Episodes/index.tsx +++ b/frontend/src/pages/Episodes/index.tsx @@ -18,6 +18,8 @@ import { useLanguageProfileBy } from "@/utilities/languages"; import { faAdjust, faBriefcase, + faCircleChevronDown, + faCircleChevronRight, faCloudUploadAlt, faHdd, faSearch, @@ -28,11 +30,23 @@ import { Container, Group, Stack } from "@mantine/core"; import { Dropzone } from "@mantine/dropzone"; import { useDocumentTitle } from "@mantine/hooks"; import { showNotification } from "@mantine/notifications"; -import { FunctionComponent, useCallback, useMemo, useRef } from "react"; +import { + FunctionComponent, + useCallback, + useMemo, + useRef, + useState, +} from "react"; import { Navigate, useParams } from "react-router-dom"; import Table from "./table"; const SeriesEpisodesView: FunctionComponent = () => { + const [state, setState] = useState({ + expand: false, + buttonText: "Expand All", + initial: true, + }); + const params = useParams(); const id = Number.parseInt(params.id as string); @@ -94,6 +108,12 @@ const SeriesEpisodesView: FunctionComponent = () => { return ; } + const toggleState = () => { + state.expand + ? setState({ expand: false, buttonText: "Expand All", initial: false }) + : setState({ expand: true, buttonText: "Collapse All", initial: false }); + }; + return ( @@ -189,12 +209,22 @@ const SeriesEpisodesView: FunctionComponent = () => { > Edit Series + { + toggleState(); + }} + > + {state.buttonText} + = ({ episodes, profile, disabled }) => { +const Table: FunctionComponent = ({ + episodes, + profile, + disabled, + expand, + initial, +}) => { const onlyDesired = useShowOnlyDesired(); const profileItems = useProfileItemsToLanguages(profile); @@ -212,9 +220,18 @@ const Table: FunctionComponent = ({ episodes, profile, disabled }) => { useEffect(() => { if (instance.current) { - instance.current.toggleRowExpanded([`season:${maxSeason}`], true); + if (initial) { + // expand the last/current season on initial display + instance.current.toggleRowExpanded([`season:${maxSeason}`], true); + // make sure season 0 is collapsed + instance.current.toggleRowExpanded([`season:0`], false); + } else { + if (expand !== undefined) { + instance.current.toggleAllRowsExpanded(expand); + } + } } - }, [maxSeason]); + }, [maxSeason, expand, initial]); return (