Skip to content

Commit

Permalink
improvement: proxy settings
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanglun committed Jun 13, 2024
1 parent 67098f4 commit 051b8ab
Show file tree
Hide file tree
Showing 16 changed files with 149 additions and 95 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dependencies": {
"@radix-ui/colors": "^3.0.0",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/themes": "^3.0.5",
"@tailwindcss/line-clamp": "^0.4.4",
"@tanstack/react-table": "^8.10.7",
Expand Down
11 changes: 11 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/components/AddFolder/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const AddFolder = (props: AddFolderProps) => {
const { action, folder } = props;
console.log("%c Line:19 🥪 folder", "color:#ed9ec7", folder);
const store = useBearStore((state) => ({
getFeedList: state.getFeedList,
getSubscribes: state.getSubscribes,
}));
const { dialogStatus, setDialogStatus, afterConfirm, afterCancel, trigger } = props;
const [name, setName] = useState("");
Expand Down Expand Up @@ -60,7 +60,7 @@ export const AddFolder = (props: AddFolderProps) => {
p.then((res) => {
console.log("🚀 ~ file: index.tsx:59 ~ p.then ~ res:", res);
if (res[0] > 0) {
store.getFeedList();
store.getSubscribes();
afterConfirm();
handleCancel();
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ArticleView/Detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export const ArticleDetail = (props: ArticleDetailProps) => {
{article.title}
</Heading>
<div className="flex items-center gap-2 text-sm sm:flex-wrap">
<div className="flex items-center gap-2 rounded-full bg-[var(--gray-4)] pr-3">
<div className="flex items-center gap-2 rounded-full bg-[var(--gray-4)] py-0.5 pl-0.5 pr-3">
<Avatar
radius="full"
className="w-6 h-6"
Expand Down
2 changes: 1 addition & 1 deletion src/components/Subscribes/ItemView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const ItemView: FC<CardProps> = ({ uuid, text, feed, index, isExpanded, t
const store = useBearStore((state) => ({
feed: state.feed,
setFeed: state.setFeed,
getFeedList: state.getFeedList,
getSubscribes: state.getSubscribes,
setFeedContextMenuTarget: state.setFeedContextMenuTarget,
feedContextMenuTarget: state.feedContextMenuTarget,
feedContextMenuStatus: state.feedContextMenuStatus,
Expand Down
12 changes: 6 additions & 6 deletions src/components/Subscribes/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import {

export const List = () => {
const store = useBearStore((state) => ({
getFeedList: state.getFeedList,
setFeedList: state.setFeedList,
feedList: state.feedList,
getSubscribes: state.getSubscribes,
setSubscribes: state.setSubscribes,
subscribes: state.subscribes,
feed: state.feed,
openFolder: state.openFolder,
closeFolder: state.closeFolder,
Expand Down Expand Up @@ -145,7 +145,7 @@ export const List = () => {
console.log("%c Line:225 🍧 list", "color:#2eafb0", list);

setTreeData(() => list);
store.setFeedList(list);
store.setSubscribes(list);

return list;
};
Expand Down Expand Up @@ -246,8 +246,8 @@ export const List = () => {
};

useEffect(() => {
setTreeData([...store.feedList] as TreeItem[]);
}, [store.feedList]);
setTreeData([...store.subscribes] as TreeItem[]);
}, [store.subscribes]);

return (
<div>
Expand Down
16 changes: 8 additions & 8 deletions src/components/Subscribes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const ChannelList = (): JSX.Element => {
const [deleteFolderStatus, setDeleteFolderStatus] = useModal();
const [editFeedStatus, setEditFeedStatus] = useModal();
const [showStatus, setModalStatus] = useModal();
const [feedList, setFeedList, getFeedList, refreshing, setRefreshing, done, setDone, startRefresh] = useRefresh();
const [feedList, setFeedList, getSubscribes, refreshing, setRefreshing, done, setDone, startRefresh] = useRefresh();
const store = useBearStore((state) => ({
feed: state.feed,
setFeed: state.setFeed,
Expand All @@ -79,9 +79,9 @@ const ChannelList = (): JSX.Element => {
}, []);

useEffect(() => {
getFeedList();
getSubscribes();
const unsubscribeGetChannels = busChannel.on("getChannels", () => {
getFeedList();
getSubscribes();
});

return () => {
Expand Down Expand Up @@ -116,7 +116,7 @@ const ChannelList = (): JSX.Element => {
toast.promise(dataAgent.markAllRead({ uuid, isToday: !!isToday, isAll: !!isAll }), {
loading: "Loading...",
success: (data) => {
getFeedList();
getSubscribes();
store.initCollectionMetas();

if (store.feed?.uuid === uuid) {
Expand Down Expand Up @@ -185,7 +185,7 @@ const ChannelList = (): JSX.Element => {
store.setFeedContextMenuTarget(null);
}

getFeedList();
getSubscribes();
};

const afterUnsubscribeFeed = () => {
Expand All @@ -197,7 +197,7 @@ const ChannelList = (): JSX.Element => {
store.setFeedContextMenuTarget(null);
}

getFeedList();
getSubscribes();
};

return (
Expand Down Expand Up @@ -398,15 +398,15 @@ const ChannelList = (): JSX.Element => {
feed={store.feedContextMenuTarget}
dialogStatus={editFeedStatus}
setDialogStatus={setEditFeedStatus}
afterConfirm={getFeedList}
afterConfirm={getSubscribes}
afterCancel={() => store.setFeedContextMenuTarget(null)}
/>
<AddFolder
action="edit"
folder={store.feedContextMenuTarget as FolderResItem | null}
dialogStatus={editFolderDialogStatus}
setDialogStatus={setEditFolderDialogStatus}
afterConfirm={getFeedList}
afterConfirm={getSubscribes}
afterCancel={() => store.setFeedContextMenuTarget(null)}
/>
</div>
Expand Down
25 changes: 12 additions & 13 deletions src/components/Subscribes/useRefresh.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useEffect, useRef, useState } from "react";
import pLimit from "p-limit";
import { FeedResItem } from "@/db";
import * as dataAgent from "@/helpers/dataAgent";
import { useBearStore } from "@/stores";

export const useRefresh = () => {
Expand All @@ -11,8 +10,8 @@ export const useRefresh = () => {

setLastSyncTime: state.setLastSyncTime,

feedList: state.feedList,
getFeedList: state.getFeedList,
subscribes: state.subscribes,
getSubscribes: state.getSubscribes,
updateFeed: state.updateFeed,
feed: state.feed,

Expand All @@ -24,8 +23,8 @@ export const useRefresh = () => {
const [done, setDone] = useState<number>(0);
const timeRef = useRef<any>();

const getFeedList = () => {
store.getFeedList();
const getSubscribes = () => {
store.getSubscribes();
};

const loadAndUpdate = (channel: FeedResItem) => {
Expand Down Expand Up @@ -60,7 +59,7 @@ export const useRefresh = () => {

const { threads = 5 } = config;
const limit = pLimit(threads);
const fns = (store.feedList || []).map((channel: any) => {
const fns = (store.subscribes || []).map((channel: any) => {
return limit(() => loadAndUpdate(channel));
});

Expand All @@ -69,7 +68,7 @@ export const useRefresh = () => {
.finally(() => {
setRefreshing(false);
setDone(0);
getFeedList();
getSubscribes();
// loop();
});
});
Expand All @@ -89,9 +88,9 @@ export const useRefresh = () => {
}

useEffect(() => {
console.log("%c Line:93 🥕 feedList", "color:#33a5ff", store.feedList);
console.log("%c Line:93 🥕 subscribes", "color:#33a5ff", store.subscribes);

if (!store.feedList || store.feedList.length === 0) {
if (!store.subscribes || store.subscribes.length === 0) {
return ;
}

Expand All @@ -114,12 +113,12 @@ export const useRefresh = () => {
return () => {
clearTimeout(timeRef.current);
};
}, [store.feedList, store.userConfig.update_interval]);
}, [store.subscribes, store.userConfig.update_interval]);

return [
store.feedList,
store.getFeedList,
getFeedList,
store.subscribes,
store.getSubscribes,
getSubscribes,
refreshing,
setRefreshing,
done,
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/dataAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const getChannels = async (
});
};

export const getFeeds = async (): Promise<AxiosResponse<FeedResItem[]>> => {
export const getSubscribes = async (): Promise<AxiosResponse<FeedResItem[]>> => {
return request.get("subscribes");
};

Expand Down
4 changes: 2 additions & 2 deletions src/layout/Local/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function LocalPage() {
feed: state.feed,
updateSettingDialogStatus: state.updateSettingDialogStatus,
}));
const [feedList, setFeedList, getFeedList, refreshing, setRefreshing, done, setDone, startRefresh] = useRefresh();
const [feedList, setFeedList, getSubscribes, refreshing, setRefreshing, done, setDone, startRefresh] = useRefresh();
const [addFolderDialogStatus, setAddFolderDialogStatus] = useModal();

useEffect(() => {
Expand Down Expand Up @@ -66,7 +66,7 @@ export function LocalPage() {
action="add"
dialogStatus={addFolderDialogStatus}
setDialogStatus={setAddFolderDialogStatus}
afterConfirm={getFeedList}
afterConfirm={getSubscribes}
afterCancel={() => {}}
trigger={
<IconButton variant="ghost" size="2" color="gray" className="text-[var(--gray-12)]">
Expand Down
2 changes: 1 addition & 1 deletion src/layout/Setting/ImportAndExport/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export const ImportAndExport = (props: any) => {
const exportToOPML = () => {
setExporting(true);
dataAgent
.getFeeds()
.getSubscribes()
.then(({ data: feeds }) => {
const doc = createOPMLObj(feeds);
const serializer = new XMLSerializer();
Expand Down
Loading

0 comments on commit 051b8ab

Please sign in to comment.