From 075ec651b0d4e07b4c7bbd95b734e3d0a0c5a469 Mon Sep 17 00:00:00 2001 From: Cooper Ransom Date: Tue, 26 Mar 2024 21:42:35 -0400 Subject: [PATCH] Polish last commit --- src/pages/onboarding/OnboardingExtension.tsx | 23 +---- src/pages/parts/player/ScrapeErrorPart.tsx | 98 ++++++++++++-------- src/utils/onboarding.ts | 24 ++++- 3 files changed, 84 insertions(+), 61 deletions(-) diff --git a/src/pages/onboarding/OnboardingExtension.tsx b/src/pages/onboarding/OnboardingExtension.tsx index db351dda..ef05cbfc 100644 --- a/src/pages/onboarding/OnboardingExtension.tsx +++ b/src/pages/onboarding/OnboardingExtension.tsx @@ -2,8 +2,7 @@ import { ReactNode, useCallback, useEffect, useMemo, useState } from "react"; import { Trans, useTranslation } from "react-i18next"; import { useAsyncFn, useInterval } from "react-use"; -import { isAllowedExtensionVersion } from "@/backend/extension/compatibility"; -import { extensionInfo, sendPage } from "@/backend/extension/messaging"; +import { sendPage } from "@/backend/extension/messaging"; import { Button } from "@/components/buttons/Button"; import { Icon, Icons } from "@/components/Icon"; import { Loading } from "@/components/layout/Loading"; @@ -22,24 +21,8 @@ import { ExtensionDetectionResult, detectExtensionInstall, } from "@/utils/detectFeatures"; - -type ExtensionStatus = - | "unknown" - | "failed" - | "disallowed" - | "noperms" - | "outdated" - | "success"; - -async function getExtensionState(): Promise { - const info = await extensionInfo(); - if (!info) return "unknown"; // cant talk to extension - if (!info.success) return "failed"; // extension failed to respond - if (!info.allowed) return "disallowed"; // extension is not enabled on this page - if (!info.hasPermission) return "noperms"; // extension has no perms to do it's tasks - if (!isAllowedExtensionVersion(info.version)) return "outdated"; // extension is too old - return "success"; // no problems -} +import { getExtensionState } from "@/utils/onboarding"; +import type { ExtensionStatus } from "@/utils/onboarding"; function RefreshBar() { const { t } = useTranslation(); diff --git a/src/pages/parts/player/ScrapeErrorPart.tsx b/src/pages/parts/player/ScrapeErrorPart.tsx index a6a89fd9..5de7e650 100644 --- a/src/pages/parts/player/ScrapeErrorPart.tsx +++ b/src/pages/parts/player/ScrapeErrorPart.tsx @@ -2,8 +2,7 @@ import { useEffect, useMemo, useState } from "react"; import { Trans, useTranslation } from "react-i18next"; import { useLocation } from "react-router-dom"; -import { isAllowedExtensionVersion } from "@/backend/extension/compatibility"; -import { extensionInfo, sendPage } from "@/backend/extension/messaging"; +import { sendPage } from "@/backend/extension/messaging"; import { Button } from "@/components/buttons/Button"; import { Icons } from "@/components/Icon"; import { IconPill } from "@/components/layout/IconPill"; @@ -12,18 +11,11 @@ import { Paragraph } from "@/components/text/Paragraph"; import { Title } from "@/components/text/Title"; import { ScrapingItems, ScrapingSegment } from "@/hooks/useProviderScrape"; import { ErrorContainer, ErrorLayout } from "@/pages/layouts/ErrorLayout"; +import { ExtensionStatus, getExtensionState } from "@/utils/onboarding"; import { getProviderApiUrls } from "@/utils/proxyUrls"; import { ErrorCardInModal } from "../errors/ErrorCard"; -type ExtensionStatus = - | "unknown" - | "failed" - | "disallowed" - | "noperms" - | "outdated" - | "success"; - export interface ScrapeErrorPartProps { data: { sources: Record; @@ -31,16 +23,6 @@ export interface ScrapeErrorPartProps { }; } -async function getExtensionState(): Promise { - const info = await extensionInfo(); - if (!info) return "unknown"; // cant talk to extension - if (!info.success) return "failed"; // extension failed to respond - if (!info.allowed) return "disallowed"; // extension is not enabled on this page - if (!info.hasPermission) return "noperms"; // extension has no perms to do it's tasks - if (!isAllowedExtensionVersion(info.version)) return "outdated"; // extension is too old - return "success"; // no problems -} - export function ScrapeErrorPart(props: ScrapeErrorPartProps) { const { t } = useTranslation(); const modal = useModal("error"); @@ -67,7 +49,7 @@ export function ScrapeErrorPart(props: ScrapeErrorPartProps) { }, [props, location]); useEffect(() => { - getExtensionState().then((state) => { + getExtensionState().then((state: ExtensionStatus) => { setExtensionState(state); if (state === "disallowed") { setTitle(t("player.scraping.extensionFailure.disabledTitle")); @@ -76,13 +58,13 @@ export function ScrapeErrorPart(props: ScrapeErrorPartProps) { }); }, [t]); - return ( - - - {t("player.scraping.notFound.badge")} - {title} - - {extensionState === "disallowed" ? ( + if (extensionState === "disallowed") { + return ( + + + {t("player.scraping.notFound.badge")} + {title} + - ) : ( - - ), + +
+ + +
+
+ {error ? ( + modal.hide()} + error={error} + /> + ) : null} +
+ ); + } + + return ( + + + {t("player.scraping.notFound.badge")} + {title} + + , + }} + />
diff --git a/src/utils/onboarding.ts b/src/utils/onboarding.ts index c2678b1c..d4ee10fd 100644 --- a/src/utils/onboarding.ts +++ b/src/utils/onboarding.ts @@ -1,8 +1,30 @@ -import { isExtensionActive } from "@/backend/extension/messaging"; +import { isAllowedExtensionVersion } from "@/backend/extension/compatibility"; +import { + extensionInfo, + isExtensionActive, +} from "@/backend/extension/messaging"; import { conf } from "@/setup/config"; import { useAuthStore } from "@/stores/auth"; import { useOnboardingStore } from "@/stores/onboarding"; +export type ExtensionStatus = + | "unknown" + | "failed" + | "disallowed" + | "noperms" + | "outdated" + | "success"; + +export async function getExtensionState(): Promise { + const info = await extensionInfo(); + if (!info) return "unknown"; // cant talk to extension + if (!info.success) return "failed"; // extension failed to respond + if (!info.allowed) return "disallowed"; // extension is not enabled on this page + if (!info.hasPermission) return "noperms"; // extension has no perms to do it's tasks + if (!isAllowedExtensionVersion(info.version)) return "outdated"; // extension is too old + return "success"; // no problems +} + export async function needsOnboarding(): Promise { // if onboarding is dislabed, no onboarding needed if (!conf().HAS_ONBOARDING) return false;