From 0cb61d14be56a34c0fdf57c6711ed7ba72ce5de9 Mon Sep 17 00:00:00 2001 From: Infinite Date: Sun, 12 Jan 2020 22:02:43 +0100 Subject: [PATCH] Remove final react-router props --- .../components/scenes/SceneDetails/Scene.tsx | 34 +++++++++---------- ui/v2.5/src/models/base-props.ts | 3 -- ui/v2.5/src/models/index.ts | 1 - 3 files changed, 16 insertions(+), 22 deletions(-) delete mode 100644 ui/v2.5/src/models/base-props.ts delete mode 100644 ui/v2.5/src/models/index.ts diff --git a/ui/v2.5/src/components/scenes/SceneDetails/Scene.tsx b/ui/v2.5/src/components/scenes/SceneDetails/Scene.tsx index d486bdd4c..04f3d0b5d 100644 --- a/ui/v2.5/src/components/scenes/SceneDetails/Scene.tsx +++ b/ui/v2.5/src/components/scenes/SceneDetails/Scene.tsx @@ -1,9 +1,9 @@ import { Card, Spinner, Tab, Tabs } from 'react-bootstrap'; import queryString from "query-string"; import React, { useEffect, useState } from "react"; +import { useParams, useLocation, useHistory } from 'react-router-dom'; import * as GQL from "src/core/generated-graphql"; import { StashService } from "src/core/StashService"; -import { IBaseProps } from "src/models"; import { GalleryViewer } from "src/components/Galleries/GalleryViewer"; import { ScenePlayer } from "../ScenePlayer/ScenePlayer"; import { SceneDetailPanel } from "./SceneDetailPanel"; @@ -12,28 +12,26 @@ import { SceneFileInfoPanel } from "./SceneFileInfoPanel"; import { SceneMarkersPanel } from "./SceneMarkersPanel"; import { ScenePerformerPanel } from "./ScenePerformerPanel"; -interface ISceneProps extends IBaseProps {} - -export const Scene: React.FC = (props: ISceneProps) => { - const [timestamp, setTimestamp] = useState(0); - const [autoplay, setAutoplay] = useState(false); +export const Scene: React.FC = () => { + const { id = 'new' } = useParams(); + const location = useLocation(); + const history = useHistory(); + const [timestamp, setTimestamp] = useState(getInitialTimestamp()); const [scene, setScene] = useState>({}); - const { data, error, loading } = StashService.useFindScene(props.match.params.id); + const { data, error, loading } = StashService.useFindScene(id); + + const queryParams = queryString.parse(location.search); + const autoplay = queryParams?.autoplay === 'true'; useEffect(() => ( setScene(data?.findScene ?? {}) ), [data]); - useEffect(() => { - const queryParams = queryString.parse(props.location.search); - if (!!queryParams.t && typeof queryParams.t === "string" && timestamp === 0) { - const newTimestamp = parseInt(queryParams.t, 10); - setTimestamp(newTimestamp); - } - if (queryParams.autoplay && typeof queryParams.autoplay === "string") { - setAutoplay(queryParams.autoplay === "true"); - } - }); + function getInitialTimestamp() { + const params = queryString.parse(location.search); + const timestamp = params?.t; + return Number.parseInt(Array.isArray(timestamp) ? timestamp[0] : timestamp ?? '0', 10); + } function onClickMarker(marker: GQL.SceneMarkerDataFragment) { setTimestamp(marker.seconds); @@ -85,7 +83,7 @@ export const Scene: React.FC = (props: ISceneProps) => { setScene(newScene)} - onDelete={() => props.history.push("/scenes")} + onDelete={() => history.push("/scenes")} /> diff --git a/ui/v2.5/src/models/base-props.ts b/ui/v2.5/src/models/base-props.ts deleted file mode 100644 index fe76c81e3..000000000 --- a/ui/v2.5/src/models/base-props.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { RouteComponentProps } from "react-router"; - -export interface IBaseProps extends RouteComponentProps {} diff --git a/ui/v2.5/src/models/index.ts b/ui/v2.5/src/models/index.ts deleted file mode 100644 index 0e1646573..000000000 --- a/ui/v2.5/src/models/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./base-props";