Skip to content

Commit

Permalink
Merge pull request #35 from web-dahuyou/dev
Browse files Browse the repository at this point in the history
修复 github API 同步问题
  • Loading branch information
web-dahuyou authored Sep 10, 2024
2 parents bb7e790 + f15d453 commit ae975ce
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 15 deletions.
2 changes: 2 additions & 0 deletions entrypoints/common/locale/modules/sync/enUS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export default {
'sync.tip.manualPushForce': 'Push local data to remote (force overwrite).',
'sync.tip.tokenChange': 'Change the access token will clear the local {type} sync history',
'sync.tip.contentTooLarge': 'The remote file content is too large, truncated by gist API, cancel merge to local',
'sync.tip.syncHistory': 'Sync history only retains the last 50 records, you can also clear the history manually.',
'sync.getYourToken': 'Get/Set your access token',
'sync.syncHistory': 'Sync History',
'sync.noSyncHistory': 'No Sync History',
'sync.clearSyncHistory': 'Clear Sync History',
}
2 changes: 2 additions & 0 deletions entrypoints/common/locale/modules/sync/zhCN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export default {
'sync.tip.manualPushForce': '推送本地数据到远程(强制覆盖)',
'sync.tip.tokenChange': '修改access token会清空本地{type}的同步历史记录',
'sync.tip.contentTooLarge': '远程文件内容太大,返回的内容被 gist API 截断了,取消合并到本地',
'sync.tip.syncHistory': '同步历史只保留最近的50条记录,您还可以手动清空历史记录',
'sync.getYourToken': '前往获取/设置 token',
'sync.syncHistory': '同步历史记录',
'sync.noSyncHistory': '暂无历史同步记录',
'sync.clearSyncHistory': '清空同步历史记录',
}
13 changes: 9 additions & 4 deletions entrypoints/common/storage/syncUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ export default class SyncUtils {
return result;
}
async addSyncResult(remoteType: SyncRemoteType, currResult: SyncResultItemProps) {
this.syncResult[remoteType] = [currResult, ...(this.syncResult[remoteType] || [])];
const _syncResultList = [currResult, ...(this.syncResult[remoteType] || [])];
// 最多保留 50 条
this.syncResult[remoteType] = _syncResultList.slice(0, 50);
return await storage.setItem<SyncResultProps>(this.storageResultKey, this.syncResult);
}
async clearSyncResult(remoteType: SyncRemoteType) {
Expand Down Expand Up @@ -233,7 +235,7 @@ export default class SyncUtils {
syncType: SyncType,
gistData: GistResponseItemProps
) {
// 如果没有gist数据,则直接输出失败结构
// 如果没有gist数据,则直接输出失败结果
if (!gistData?.id) {
this.handleSyncResult(remoteType, syncType, gistData);
return;
Expand Down Expand Up @@ -311,8 +313,11 @@ export default class SyncUtils {
const isExist = gistData && gistData.id;

if (isExist) {
this.setConfigByType(remoteType, { gistId: gistData.id });
await this.handleBySyncType(remoteType, syncType, gistData);
await this.setConfigByType(remoteType, { gistId: gistData.id });
// 这里需要注意,github API 列表中并不返回文件内容(gitee API 在列表中依然返回content内容)
// 因此为了保持逻辑一致性,全都通过id来手动获取一遍内容
const gistDataById = await this.getGistById(remoteType);
await this.handleBySyncType(remoteType, syncType, gistDataById);
} else {
const data = await this.createGist(remoteType);
this.setConfigByType(remoteType, { gistId: data.id || '' });
Expand Down
4 changes: 1 addition & 3 deletions entrypoints/options/home/SortingBtns.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { useState, useCallback } from 'react';
import { theme, Button } from 'antd';
import { Button } from 'antd';
import { SortAscendingOutlined, SortDescendingOutlined } from '@ant-design/icons';
import { useIntlUtls } from '~/entrypoints/common/hooks/global';

export default function SortingBtns({ onSort }: { onSort?: (type: string) => void }) {
const { token } = theme.useToken();
const { $fmt } = useIntlUtls();

return <>
Expand Down
2 changes: 1 addition & 1 deletion entrypoints/options/sync/Sync.styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const StyledSidebarWrapper = styled.div<{ $primaryColor?: string; $collap
position: absolute;
box-sizing: border-box;
top: 0;
right: -32px;
right: -36px;
display: flex;
flex-direction: column;
gap: 6px;
Expand Down
15 changes: 13 additions & 2 deletions entrypoints/options/sync/SyncResultList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { theme, Flex, Space, Alert, Empty, Tooltip, Typography } from 'antd';
import { QuestionCircleOutlined } from '@ant-design/icons';
import type { SyncResultItemProps } from '~/entrypoints/types';
import { useIntlUtls } from '~/entrypoints/common/hooks/global';
import { SUCCESS_KEY } from '~/entrypoints/common/constants';
Expand All @@ -25,8 +26,18 @@ export default function SyncResultList({ resultList }: SyncResultListProps) {

return (
<Flex vertical gap={12}>
<Space>
<Typography.Title level={5}>{$fmt('sync.syncHistory')}</Typography.Title>
<Space align="center">
<Typography.Title level={5} style={{ margin: 0 }}>{$fmt('sync.syncHistory')}</Typography.Title>
<Tooltip
color={token.colorBgElevated}
placement="bottom"
destroyTooltipOnHide
title={
<Typography.Text>{ $fmt('sync.tip.syncHistory') }</Typography.Text>
}
>
<QuestionCircleOutlined />
</Tooltip>
</Space>
{resultList.map((result) => (
<Alert
Expand Down
21 changes: 17 additions & 4 deletions entrypoints/options/sync/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useState } from 'react';
import { theme, Drawer } from 'antd';
import { theme, Drawer, Button } from 'antd';
import { ClearOutlined } from '@ant-design/icons';
import dayjs from 'dayjs';
import { classNames } from '~/entrypoints/common/utils';
import { useIntlUtls } from '~/entrypoints/common/hooks/global';
Expand Down Expand Up @@ -44,6 +45,11 @@ export default function SyncPage() {
}
};

const clearSyncResult = async () => {
await syncUtils.clearSyncResult(selectedKey);
getSyncInfo();
}

const getSyncInfo = async () => {
syncUtils.getSyncStatus();
setSyncStatus(syncUtils.syncStatus);
Expand Down Expand Up @@ -73,9 +79,16 @@ export default function SyncPage() {
<div
className={classNames('sidebar-inner-box', sidebarCollapsed && 'collapsed')}
>
{/* <div className="sidebar-action-box">
<ToggleSidebarBtn onCollapseChange={setSidebarCollapsed}></ToggleSidebarBtn>
</div> */}
<div className="sidebar-action-box">
{/* <ToggleSidebarBtn onCollapseChange={setSidebarCollapsed}></ToggleSidebarBtn> */}
<div
className="action-icon"
title={$fmt('sync.clearSyncHistory')}
onClick={clearSyncResult}
>
<Button icon={<ClearOutlined />}></Button>
</div>
</div>
<div className="sidebar-inner-content">
<SidebarContent
selectedKey={selectedKey}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "nice-tab",
"description": "A nice, convenient, powerful tab manager [open source]",
"private": true,
"version": "2.2.2",
"version": "2.2.3",
"type": "module",
"scripts": {
"dev": "wxt",
Expand Down

0 comments on commit ae975ce

Please sign in to comment.