From 661aa7a771989214e4573a8ee49f05bbe9274672 Mon Sep 17 00:00:00 2001 From: DeanYona Date: Sun, 21 Apr 2024 20:32:03 +0300 Subject: [PATCH 1/2] organize-filtersWindow --- components/Projects/FiltersBar/FiltersBar.tsx | 64 +++------------ .../Projects/FiltersBar/FiltersWindow.tsx | 79 +++++++++++++++++++ 2 files changed, 90 insertions(+), 53 deletions(-) create mode 100644 components/Projects/FiltersBar/FiltersWindow.tsx diff --git a/components/Projects/FiltersBar/FiltersBar.tsx b/components/Projects/FiltersBar/FiltersBar.tsx index 22aa254..fb1ad0e 100644 --- a/components/Projects/FiltersBar/FiltersBar.tsx +++ b/components/Projects/FiltersBar/FiltersBar.tsx @@ -11,6 +11,7 @@ import Link from 'next/link'; import { ProjectPaginationFilter } from '@/types/project'; import { useTranslations } from 'next-intl'; import { SearchInput } from '@/components/Common/Inputs/SearchInput'; +import FiltersWindow from './FiltersWindow'; interface FiltersBarProps { filters: ProjectFilter[]; @@ -115,59 +116,16 @@ const FiltersBar: React.FC = ({ height={27} /> {/* settings window on burger click */} - {toggleFiltersWindow ? ( - <> -
-
-

- {t('projectsFilters')}{' '} -

- {/* sort by ProjectPaginationFilter (sortoptions,sortoptionsmapper) */} -
- - {t('filters')} - -
- {sortOptions.map(sortOption => ( - - ))} -
-
- {/* sort by set languages */} -
- - {t('tags')} - -
- {filters.map(filter => ( - - handleFilterOptionChange(filter) - } - isSelected={filter.isActive} - /> - ))} -
-
-
-
-
-
-
-
- - ) : null} + {toggleFiltersWindow && ( + + )}
; + sortOptions: string[]; + selectedSortOption: any; + handleCategoryOptionSelection: any; + filters: ProjectFilter[]; + handleFilterOptionChange: any; +} + +const FiltersWindow = ({ + filterRef, + sortOptions, + selectedSortOption, + handleCategoryOptionSelection, + filters, + handleFilterOptionChange, +}: FiltersWindow) => { + const t = useTranslations('Projects.FiltersBar'); + + return ( +
+
+
+

+ {t('projectsFilters')}{' '} +

+ {/* sort by ProjectPaginationFilter (sortoptions,sortoptionsmapper) */} +
+ + {t('filters')} + +
+ {sortOptions.map(sortOption => ( + + ))} +
+
+ {/* sort by set languages */} +
+ + {t('tags')} + +
+ {filters.map(filter => ( + handleFilterOptionChange(filter)} + isSelected={filter.isActive} + /> + ))} +
+
+
+
+
+
+
+
+
+ ); +}; + +export default FiltersWindow; From 2b7a6e85c50845ae773d2bb0c3d97aeba3d01a04 Mon Sep 17 00:00:00 2001 From: DeanYona Date: Tue, 23 Apr 2024 00:51:26 +0300 Subject: [PATCH 2/2] fix-tags-toggling --- app/[locale]/projects/page.tsx | 17 ++++++++++++++--- .../Projects/FiltersBar/FilterBtnsGroup.tsx | 8 ++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/[locale]/projects/page.tsx b/app/[locale]/projects/page.tsx index 28001d2..805503f 100644 --- a/app/[locale]/projects/page.tsx +++ b/app/[locale]/projects/page.tsx @@ -42,12 +42,23 @@ const ProjectsPage = () => { setLoading(true); const existingTags = structuredClone(tags); - // we set tag active to true - for (const exisitingTag of existingTags) { + // we set tags chosen to active and all the others to not + if (existingTags.every(value => value.isActive)) { + existingTags.forEach(existingTag => { + existingTag.isActive = false; + }); + } + + existingTags.forEach(exisitingTag => { if (exisitingTag.name === tag.name) { exisitingTag.isActive = !exisitingTag.isActive; - break; } + }); + + if (existingTags.every(value => !value.isActive)) { + existingTags.forEach(existingTag => { + existingTag.isActive = true; + }); } setTags(existingTags); diff --git a/components/Projects/FiltersBar/FilterBtnsGroup.tsx b/components/Projects/FiltersBar/FilterBtnsGroup.tsx index 8c5804e..4de1d13 100644 --- a/components/Projects/FiltersBar/FilterBtnsGroup.tsx +++ b/components/Projects/FiltersBar/FilterBtnsGroup.tsx @@ -12,9 +12,9 @@ const FilterBtnsGroup = ({ filters, handleFilterOptionChange, }: FilterBtnsGroupProps) => { - const handleBtnFilterClick = (filter: ProjectFilter) => { - handleFilterOptionChange(filter); - }; + // const handleBtnFilterClick = (filter: ProjectFilter) => { + // handleFilterOptionChange(filter); + // }; return (
@@ -22,7 +22,7 @@ const FilterBtnsGroup = ({ handleBtnFilterClick(filter)} + onBtnClick={() => handleFilterOptionChange(filter)} /> ))}