Skip to content

Commit

Permalink
Merge pull request #21 from gary-Shen/fix/gist
Browse files Browse the repository at this point in the history
update: optimize ux
  • Loading branch information
gary-Shen authored Jun 26, 2023
2 parents 5557e14 + 0ea9526 commit 95ac22c
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/components/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(function InnerInput
const InputGroupWrapper = styled.div`
& > * {
white-space: nowrap;
align-self: stretch;
}
&:not(.nospace) > * + * {
Expand Down
15 changes: 13 additions & 2 deletions src/hooks/useGistQuery.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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(), []);
},
});
Expand All @@ -30,6 +40,7 @@ export const useGistOne = (gistId: string | undefined, options?: any) => {
enabled: !!gistId,
placeholderData: {} as any,
select: (data) => data?.data,
onError: errHandler,
...options,
});

Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -66,6 +66,7 @@ export default function useSettings(): [
const mutation = useGistUpdate(settings?.gist?.id);
useEffect(() => {
if (!accessToken) {
destroyOctokit();
return;
}

Expand Down
3 changes: 2 additions & 1 deletion src/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
3 changes: 2 additions & 1 deletion src/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@
"sync failed": "同步失败",
"syncing": "同步中...",
"built in color": "内置颜色",
"custom color": "自定义颜色"
"custom color": "自定义颜色",
"proceed": "拉取 Gist"
}
3 changes: 2 additions & 1 deletion src/locales/zh-TR.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@
"sync failed": "同步失敗",
"syncing": "同步中...",
"built in color": "內建顏色",
"custom color": "自訂顏色"
"custom color": "自訂顏色",
"proceed": "繼續"
}
34 changes: 19 additions & 15 deletions src/partials/Setting/OAuth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -335,20 +335,24 @@ export default function OAuth({ onClose }: OAuthProps) {

return (
<StyledOauth className="oauth-modal-content">
<Input
className="mb-2"
placeholder={t('pasteToken')}
autoFocus
onBlur={handleSave}
onKeyDown={(e) => {
if (e.which === 13) {
e.preventDefault();
handleSave();
}
}}
onChange={handleOnChange}
value={tokenValue}
/>
<InputGroup className="mb-2">
<Input
placeholder={t('pasteToken')}
autoFocus
onBlur={handleSave}
onKeyDown={(e) => {
if (e.which === 13) {
e.preventDefault();
handleSave();
}
}}
onChange={handleOnChange}
value={tokenValue}
/>
<Button className="!px-4" disabled={!tokenValue} onClick={handleSave}>
{t('proceed')}
</Button>
</InputGroup>
<div className="flex justify-end mb-4">
<IconText
position="right"
Expand Down
2 changes: 1 addition & 1 deletion src/partials/Setting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default function SettingModal({ visible, onClose }: OAuthProps) {
}, [handleClose, handleLangChange, handleThemeSolutionChange, settings, t]);

return (
<Modal title={t('setting')} visible={visible} onClose={handleClose} width={442}>
<Modal title={t('setting')} visible={visible} onClose={handleClose} width={512}>
<MyTabs items={tabItems} />
</Modal>
);
Expand Down

1 comment on commit 95ac22c

@vercel
Copy link

@vercel vercel bot commented on 95ac22c Jun 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

candi-tab – ./

candi-tab.vercel.app
candi-tab-gary-shen.vercel.app
candi-tab-git-master-gary-shen.vercel.app

Please sign in to comment.