Skip to content

Commit

Permalink
improvement: fixed #33 save expanded status
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanglun committed Oct 26, 2023
1 parent 8b1c198 commit 716dd41
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/components/Subscribes/ItemView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export const ItemView: FC<CardProps> = ({
}));

const handleToggle = () => {
console.log("%c Line:42 🍷 handleToggle", "color:#b03734", feed.item_type);
if (feed.item_type === "folder") {
toggleFolder(uuid);
}
Expand Down
15 changes: 5 additions & 10 deletions src/components/Subscribes/List.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import update from "immutability-helper";
import { useCallback, useEffect, useState } from "react";
import type { CSSProperties } from "react";
import { SubscribeItem } from "./SubscribeItem";
import { useBearStore } from "@/stores";
import { FeedResItem } from "@/db";
import * as dataAgent from "@/helpers/dataAgent";
import { ItemView } from "./ItemView";
import {
adjustedTargetIndex,
findFolderAndIndex,
Expand All @@ -20,6 +18,8 @@ export const List = () => {
getFeedList: state.getFeedList,
feedList: state.feedList,
feed: state.feed,
openFolder: state.openFolder,
closeFolder: state.closeFolder,
}));
const [treeData, setTreeData] = useState<TreeItem[]>([]);
const moveItem = useCallback(
Expand Down Expand Up @@ -213,6 +213,8 @@ export const List = () => {

folder.is_expanded = !folder.is_expanded;

folder.is_expanded ? store.openFolder(folderId) : store.closeFolder(folderId);

setTreeData([...newTreeData]);
};

Expand Down Expand Up @@ -243,14 +245,7 @@ export const List = () => {
);

useEffect(() => {
setTreeData(
[...store.feedList].map((_) => {
return {
..._,
is_expanded: false,
};
})
);
setTreeData([...store.feedList] as TreeItem[]);
}, [store.feedList]);

return (
Expand Down
1 change: 1 addition & 0 deletions src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface FeedResItem {
update_date?: Date;
last_sync_date?: string;
folder_uuid?: string | null;
is_expanded?: boolean;
}
export interface Article {
id?: number;
Expand Down
31 changes: 31 additions & 0 deletions src/stores/createFeedSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export interface FeedSlice {
setFeedContextMenuTarget: (target: FeedResItem | null) => void;
feedContextMenuStatus: boolean;
setFeedContextMenuStatus: (status: boolean) => void;

openFolder: (uuid: string) => void;
closeFolder: (uuid: string) => void;
}

export const createFeedSlice: StateCreator<FeedSlice> = (
Expand Down Expand Up @@ -212,4 +215,32 @@ export const createFeedSlice: StateCreator<FeedSlice> = (
feedContextMenuStatus: status,
}));
},

closeFolder: (uuid: string) => {
let list = get().feedList;

list.forEach(_ => {
if (_.uuid === uuid) {
_.is_expanded = false;
}
});

set(() => ({
feedList: [...list]
}))
},

openFolder: (uuid: string) => {
let list = get().feedList;

list.forEach(_ => {
if (_.uuid === uuid) {
_.is_expanded = true;
}
});

set(() => ({
feedList: [...list]
}))
}
});

0 comments on commit 716dd41

Please sign in to comment.