From b7484363dc0e2e0fb77926ebb864dbee0efdb544 Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 7 Apr 2024 21:23:14 +0800 Subject: [PATCH] chore: tweak store imports --- .../src/components/CreateShortcutButton.tsx | 2 +- .../src/components/PullShortcutsButton.tsx | 2 +- .../src/components/ShortcutsContainer.tsx | 2 +- frontend/extension/src/context/provider.tsx | 16 ++++++++++++---- frontend/extension/src/helpers/utils.ts | 6 ------ frontend/extension/src/options.tsx | 2 +- frontend/extension/src/popup.tsx | 2 +- frontend/extension/src/stores/index.ts | 3 +++ .../extension/src/{store => stores}/shortcut.ts | 0 9 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 frontend/extension/src/stores/index.ts rename frontend/extension/src/{store => stores}/shortcut.ts (100%) diff --git a/frontend/extension/src/components/CreateShortcutButton.tsx b/frontend/extension/src/components/CreateShortcutButton.tsx index 87a5e69..6070c04 100644 --- a/frontend/extension/src/components/CreateShortcutButton.tsx +++ b/frontend/extension/src/components/CreateShortcutButton.tsx @@ -2,7 +2,7 @@ import { Button, IconButton, Input, Modal, ModalDialog } from "@mui/joy"; import { useEffect, useState } from "react"; import { toast } from "react-hot-toast"; import { useStorageContext } from "@/context"; -import useShortcutStore from "@/store/shortcut"; +import { useShortcutStore } from "@/stores"; import type { Visibility } from "@/types/proto/api/v1/common"; import { Shortcut } from "@/types/proto/api/v1/shortcut_service"; import Icon from "./Icon"; diff --git a/frontend/extension/src/components/PullShortcutsButton.tsx b/frontend/extension/src/components/PullShortcutsButton.tsx index 2d923c7..b5ab32d 100644 --- a/frontend/extension/src/components/PullShortcutsButton.tsx +++ b/frontend/extension/src/components/PullShortcutsButton.tsx @@ -2,7 +2,7 @@ import { IconButton } from "@mui/joy"; import { useEffect } from "react"; import { toast } from "react-hot-toast"; import { useStorageContext } from "@/context"; -import useShortcutStore from "@/store/shortcut"; +import { useShortcutStore } from "@/stores"; import Icon from "./Icon"; const PullShortcutsButton = () => { diff --git a/frontend/extension/src/components/ShortcutsContainer.tsx b/frontend/extension/src/components/ShortcutsContainer.tsx index b9ef32f..9c56709 100644 --- a/frontend/extension/src/components/ShortcutsContainer.tsx +++ b/frontend/extension/src/components/ShortcutsContainer.tsx @@ -1,5 +1,5 @@ import classNames from "classnames"; -import useShortcutStore from "@/store/shortcut"; +import { useShortcutStore } from "@/stores"; import Icon from "./Icon"; import ShortcutView from "./ShortcutView"; diff --git a/frontend/extension/src/context/provider.tsx b/frontend/extension/src/context/provider.tsx index 77fca1f..d6c08f2 100644 --- a/frontend/extension/src/context/provider.tsx +++ b/frontend/extension/src/context/provider.tsx @@ -16,18 +16,26 @@ const StorageContextProvider = ({ children }: Props) => { useEffect(() => { (async () => { - const domain = await storage.get("domain"); + let instanceUrl = await storage.get("instance_url"); const accessToken = await storage.get("access_token"); const defaultVisibility = (await storage.get("default_visibility")) as Visibility; - setInstanceUrl(domain); + // Migrate domain to instance_url. + const domain = await storage.get("domain"); + if (domain) { + instanceUrl = domain; + await storage.remove("domain"); + await storage.set("instance_url", instanceUrl); + } + + setInstanceUrl(instanceUrl); setAccessToken(accessToken); setDefaultVisibility(defaultVisibility); setIsInitialized(true); })(); storage.watch({ - domain: (c) => { + instance_url: (c) => { setInstanceUrl(c.newValue); }, access_token: (c) => { @@ -45,7 +53,7 @@ const StorageContextProvider = ({ children }: Props) => { instanceUrl, accessToken, defaultVisibility, - setInstanceUrl: (instanceUrl: string) => storage.set("domain", instanceUrl), + setInstanceUrl: (instanceUrl: string) => storage.set("instance_url", instanceUrl), setAccessToken: (accessToken: string) => storage.set("access_token", accessToken), setDefaultVisibility: (visibility: Visibility) => storage.set("default_visibility", visibility), }} diff --git a/frontend/extension/src/helpers/utils.ts b/frontend/extension/src/helpers/utils.ts index 2280589..fcb3085 100644 --- a/frontend/extension/src/helpers/utils.ts +++ b/frontend/extension/src/helpers/utils.ts @@ -1,9 +1,3 @@ -import { isNull, isUndefined } from "lodash-es"; - -export const isNullorUndefined = (value: any) => { - return isNull(value) || isUndefined(value); -}; - export const getFaviconWithGoogleS2 = (url: string) => { try { const urlObject = new URL(url); diff --git a/frontend/extension/src/options.tsx b/frontend/extension/src/options.tsx index 5bb0344..0440aba 100644 --- a/frontend/extension/src/options.tsx +++ b/frontend/extension/src/options.tsx @@ -1,13 +1,13 @@ import { Button, CssVarsProvider, Divider, Input, Select, Option } from "@mui/joy"; import { useEffect, useState } from "react"; import { Toaster, toast } from "react-hot-toast"; +import { useShortcutStore } from "@/stores"; import Icon from "./components/Icon"; import Logo from "./components/Logo"; import PullShortcutsButton from "./components/PullShortcutsButton"; import ShortcutsContainer from "./components/ShortcutsContainer"; import { StorageContextProvider, useStorageContext } from "./context"; import useColorTheme from "./hooks/useColorTheme"; -import useShortcutStore from "./store/shortcut"; import "./style.css"; import { Visibility } from "./types/proto/api/v1/common"; diff --git a/frontend/extension/src/popup.tsx b/frontend/extension/src/popup.tsx index 4be21e4..c98f509 100644 --- a/frontend/extension/src/popup.tsx +++ b/frontend/extension/src/popup.tsx @@ -6,9 +6,9 @@ import Icon from "@/components/Icon"; import Logo from "@/components/Logo"; import PullShortcutsButton from "@/components/PullShortcutsButton"; import ShortcutsContainer from "@/components/ShortcutsContainer"; +import { useShortcutStore } from "@/stores"; import { StorageContextProvider, useStorageContext } from "./context"; import useColorTheme from "./hooks/useColorTheme"; -import useShortcutStore from "./store/shortcut"; import "./style.css"; const IndexPopup = () => { diff --git a/frontend/extension/src/stores/index.ts b/frontend/extension/src/stores/index.ts new file mode 100644 index 0000000..124812c --- /dev/null +++ b/frontend/extension/src/stores/index.ts @@ -0,0 +1,3 @@ +import useShortcutStore from "./shortcut"; + +export { useShortcutStore }; diff --git a/frontend/extension/src/store/shortcut.ts b/frontend/extension/src/stores/shortcut.ts similarity index 100% rename from frontend/extension/src/store/shortcut.ts rename to frontend/extension/src/stores/shortcut.ts