Added Expand All / Collapse All button for series seasons

pull/2403/head
JayZed 9 months ago committed by GitHub
parent b933eb87b9
commit 5dd001317d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -18,6 +18,8 @@ import { useLanguageProfileBy } from "@/utilities/languages";
import { import {
faAdjust, faAdjust,
faBriefcase, faBriefcase,
faCircleChevronDown,
faCircleChevronRight,
faCloudUploadAlt, faCloudUploadAlt,
faHdd, faHdd,
faSearch, faSearch,
@ -28,11 +30,23 @@ import { Container, Group, Stack } from "@mantine/core";
import { Dropzone } from "@mantine/dropzone"; import { Dropzone } from "@mantine/dropzone";
import { useDocumentTitle } from "@mantine/hooks"; import { useDocumentTitle } from "@mantine/hooks";
import { showNotification } from "@mantine/notifications"; 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 { Navigate, useParams } from "react-router-dom";
import Table from "./table"; import Table from "./table";
const SeriesEpisodesView: FunctionComponent = () => { const SeriesEpisodesView: FunctionComponent = () => {
const [state, setState] = useState({
expand: false,
buttonText: "Expand All",
initial: true,
});
const params = useParams(); const params = useParams();
const id = Number.parseInt(params.id as string); const id = Number.parseInt(params.id as string);
@ -94,6 +108,12 @@ const SeriesEpisodesView: FunctionComponent = () => {
return <Navigate to={RouterNames.NotFound}></Navigate>; return <Navigate to={RouterNames.NotFound}></Navigate>;
} }
const toggleState = () => {
state.expand
? setState({ expand: false, buttonText: "Expand All", initial: false })
: setState({ expand: true, buttonText: "Collapse All", initial: false });
};
return ( return (
<Container px={0} fluid> <Container px={0} fluid>
<QueryOverlay result={seriesQuery}> <QueryOverlay result={seriesQuery}>
@ -189,12 +209,22 @@ const SeriesEpisodesView: FunctionComponent = () => {
> >
Edit Series Edit Series
</Toolbox.Button> </Toolbox.Button>
<Toolbox.Button
icon={state.expand ? faCircleChevronRight : faCircleChevronDown}
onClick={() => {
toggleState();
}}
>
{state.buttonText}
</Toolbox.Button>
</Group> </Group>
</Toolbox> </Toolbox>
<Stack> <Stack>
<ItemOverview item={series ?? null} details={details}></ItemOverview> <ItemOverview item={series ?? null} details={details}></ItemOverview>
<QueryOverlay result={episodesQuery}> <QueryOverlay result={episodesQuery}>
<Table <Table
expand={state.expand}
initial={state.initial}
episodes={episodes ?? null} episodes={episodes ?? null}
profile={profile} profile={profile}
disabled={hasTask || !series || series.profileId === null} disabled={hasTask || !series || series.profileId === null}

@ -31,9 +31,17 @@ interface Props {
episodes: Item.Episode[] | null; episodes: Item.Episode[] | null;
disabled?: boolean; disabled?: boolean;
profile?: Language.Profile; profile?: Language.Profile;
expand?: boolean;
initial?: boolean;
} }
const Table: FunctionComponent<Props> = ({ episodes, profile, disabled }) => { const Table: FunctionComponent<Props> = ({
episodes,
profile,
disabled,
expand,
initial,
}) => {
const onlyDesired = useShowOnlyDesired(); const onlyDesired = useShowOnlyDesired();
const profileItems = useProfileItemsToLanguages(profile); const profileItems = useProfileItemsToLanguages(profile);
@ -212,9 +220,18 @@ const Table: FunctionComponent<Props> = ({ episodes, profile, disabled }) => {
useEffect(() => { useEffect(() => {
if (instance.current) { if (instance.current) {
if (initial) {
// expand the last/current season on initial display
instance.current.toggleRowExpanded([`season:${maxSeason}`], true); 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 ( return (
<GroupTable <GroupTable

Loading…
Cancel
Save