From 6a087e659c9c50a86560cf610b711f1ca2c86e9a Mon Sep 17 00:00:00 2001 From: daniyal Date: Mon, 23 Sep 2024 14:56:14 +0500 Subject: [PATCH] fix: show appropriate filters based on searching item --- src/pages/search.tsx | 164 +++++++++++++++++++++++++++++-------------- 1 file changed, 110 insertions(+), 54 deletions(-) diff --git a/src/pages/search.tsx b/src/pages/search.tsx index 7c11dfa..5bace93 100644 --- a/src/pages/search.tsx +++ b/src/pages/search.tsx @@ -51,6 +51,7 @@ interface FilterOptions { sort: SortByEnum moderated: ModeratedFilterEnum searching: SearchingFilterEnum + source: string } export const SearchPage = () => { @@ -61,6 +62,7 @@ export const SearchPage = () => { const [filterOptions, setFilterOptions] = useState({ sort: SortByEnum.Latest, moderated: ModeratedFilterEnum.Moderated, + source: window.location.host, searching: (searchParams.get('searching') as SearchingFilterEnum) || SearchingFilterEnum.Mods @@ -164,73 +166,121 @@ const Filters = React.memo( return (
-
-
- + {filterOptions.searching === SearchingFilterEnum.Mods && ( +
+
+ -
- {Object.values(SortByEnum).map((item, index) => ( -
- setFilterOptions((prev) => ({ - ...prev, - sort: item - })) - } - > - {item} -
- ))} -
-
-
-
-
- -
- {Object.values(ModeratedFilterEnum).map((item, index) => { - if (item === ModeratedFilterEnum.Unmoderated_Fully) { - const isAdmin = - userState.user?.npub === - import.meta.env.VITE_REPORTING_NPUB - - if (!isAdmin) return null - } - - return ( +
+ {Object.values(SortByEnum).map((item, index) => (
setFilterOptions((prev) => ({ ...prev, - moderated: item + sort: item })) } > {item}
- ) - })} + ))} +
-
+ )} + + {(filterOptions.searching === SearchingFilterEnum.Mods || + filterOptions.searching === SearchingFilterEnum.Users) && ( +
+
+ +
+ {Object.values(ModeratedFilterEnum).map((item, index) => { + if (item === ModeratedFilterEnum.Unmoderated_Fully) { + const isAdmin = + userState.user?.npub === + import.meta.env.VITE_REPORTING_NPUB + + if (!isAdmin) return null + } + + return ( +
+ setFilterOptions((prev) => ({ + ...prev, + moderated: item + })) + } + > + {item} +
+ ) + })} +
+
+
+ )} + + {filterOptions.searching === SearchingFilterEnum.Mods && ( +
+
+ +
+
+ setFilterOptions((prev) => ({ + ...prev, + source: window.location.host + })) + } + > + Show From: {window.location.host} +
+
+ setFilterOptions((prev) => ({ + ...prev, + source: 'Show All' + })) + } + > + Show All +
+
+
+
+ )} +