From 1a8d3eda786bb176d723a48dd96733cad605b2bf Mon Sep 17 00:00:00 2001 From: Oleksandr Holub Date: Sun, 26 Nov 2023 20:41:49 -0600 Subject: [PATCH] added UserInteractionsFilter.tsx --- client/src/components/Button.tsx | 2 +- .../src/screens/LinkList/LinkListScreen.tsx | 2 +- .../LinkListToolbar/LinkListToolbar.tsx | 4 +- .../components/UserInteractionsFilter.tsx | 47 +++++++++++++++++++ client/src/stores/LinkStore.ts | 27 +++++++++-- 5 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 client/src/screens/LinkList/components/LinkListToolbar/components/UserInteractionsFilter.tsx diff --git a/client/src/components/Button.tsx b/client/src/components/Button.tsx index 5c1f134..4404444 100644 --- a/client/src/components/Button.tsx +++ b/client/src/components/Button.tsx @@ -22,7 +22,7 @@ const Button = ({ isLoading, isDisabled, type, className, onClick, children, dis return ( +); + +const UserInteractionsFilter = observer(() => { + const { toggleLikedFilter, toggleSavedFilter, toggleOwnedFilter, state: { filter: { liked, saved, owned }}} = useLinkStore(); + return ( +
+ toggleLikedFilter()} active={liked} groupSide="left"> + + Liked + + toggleSavedFilter()} active={saved} groupSide="middle"> + + Saved + + toggleOwnedFilter()} active={owned} groupSide="right"> + + Owned + +
+ ); +}); + +export default UserInteractionsFilter; \ No newline at end of file diff --git a/client/src/stores/LinkStore.ts b/client/src/stores/LinkStore.ts index 7d8f36e..4850f3b 100644 --- a/client/src/stores/LinkStore.ts +++ b/client/src/stores/LinkStore.ts @@ -7,6 +7,9 @@ import PreviewLink from '../services/LinkService/interfaces/PreviewLink.ts'; type Filter = { tags: string[]; title: string; + liked: boolean; + saved: boolean; + owned: boolean; }; type Preview = { @@ -35,7 +38,10 @@ class LinkStore { tags: [], filter: { tags: [], - title: '' + title: '', + liked: false, + saved: false, + owned: false, }, preview: { } @@ -65,6 +71,21 @@ class LinkStore { await this.getList(); }; + public toggleLikedFilter = async () => { + this.state.filter.liked = !this.state.filter.liked; + await this.getList(); + } + + public toggleSavedFilter = async () => { + this.state.filter.saved = !this.state.filter.saved; + await this.getList(); + } + + public toggleOwnedFilter = async () => { + this.state.filter.owned = !this.state.filter.owned; + await this.getList(); + } + public setFilterTitle = (title: string) => { this.state.filter.title = title; }; @@ -173,7 +194,7 @@ class LinkStore { this.state.tags = this.state.tags.filter(tag => !tagsToRemove.includes(tag)); this.state.filter.tags = this.state.filter.tags.filter(tagName => !tagsToRemove.some(tag => tag.name === tagName)); }); - } + }; public getList = async () => { this.state.isListLoading = true; @@ -186,7 +207,7 @@ class LinkStore { this.state.tags = [...new Set(response.tags)]; this.state.isListLoading = false; }); - } + }; } export default LinkStore; \ No newline at end of file