diff --git a/locales/app/en.json b/locales/app/en.json index 6e04a847c..3a5deadb2 100644 --- a/locales/app/en.json +++ b/locales/app/en.json @@ -146,6 +146,7 @@ "signin.continue_with_github": "Continue with GitHub", "signin.continue_with_google": "Continue with Google", "signin.sign_in_to": "Sign in to", + "sync_indicator.disabled": "Due to security reasons, sync is disabled.", "sync_indicator.offline": "Offline", "sync_indicator.synced": "Synced with server", "tip_modal.amount": "Amount", diff --git a/src/renderer/src/components/icons/PhCloudWarning.tsx b/src/renderer/src/components/icons/PhCloudWarning.tsx new file mode 100644 index 000000000..070953991 --- /dev/null +++ b/src/renderer/src/components/icons/PhCloudWarning.tsx @@ -0,0 +1,18 @@ +import type { SVGProps } from "react" + +export function PhCloudWarning(props: SVGProps) { + return ( + + + + ) +} diff --git a/src/renderer/src/modules/settings/helper/SyncIndicator.tsx b/src/renderer/src/modules/settings/helper/SyncIndicator.tsx index 40a369a72..8683ea728 100644 --- a/src/renderer/src/modules/settings/helper/SyncIndicator.tsx +++ b/src/renderer/src/modules/settings/helper/SyncIndicator.tsx @@ -1,16 +1,19 @@ import { PhCloudCheck } from "@renderer/components/icons/PhCloudCheck" +import { PhCloudWarning } from "@renderer/components/icons/PhCloudWarning" import { PhCloudX } from "@renderer/components/icons/PhCloudX" import { Tooltip, TooltipContent, TooltipTrigger } from "@renderer/components/ui/tooltip" import { useAuthQuery, useIsOnline } from "@renderer/hooks/common" import { settings } from "@renderer/queries/settings" -import { useEffect, useRef } from "react" +import { useEffect, useMemo, useRef } from "react" import { useTranslation } from "react-i18next" +import { useSettingContextSelector } from "../modal/hooks" import { settingSyncQueue } from "./sync-queue" -export const SyncIndicator = () => { +export const SettingSyncIndicator = () => { const { t } = useTranslation() const { data: remoteSettings, isLoading } = useAuthQuery(settings.get(), {}) + const canSync = useSettingContextSelector((s) => s.canSync) const isOnline = useIsOnline() const onceRef = useRef(false) @@ -26,17 +29,41 @@ export const SyncIndicator = () => { } }, [remoteSettings, isLoading]) + const metaInfo: { + icon: React.FC> + text: string + } = useMemo(() => { + switch (true) { + case !isOnline: { + return { + icon: PhCloudX, + text: t("sync_indicator.offline"), + } + } + case !canSync: { + return { + icon: PhCloudWarning, + text: t("sync_indicator.disabled"), + } + } + default: { + return { + icon: PhCloudCheck, + text: t("sync_indicator.synced"), + } + } + } + }, [isOnline, canSync, t]) + return (
- {isOnline ? : } +
-
- {isOnline ? t("sync_indicator.synced") : t("sync_indicator.offline")} -
+
{metaInfo.text}
) diff --git a/src/renderer/src/modules/settings/modal/hooks.ts b/src/renderer/src/modules/settings/modal/hooks.ts index 1feadfaae..acab65957 100644 --- a/src/renderer/src/modules/settings/modal/hooks.ts +++ b/src/renderer/src/modules/settings/modal/hooks.ts @@ -1,6 +1,9 @@ import { useModalStack } from "@renderer/components/ui/modal/stacked/hooks" import { NoopChildren } from "@renderer/components/ui/modal/stacked/utils" +import type { ExtractAtomValue, PrimitiveAtom } from "jotai" +import { atom, useAtomValue, useSetAtom } from "jotai" import { createElement, useCallback } from "react" +import { createContext, useContextSelector } from "use-context-selector" import { SettingModalContent } from "./content" @@ -22,3 +25,21 @@ export const useSettingModal = () => { [present], ) } + +interface Ctx { + canSync: PrimitiveAtom +} +export const defaultCtx: Ctx = { + canSync: atom(true), +} +export const SettingContext = createContext(defaultCtx) + +export const useSettingContextSelector = (selector: (state: Ctx) => T) => { + // @ts-expect-error + return useAtomValue(useContextSelector(SettingContext, selector)) as ExtractAtomValue +} + +export const useSetSettingCanSync = () => { + const canSync = useContextSelector(SettingContext, (s) => s.canSync) + return useSetAtom(canSync) +} diff --git a/src/renderer/src/modules/settings/modal/layout.tsx b/src/renderer/src/modules/settings/modal/layout.tsx index 585c35f7b..d16f1f001 100644 --- a/src/renderer/src/modules/settings/modal/layout.tsx +++ b/src/renderer/src/modules/settings/modal/layout.tsx @@ -10,9 +10,10 @@ import type { PointerEventHandler, PropsWithChildren } from "react" import { Suspense, useCallback, useEffect, useRef } from "react" import { settings } from "../constants" -import { SyncIndicator } from "../helper/SyncIndicator" +import { SettingSyncIndicator } from "../helper/SyncIndicator" import { SettingsSidebarTitle } from "../title" import { useSetSettingTab, useSettingTab } from "./context" +import { defaultCtx, SettingContext } from "./hooks" export function SettingModalLayout( props: PropsWithChildren<{ @@ -74,55 +75,57 @@ export function SettingModalLayout( cursor: "grabbing", }} > - - {draggable && ( -
- )} -
-
-
- - {APP_NAME} -
- + + + {draggable && ( +
+ )} +
+
+
+ + {APP_NAME} +
+ -
- +
+ +
+
+
+ {children}
-
- {children} -
-
- + +
) diff --git a/src/renderer/src/modules/settings/tabs/integration.tsx b/src/renderer/src/modules/settings/tabs/integration.tsx index 1b3abb208..97311107b 100644 --- a/src/renderer/src/modules/settings/tabs/integration.tsx +++ b/src/renderer/src/modules/settings/tabs/integration.tsx @@ -9,9 +9,10 @@ import { SimpleIconsInstapaper, SimpleIconsReadwise, } from "@renderer/components/ui/platform-icon/icons" +import { useEffect } from "react" import { useTranslation } from "react-i18next" -import { SettingsTitle } from "../title" +import { useSetSettingCanSync } from "../modal/hooks" const { defineSettingItem, SettingBuilder } = createSetting( useIntegrationSettingValue, @@ -19,89 +20,93 @@ const { defineSettingItem, SettingBuilder } = createSetting( ) export const SettingIntegration = () => { const { t } = useTranslation("settings") + const setSync = useSetSettingCanSync() + useEffect(() => { + setSync(false) + return () => { + setSync(true) + } + }, [setSync]) return ( - <> - -
- - - {t("integration.eagle.title")} - - ), +
+ + + {t("integration.eagle.title")} + + ), + }, + defineSettingItem("enableEagle", { + label: t("integration.eagle.enable.label"), + description: t("integration.eagle.enable.description"), + }), + { + type: "title", + value: ( + + + {t("integration.readwise.title")} + + ), + }, + defineSettingItem("enableReadwise", { + label: t("integration.readwise.enable.label"), + description: t("integration.readwise.enable.description"), + }), + defineSettingItem("readwiseToken", { + label: t("integration.readwise.token.label"), + vertical: true, + type: "password", + description: ( + <> + {t("integration.readwise.token.description")}{" "} + + readwise.io/access_token + + . + + ), + }), + { + type: "title", + value: ( + + + {t("integration.instapaper.title")} + + ), + }, + defineSettingItem("enableInstapaper", { + label: t("integration.instapaper.enable.label"), + description: t("integration.instapaper.enable.description"), + }), + defineSettingItem("instapaperUsername", { + label: t("integration.instapaper.username.label"), + componentProps: { + labelClassName: "w-[150px]", }, - defineSettingItem("enableEagle", { - label: t("integration.eagle.enable.label"), - description: t("integration.eagle.enable.description"), - }), - { - type: "title", - value: ( - - - {t("integration.readwise.title")} - - ), + }), + defineSettingItem("instapaperPassword", { + label: t("integration.instapaper.password.label"), + type: "password", + componentProps: { + labelClassName: "w-[150px]", }, - defineSettingItem("enableReadwise", { - label: t("integration.readwise.enable.label"), - description: t("integration.readwise.enable.description"), - }), - defineSettingItem("readwiseToken", { - label: t("integration.readwise.token.label"), - vertical: true, - type: "password", - description: ( - <> - {t("integration.readwise.token.description")}{" "} - - readwise.io/access_token - - . - - ), - }), - { - type: "title", - value: ( - - - {t("integration.instapaper.title")} - - ), - }, - defineSettingItem("enableInstapaper", { - label: t("integration.instapaper.enable.label"), - description: t("integration.instapaper.enable.description"), - }), - defineSettingItem("instapaperUsername", { - label: t("integration.instapaper.username.label"), - componentProps: { - labelClassName: "w-[150px]", - }, - }), - defineSettingItem("instapaperPassword", { - label: t("integration.instapaper.password.label"), - type: "password", - componentProps: { - labelClassName: "w-[150px]", - }, - }), + }), - BottomTip, - ]} - /> -
- + BottomTip, + ]} + /> +
) } diff --git a/src/renderer/src/pages/settings/(settings)/integration.tsx b/src/renderer/src/pages/settings/(settings)/integration.tsx index 58715801a..da51e866a 100644 --- a/src/renderer/src/pages/settings/(settings)/integration.tsx +++ b/src/renderer/src/pages/settings/(settings)/integration.tsx @@ -1,4 +1,5 @@ import { SettingIntegration } from "@renderer/modules/settings/tabs/integration" +import { SettingsTitle } from "@renderer/modules/settings/title" import { defineSettingPageData } from "@renderer/modules/settings/utils" const iconName = "i-mgc-department-cute-re" @@ -11,5 +12,10 @@ export const loader = defineSettingPageData({ }) export function Component() { - return + return ( + <> + + + + ) }