From df5735cfbf719d9cd90b19fcfc6054b1048e8dc0 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Thu, 26 Oct 2023 19:53:22 +0200 Subject: [PATCH] pwa fix and dont remove t param after use --- src/components/player/atoms/Episodes.tsx | 4 +++- src/hooks/useOverlayRouter.ts | 11 +++++++---- src/hooks/useQueryParams.ts | 2 +- src/pages/PlayerView.tsx | 11 +++++------ vite.config.ts | 1 + 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/components/player/atoms/Episodes.tsx b/src/components/player/atoms/Episodes.tsx index f79e2081..d69b9275 100644 --- a/src/components/player/atoms/Episodes.tsx +++ b/src/components/player/atoms/Episodes.tsx @@ -109,7 +109,9 @@ function EpisodesView({ const newData = setPlayerMeta(loadingState.value.fullData, episodeId); if (newData) onChange?.(newData); } - router.close(); + // prevent router clear here, otherwise its done double + // player already switches route after meta change + router.close(true); }, [setPlayerMeta, loadingState, router, onChange] ); diff --git a/src/hooks/useOverlayRouter.ts b/src/hooks/useOverlayRouter.ts index 33c31431..3c46fc6c 100644 --- a/src/hooks/useOverlayRouter.ts +++ b/src/hooks/useOverlayRouter.ts @@ -91,10 +91,13 @@ export function useInternalOverlayRouter(id: string) { return routerActive; } - const close = useCallback(() => { - if (route) setRoute(null); - setTransition(null); - }, [setRoute, route, setTransition]); + const close = useCallback( + (preventRouteClear?: boolean) => { + if (route && !preventRouteClear) setRoute(null); + setTransition(null); + }, + [setRoute, route, setTransition] + ); const open = useCallback( (defaultRoute = "/") => { diff --git a/src/hooks/useQueryParams.ts b/src/hooks/useQueryParams.ts index 8630c8a3..1469aace 100644 --- a/src/hooks/useQueryParams.ts +++ b/src/hooks/useQueryParams.ts @@ -32,7 +32,7 @@ export function useQueryParam( search: parsed.toString(), }); }, - [param, location, router] + [param, location.search, router] ); return [currentValue, set]; diff --git a/src/pages/PlayerView.tsx b/src/pages/PlayerView.tsx index e58f35e1..777e32b4 100644 --- a/src/pages/PlayerView.tsx +++ b/src/pages/PlayerView.tsx @@ -26,7 +26,7 @@ export function PlayerView() { sources: Record; sourceOrder: ScrapingItems[]; } | null>(null); - const [startAtParam, setStartAtParam] = useQueryParam("t"); + const [startAtParam] = useQueryParam("t"); const { status, playMedia, reset, setScrapeNotFound } = usePlayer(); const { setPlayerMeta, scrapeMedia } = usePlayerMeta(); const backUrl = useLastNonPlayerLink(); @@ -54,14 +54,13 @@ export function PlayerView() { const playAfterScrape = useCallback( (out: RunOutput | null) => { if (!out) return; + let startAt: number | undefined; - if (startAtParam) { - setStartAtParam(null); - startAt = parseTimestamp(startAtParam) ?? undefined; - } + if (startAtParam) startAt = parseTimestamp(startAtParam) ?? undefined; + playMedia(convertRunoutputToSource(out), out.sourceId, startAt); }, - [playMedia, setStartAtParam, startAtParam] + [playMedia, startAtParam] ); return ( diff --git a/vite.config.ts b/vite.config.ts index 10746762..bf8e7e60 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -54,6 +54,7 @@ export default defineConfig(({ mode }) => { theme_color: "#120f1d", background_color: "#120f1d", display: "standalone", + orientation: "portrait-primary", start_url: "/", icons: [ {