mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
Fix url not updated for default tab on Performer/Studio/Tag pages (#4538)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Button, Tabs, Tab } from "react-bootstrap";
|
||||
import React, { useEffect, useMemo, useState } from "react";
|
||||
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { useHistory, Redirect, RouteComponentProps } from "react-router-dom";
|
||||
import { FormattedMessage, useIntl } from "react-intl";
|
||||
import { Helmet } from "react-helmet";
|
||||
@@ -48,7 +48,7 @@ import { ExternalLink } from "src/components/Shared/ExternalLink";
|
||||
|
||||
interface IProps {
|
||||
studio: GQL.StudioDataFragment;
|
||||
tabKey: TabKey;
|
||||
tabKey?: TabKey;
|
||||
}
|
||||
|
||||
interface IStudioParams {
|
||||
@@ -138,9 +138,23 @@ const StudioPage: React.FC<IProps> = ({ studio, tabKey }) => {
|
||||
studio,
|
||||
]);
|
||||
|
||||
if (tabKey === defaultTab) {
|
||||
tabKey = populatedDefaultTab;
|
||||
}
|
||||
const setTabKey = useCallback(
|
||||
(newTabKey: string | null) => {
|
||||
if (!newTabKey) newTabKey = populatedDefaultTab;
|
||||
if (newTabKey === tabKey) return;
|
||||
|
||||
if (isTabKey(newTabKey)) {
|
||||
history.replace(`/studios/${studio.id}/${newTabKey}`);
|
||||
}
|
||||
},
|
||||
[populatedDefaultTab, tabKey, history, studio.id]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (tabKey === defaultTab) {
|
||||
setTabKey(populatedDefaultTab);
|
||||
}
|
||||
}, [setTabKey, populatedDefaultTab, tabKey]);
|
||||
|
||||
// set up hotkeys
|
||||
useEffect(() => {
|
||||
@@ -270,17 +284,6 @@ const StudioPage: React.FC<IProps> = ({ studio, tabKey }) => {
|
||||
}
|
||||
}
|
||||
|
||||
function setTabKey(newTabKey: string | null) {
|
||||
if (!newTabKey || newTabKey === defaultTab) newTabKey = populatedDefaultTab;
|
||||
if (newTabKey === tabKey) return;
|
||||
|
||||
if (newTabKey === populatedDefaultTab) {
|
||||
history.replace(`/studios/${studio.id}`);
|
||||
} else if (isTabKey(newTabKey)) {
|
||||
history.replace(`/studios/${studio.id}/${newTabKey}`);
|
||||
}
|
||||
}
|
||||
|
||||
const renderClickableIcons = () => (
|
||||
<span className="name-icons">
|
||||
{studio.url && (
|
||||
@@ -574,11 +577,7 @@ const StudioLoader: React.FC<RouteComponentProps<IStudioParams>> = ({
|
||||
if (!data?.findStudio)
|
||||
return <ErrorMessage error={`No studio found with id ${id}.`} />;
|
||||
|
||||
if (!tab) {
|
||||
return <StudioPage studio={data.findStudio} tabKey={defaultTab} />;
|
||||
}
|
||||
|
||||
if (!isTabKey(tab)) {
|
||||
if (tab && !isTabKey(tab)) {
|
||||
return (
|
||||
<Redirect
|
||||
to={{
|
||||
@@ -589,7 +588,9 @@ const StudioLoader: React.FC<RouteComponentProps<IStudioParams>> = ({
|
||||
);
|
||||
}
|
||||
|
||||
return <StudioPage studio={data.findStudio} tabKey={tab} />;
|
||||
return (
|
||||
<StudioPage studio={data.findStudio} tabKey={tab as TabKey | undefined} />
|
||||
);
|
||||
};
|
||||
|
||||
export default StudioLoader;
|
||||
|
||||
Reference in New Issue
Block a user