From 0ea95266ba6fe5e87978ef7e5e16b20d66d5b9c3 Mon Sep 17 00:00:00 2001 From: gary-Shen Date: Mon, 26 Jun 2023 12:59:57 +0800 Subject: [PATCH] update: optimize ux --- src/components/Input.tsx | 1 + src/hooks/useGistQuery.ts | 15 ++++++++++-- src/hooks/useSettings.ts | 3 ++- src/locales/en-US.json | 3 ++- src/locales/zh-CN.json | 3 ++- src/locales/zh-TR.json | 3 ++- src/partials/Setting/OAuth/index.tsx | 34 ++++++++++++++++------------ src/partials/Setting/index.tsx | 2 +- 8 files changed, 42 insertions(+), 22 deletions(-) diff --git a/src/components/Input.tsx b/src/components/Input.tsx index e3ba022..8b8f033 100644 --- a/src/components/Input.tsx +++ b/src/components/Input.tsx @@ -27,6 +27,7 @@ const Input = React.forwardRef(function InnerInput const InputGroupWrapper = styled.div` & > * { white-space: nowrap; + align-self: stretch; } &:not(.nospace) > * + * { diff --git a/src/hooks/useGistQuery.ts b/src/hooks/useGistQuery.ts index 16e38ee..60df3f1 100644 --- a/src/hooks/useGistQuery.ts +++ b/src/hooks/useGistQuery.ts @@ -1,10 +1,19 @@ import { useQuery } from '@tanstack/react-query'; import { useEffect } from 'react'; +import toast from 'react-hot-toast'; -import { fetchAll, fetchOne } from '@/service/gist'; +import { destroyOctokit, fetchAll, fetchOne } from '@/service/gist'; import { gistKeys } from '@/constant/queryKeys/gist'; import queryClient from '@/components/QueryProvider'; +const errHandler = (err: any) => { + if (err.status === 401) { + toast.dismiss(); + toast.error('Unauthorized! Please check your access token.'); + destroyOctokit(); + } +}; + export const useGistAll = (accessToken: string) => { useEffect(() => { if (!accessToken) { @@ -17,7 +26,8 @@ export const useGistAll = (accessToken: string) => { placeholderData: {} as any, enabled: !!accessToken, select: (data) => data?.data, - onError() { + onError: (err) => { + errHandler(err); queryClient.setQueryData(gistKeys.lists(), []); }, }); @@ -30,6 +40,7 @@ export const useGistOne = (gistId: string | undefined, options?: any) => { enabled: !!gistId, placeholderData: {} as any, select: (data) => data?.data, + onError: errHandler, ...options, }); diff --git a/src/hooks/useSettings.ts b/src/hooks/useSettings.ts index 24e8d19..104d52c 100644 --- a/src/hooks/useSettings.ts +++ b/src/hooks/useSettings.ts @@ -10,7 +10,7 @@ import _ from 'lodash'; import type { Block, Link, Setting } from '@/types/setting.type'; import { gid } from '@/utils/gid'; import parseGistContent from '@/utils/parseGistContent'; -import { setOctokit } from '@/service/gist'; +import { destroyOctokit, setOctokit } from '@/service/gist'; import { calcLayout } from '@/utils/calcLayout'; import { load, save } from './settings'; @@ -66,6 +66,7 @@ export default function useSettings(): [ const mutation = useGistUpdate(settings?.gist?.id); useEffect(() => { if (!accessToken) { + destroyOctokit(); return; } diff --git a/src/locales/en-US.json b/src/locales/en-US.json index f2a3a1c..49bc9e4 100644 --- a/src/locales/en-US.json +++ b/src/locales/en-US.json @@ -49,5 +49,6 @@ "sync failed": "Synchronization failed", "syncing": "Synchronizing...", "built in color": "Built-in color", - "custom color": "Custom color" + "custom color": "Custom color", + "proceed": "Proceed" } diff --git a/src/locales/zh-CN.json b/src/locales/zh-CN.json index 655657b..e33070d 100644 --- a/src/locales/zh-CN.json +++ b/src/locales/zh-CN.json @@ -50,5 +50,6 @@ "sync failed": "同步失败", "syncing": "同步中...", "built in color": "内置颜色", - "custom color": "自定义颜色" + "custom color": "自定义颜色", + "proceed": "拉取 Gist" } diff --git a/src/locales/zh-TR.json b/src/locales/zh-TR.json index 0982d2f..6010e4e 100644 --- a/src/locales/zh-TR.json +++ b/src/locales/zh-TR.json @@ -50,5 +50,6 @@ "sync failed": "同步失敗", "syncing": "同步中...", "built in color": "內建顏色", - "custom color": "自訂顏色" + "custom color": "自訂顏色", + "proceed": "繼續" } diff --git a/src/partials/Setting/OAuth/index.tsx b/src/partials/Setting/OAuth/index.tsx index 4ea36f0..0f8ea60 100644 --- a/src/partials/Setting/OAuth/index.tsx +++ b/src/partials/Setting/OAuth/index.tsx @@ -13,7 +13,7 @@ import type { IGist } from '@/types/gist.type'; import { gid } from '@/utils/gid'; import parseGistContent from '@/utils/parseGistContent'; import { useGistAll, useGistOne } from '@/hooks/useGistQuery'; -import Input from '@/components/Input'; +import Input, { InputGroup } from '@/components/Input'; import TextArea from '@/components/TextArea'; import Spin from '@/components/Spin'; import IconText from '@/components/IconText'; @@ -335,20 +335,24 @@ export default function OAuth({ onClose }: OAuthProps) { return ( - { - if (e.which === 13) { - e.preventDefault(); - handleSave(); - } - }} - onChange={handleOnChange} - value={tokenValue} - /> + + { + if (e.which === 13) { + e.preventDefault(); + handleSave(); + } + }} + onChange={handleOnChange} + value={tokenValue} + /> + +
+ );