From c2b93676ddb5c5a5e03d403a0faf6307a58833e6 Mon Sep 17 00:00:00 2001 From: yoshnopa <40072150+yoshnopa@users.noreply.github.com> Date: Thu, 24 Aug 2023 03:08:25 +0200 Subject: [PATCH] Details pages start with populated content tab (#4032) --- .../Performers/PerformerDetails/Performer.tsx | 26 +++++++++++-- .../Studios/StudioDetails/Studio.tsx | 39 +++++++++++++++++-- .../src/components/Tags/TagDetails/Tag.tsx | 30 ++++++++++++-- 3 files changed, 84 insertions(+), 11 deletions(-) diff --git a/ui/v2.5/src/components/Performers/PerformerDetails/Performer.tsx b/ui/v2.5/src/components/Performers/PerformerDetails/Performer.tsx index c628f3ee4..8d42a6c2a 100644 --- a/ui/v2.5/src/components/Performers/PerformerDetails/Performer.tsx +++ b/ui/v2.5/src/components/Performers/PerformerDetails/Performer.tsx @@ -57,6 +57,7 @@ interface IPerformerParams { } const validTabs = [ + "default", "scenes", "galleries", "images", @@ -65,7 +66,7 @@ const validTabs = [ ] as const; type TabKey = (typeof validTabs)[number]; -const defaultTab: TabKey = "scenes"; +const defaultTab: TabKey = "default"; function isTabKey(tab: string): tab is TabKey { return validTabs.includes(tab as TabKey); @@ -117,11 +118,30 @@ const PerformerPage: React.FC = ({ performer, tabKey }) => { const [updatePerformer] = usePerformerUpdate(); const [deletePerformer, { loading: isDestroying }] = usePerformerDestroy(); + const populatedDefaultTab = useMemo(() => { + let ret: TabKey = "scenes"; + if (performer.scene_count == 0) { + if (performer.gallery_count != 0) { + ret = "galleries"; + } else if (performer.image_count != 0) { + ret = "images"; + } else if (performer.movie_count != 0) { + ret = "movies"; + } + } + + return ret; + }, [performer]); + + if (tabKey === defaultTab) { + tabKey = populatedDefaultTab; + } + function setTabKey(newTabKey: string | null) { - if (!newTabKey) newTabKey = defaultTab; + if (!newTabKey || newTabKey === defaultTab) newTabKey = populatedDefaultTab; if (newTabKey === tabKey) return; - if (newTabKey === defaultTab) { + if (newTabKey === populatedDefaultTab) { history.replace(`/performers/${performer.id}`); } else if (isTabKey(newTabKey)) { history.replace(`/performers/${performer.id}/${newTabKey}`); diff --git a/ui/v2.5/src/components/Studios/StudioDetails/Studio.tsx b/ui/v2.5/src/components/Studios/StudioDetails/Studio.tsx index d282b9294..aa404aad6 100644 --- a/ui/v2.5/src/components/Studios/StudioDetails/Studio.tsx +++ b/ui/v2.5/src/components/Studios/StudioDetails/Studio.tsx @@ -1,5 +1,5 @@ import { Button, Tabs, Tab } from "react-bootstrap"; -import React, { useEffect, useState } from "react"; +import React, { useEffect, useMemo, useState } from "react"; import { useHistory, Redirect, RouteComponentProps } from "react-router-dom"; import { FormattedMessage, useIntl } from "react-intl"; import { Helmet } from "react-helmet"; @@ -57,6 +57,7 @@ interface IStudioParams { } const validTabs = [ + "default", "scenes", "galleries", "images", @@ -66,7 +67,7 @@ const validTabs = [ ] as const; type TabKey = (typeof validTabs)[number]; -const defaultTab: TabKey = "scenes"; +const defaultTab: TabKey = "default"; function isTabKey(tab: string): tab is TabKey { return validTabs.includes(tab as TabKey); @@ -112,6 +113,36 @@ const StudioPage: React.FC = ({ studio, tabKey }) => { const movieCount = (showAllCounts ? studio.movie_count_all : studio.movie_count) ?? 0; + const populatedDefaultTab = useMemo(() => { + let ret: TabKey = "scenes"; + if (sceneCount == 0) { + if (galleryCount != 0) { + ret = "galleries"; + } else if (imageCount != 0) { + ret = "images"; + } else if (performerCount != 0) { + ret = "performers"; + } else if (movieCount != 0) { + ret = "movies"; + } else if (studio.child_studios.length != 0) { + ret = "childstudios"; + } + } + + return ret; + }, [ + sceneCount, + galleryCount, + imageCount, + performerCount, + movieCount, + studio, + ]); + + if (tabKey === defaultTab) { + tabKey = populatedDefaultTab; + } + // set up hotkeys useEffect(() => { Mousetrap.bind("e", () => toggleEditing()); @@ -243,10 +274,10 @@ const StudioPage: React.FC = ({ studio, tabKey }) => { } function setTabKey(newTabKey: string | null) { - if (!newTabKey) newTabKey = defaultTab; + if (!newTabKey || newTabKey === defaultTab) newTabKey = populatedDefaultTab; if (newTabKey === tabKey) return; - if (newTabKey === defaultTab) { + if (newTabKey === populatedDefaultTab) { history.replace(`/studios/${studio.id}`); } else if (isTabKey(newTabKey)) { history.replace(`/studios/${studio.id}/${newTabKey}`); diff --git a/ui/v2.5/src/components/Tags/TagDetails/Tag.tsx b/ui/v2.5/src/components/Tags/TagDetails/Tag.tsx index 53fcfcbee..5ba59bc87 100644 --- a/ui/v2.5/src/components/Tags/TagDetails/Tag.tsx +++ b/ui/v2.5/src/components/Tags/TagDetails/Tag.tsx @@ -1,5 +1,5 @@ import { Tabs, Tab, Dropdown, Button } from "react-bootstrap"; -import React, { useEffect, useState } from "react"; +import React, { useEffect, useMemo, useState } from "react"; import { useHistory, Redirect, RouteComponentProps } from "react-router-dom"; import { FormattedMessage, useIntl } from "react-intl"; import { Helmet } from "react-helmet"; @@ -53,6 +53,7 @@ interface ITagParams { } const validTabs = [ + "default", "scenes", "images", "galleries", @@ -61,7 +62,7 @@ const validTabs = [ ] as const; type TabKey = (typeof validTabs)[number]; -const defaultTab: TabKey = "scenes"; +const defaultTab: TabKey = "default"; function isTabKey(tab: string): tab is TabKey { return validTabs.includes(tab as TabKey); @@ -107,11 +108,32 @@ const TagPage: React.FC = ({ tag, tabKey }) => { const performerCount = (showAllCounts ? tag.performer_count_all : tag.performer_count) ?? 0; + const populatedDefaultTab = useMemo(() => { + let ret: TabKey = "scenes"; + if (sceneCount == 0) { + if (imageCount != 0) { + ret = "images"; + } else if (galleryCount != 0) { + ret = "galleries"; + } else if (sceneMarkerCount != 0) { + ret = "markers"; + } else if (performerCount != 0) { + ret = "performers"; + } + } + + return ret; + }, [sceneCount, imageCount, galleryCount, sceneMarkerCount, performerCount]); + + if (tabKey === defaultTab) { + tabKey = populatedDefaultTab; + } + function setTabKey(newTabKey: string | null) { - if (!newTabKey) newTabKey = defaultTab; + if (!newTabKey || newTabKey === defaultTab) newTabKey = populatedDefaultTab; if (newTabKey === tabKey) return; - if (newTabKey === defaultTab) { + if (newTabKey === populatedDefaultTab) { history.replace(`/tags/${tag.id}`); } else if (isTabKey(newTabKey)) { history.replace(`/tags/${tag.id}/${newTabKey}`);