mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-20 14:37:43 +01:00
Polish last commit
This commit is contained in:
parent
b7be016377
commit
075ec651b0
3 changed files with 84 additions and 61 deletions
|
@ -2,8 +2,7 @@ import { ReactNode, useCallback, useEffect, useMemo, useState } from "react";
|
||||||
import { Trans, useTranslation } from "react-i18next";
|
import { Trans, useTranslation } from "react-i18next";
|
||||||
import { useAsyncFn, useInterval } from "react-use";
|
import { useAsyncFn, useInterval } from "react-use";
|
||||||
|
|
||||||
import { isAllowedExtensionVersion } from "@/backend/extension/compatibility";
|
import { sendPage } from "@/backend/extension/messaging";
|
||||||
import { extensionInfo, sendPage } from "@/backend/extension/messaging";
|
|
||||||
import { Button } from "@/components/buttons/Button";
|
import { Button } from "@/components/buttons/Button";
|
||||||
import { Icon, Icons } from "@/components/Icon";
|
import { Icon, Icons } from "@/components/Icon";
|
||||||
import { Loading } from "@/components/layout/Loading";
|
import { Loading } from "@/components/layout/Loading";
|
||||||
|
@ -22,24 +21,8 @@ import {
|
||||||
ExtensionDetectionResult,
|
ExtensionDetectionResult,
|
||||||
detectExtensionInstall,
|
detectExtensionInstall,
|
||||||
} from "@/utils/detectFeatures";
|
} from "@/utils/detectFeatures";
|
||||||
|
import { getExtensionState } from "@/utils/onboarding";
|
||||||
type ExtensionStatus =
|
import type { ExtensionStatus } from "@/utils/onboarding";
|
||||||
| "unknown"
|
|
||||||
| "failed"
|
|
||||||
| "disallowed"
|
|
||||||
| "noperms"
|
|
||||||
| "outdated"
|
|
||||||
| "success";
|
|
||||||
|
|
||||||
async function getExtensionState(): Promise<ExtensionStatus> {
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
function RefreshBar() {
|
function RefreshBar() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
|
@ -2,8 +2,7 @@ import { useEffect, useMemo, useState } from "react";
|
||||||
import { Trans, useTranslation } from "react-i18next";
|
import { Trans, useTranslation } from "react-i18next";
|
||||||
import { useLocation } from "react-router-dom";
|
import { useLocation } from "react-router-dom";
|
||||||
|
|
||||||
import { isAllowedExtensionVersion } from "@/backend/extension/compatibility";
|
import { sendPage } from "@/backend/extension/messaging";
|
||||||
import { extensionInfo, sendPage } from "@/backend/extension/messaging";
|
|
||||||
import { Button } from "@/components/buttons/Button";
|
import { Button } from "@/components/buttons/Button";
|
||||||
import { Icons } from "@/components/Icon";
|
import { Icons } from "@/components/Icon";
|
||||||
import { IconPill } from "@/components/layout/IconPill";
|
import { IconPill } from "@/components/layout/IconPill";
|
||||||
|
@ -12,18 +11,11 @@ import { Paragraph } from "@/components/text/Paragraph";
|
||||||
import { Title } from "@/components/text/Title";
|
import { Title } from "@/components/text/Title";
|
||||||
import { ScrapingItems, ScrapingSegment } from "@/hooks/useProviderScrape";
|
import { ScrapingItems, ScrapingSegment } from "@/hooks/useProviderScrape";
|
||||||
import { ErrorContainer, ErrorLayout } from "@/pages/layouts/ErrorLayout";
|
import { ErrorContainer, ErrorLayout } from "@/pages/layouts/ErrorLayout";
|
||||||
|
import { ExtensionStatus, getExtensionState } from "@/utils/onboarding";
|
||||||
import { getProviderApiUrls } from "@/utils/proxyUrls";
|
import { getProviderApiUrls } from "@/utils/proxyUrls";
|
||||||
|
|
||||||
import { ErrorCardInModal } from "../errors/ErrorCard";
|
import { ErrorCardInModal } from "../errors/ErrorCard";
|
||||||
|
|
||||||
type ExtensionStatus =
|
|
||||||
| "unknown"
|
|
||||||
| "failed"
|
|
||||||
| "disallowed"
|
|
||||||
| "noperms"
|
|
||||||
| "outdated"
|
|
||||||
| "success";
|
|
||||||
|
|
||||||
export interface ScrapeErrorPartProps {
|
export interface ScrapeErrorPartProps {
|
||||||
data: {
|
data: {
|
||||||
sources: Record<string, ScrapingSegment>;
|
sources: Record<string, ScrapingSegment>;
|
||||||
|
@ -31,16 +23,6 @@ export interface ScrapeErrorPartProps {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getExtensionState(): Promise<ExtensionStatus> {
|
|
||||||
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) {
|
export function ScrapeErrorPart(props: ScrapeErrorPartProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const modal = useModal("error");
|
const modal = useModal("error");
|
||||||
|
@ -67,7 +49,7 @@ export function ScrapeErrorPart(props: ScrapeErrorPartProps) {
|
||||||
}, [props, location]);
|
}, [props, location]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getExtensionState().then((state) => {
|
getExtensionState().then((state: ExtensionStatus) => {
|
||||||
setExtensionState(state);
|
setExtensionState(state);
|
||||||
if (state === "disallowed") {
|
if (state === "disallowed") {
|
||||||
setTitle(t("player.scraping.extensionFailure.disabledTitle"));
|
setTitle(t("player.scraping.extensionFailure.disabledTitle"));
|
||||||
|
@ -76,13 +58,13 @@ export function ScrapeErrorPart(props: ScrapeErrorPartProps) {
|
||||||
});
|
});
|
||||||
}, [t]);
|
}, [t]);
|
||||||
|
|
||||||
return (
|
if (extensionState === "disallowed") {
|
||||||
<ErrorLayout>
|
return (
|
||||||
<ErrorContainer>
|
<ErrorLayout>
|
||||||
<IconPill icon={icon}>{t("player.scraping.notFound.badge")}</IconPill>
|
<ErrorContainer>
|
||||||
<Title>{title}</Title>
|
<IconPill icon={icon}>{t("player.scraping.notFound.badge")}</IconPill>
|
||||||
<Paragraph>
|
<Title>{title}</Title>
|
||||||
{extensionState === "disallowed" ? (
|
<Paragraph>
|
||||||
<Trans
|
<Trans
|
||||||
i18nKey="player.scraping.extensionFailure.text"
|
i18nKey="player.scraping.extensionFailure.text"
|
||||||
components={{
|
components={{
|
||||||
|
@ -91,16 +73,54 @@ export function ScrapeErrorPart(props: ScrapeErrorPartProps) {
|
||||||
),
|
),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
) : (
|
</Paragraph>
|
||||||
<Trans
|
<div className="flex gap-3">
|
||||||
i18nKey="player.scraping.notFound.text"
|
<Button
|
||||||
components={{
|
href="/"
|
||||||
bold: (
|
theme="secondary"
|
||||||
<span className="font-bold" style={{ color: "#cfcfcf" }} />
|
padding="md:px-12 p-2.5"
|
||||||
),
|
className="mt-6"
|
||||||
|
>
|
||||||
|
{t("player.scraping.notFound.homeButton")}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
sendPage({
|
||||||
|
page: "PermissionGrant",
|
||||||
|
redirectUrl: window.location.href,
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
theme="purple"
|
||||||
)}
|
padding="md:px-12 p-2.5"
|
||||||
|
className="mt-6"
|
||||||
|
>
|
||||||
|
{t("player.scraping.extensionFailure.enableExtension")}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</ErrorContainer>
|
||||||
|
{error ? (
|
||||||
|
<ErrorCardInModal
|
||||||
|
id={modal.id}
|
||||||
|
onClose={() => modal.hide()}
|
||||||
|
error={error}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
</ErrorLayout>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ErrorLayout>
|
||||||
|
<ErrorContainer>
|
||||||
|
<IconPill icon={icon}>{t("player.scraping.notFound.badge")}</IconPill>
|
||||||
|
<Title>{title}</Title>
|
||||||
|
<Paragraph>
|
||||||
|
<Trans
|
||||||
|
i18nKey="player.scraping.notFound.text"
|
||||||
|
components={{
|
||||||
|
bold: <span className="font-bold" style={{ color: "#cfcfcf" }} />,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</Paragraph>
|
</Paragraph>
|
||||||
<div className="flex gap-3">
|
<div className="flex gap-3">
|
||||||
<Button
|
<Button
|
||||||
|
@ -122,9 +142,7 @@ export function ScrapeErrorPart(props: ScrapeErrorPartProps) {
|
||||||
padding="md:px-12 p-2.5"
|
padding="md:px-12 p-2.5"
|
||||||
className="mt-6"
|
className="mt-6"
|
||||||
>
|
>
|
||||||
{extensionState === "unknown"
|
{t("player.scraping.notFound.detailsButton")}
|
||||||
? t("player.scraping.notFound.detailsButton")
|
|
||||||
: t("player.scraping.extensionFailure.enableExtension")}
|
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</ErrorContainer>
|
</ErrorContainer>
|
||||||
|
|
|
@ -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 { conf } from "@/setup/config";
|
||||||
import { useAuthStore } from "@/stores/auth";
|
import { useAuthStore } from "@/stores/auth";
|
||||||
import { useOnboardingStore } from "@/stores/onboarding";
|
import { useOnboardingStore } from "@/stores/onboarding";
|
||||||
|
|
||||||
|
export type ExtensionStatus =
|
||||||
|
| "unknown"
|
||||||
|
| "failed"
|
||||||
|
| "disallowed"
|
||||||
|
| "noperms"
|
||||||
|
| "outdated"
|
||||||
|
| "success";
|
||||||
|
|
||||||
|
export async function getExtensionState(): Promise<ExtensionStatus> {
|
||||||
|
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<boolean> {
|
export async function needsOnboarding(): Promise<boolean> {
|
||||||
// if onboarding is dislabed, no onboarding needed
|
// if onboarding is dislabed, no onboarding needed
|
||||||
if (!conf().HAS_ONBOARDING) return false;
|
if (!conf().HAS_ONBOARDING) return false;
|
||||||
|
|
Loading…
Reference in a new issue