-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1964 from Plant-for-the-Planet-org/feature/design…
…-projectlist-filter project filter
- Loading branch information
Showing
36 changed files
with
1,189 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { useState, ChangeEvent, useEffect } from 'react'; | ||
import { SearchTextField } from './SearchTextField'; | ||
import CrossIcon from '../icons/CrossIcon'; | ||
import style from './ProjectListControls.module.scss'; | ||
import SearchIcon from '../icons/SearchIcon'; | ||
import { useTranslations } from 'next-intl'; | ||
import { SetState } from '../../features/common/types/common'; | ||
import { useDebouncedEffect } from '../../utils/useDebouncedEffect'; | ||
|
||
interface ActiveSearchFieldProps { | ||
setIsSearching: SetState<boolean>; | ||
setIsFilterOpen: SetState<boolean>; | ||
} | ||
|
||
const ActiveSearchField = ({ | ||
setIsSearching, | ||
setIsFilterOpen, | ||
}: ActiveSearchFieldProps) => { | ||
const [searchValue, setSearchValue] = useState(''); | ||
const [debouncedSearchValue, setDebouncedSearchValue] = useState(''); | ||
|
||
useEffect(() => { | ||
if (debouncedSearchValue) window.alert(`${debouncedSearchValue} searched!`); | ||
}, [debouncedSearchValue]); | ||
|
||
useDebouncedEffect( | ||
() => { | ||
setDebouncedSearchValue(searchValue); | ||
}, | ||
1000, | ||
[searchValue] | ||
); | ||
const t = useTranslations('AllProjects'); | ||
|
||
const resetSearchTab = () => { | ||
setSearchValue(''); | ||
setIsSearching(false); | ||
setIsFilterOpen(false); | ||
}; | ||
|
||
return ( | ||
<div className={style.activeSearchFieldContainer}> | ||
<button className={style.activeSearchIcon}> | ||
<SearchIcon /> | ||
</button> | ||
<SearchTextField | ||
id="standard-search" | ||
variant="standard" | ||
placeholder={t('searchProject')} | ||
value={searchValue} | ||
onChange={(event: ChangeEvent<HTMLInputElement>) => { | ||
setSearchValue(event.target.value); | ||
}} | ||
/> | ||
|
||
<button onClick={resetSearchTab} className={style.crossIcon}> | ||
<CrossIcon /> | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ActiveSearchField; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import style from './ProjectListControls.module.scss'; | ||
import { useTranslations } from 'next-intl'; | ||
import { Classification } from '.'; | ||
import { SetState } from '../../features/common/types/common'; | ||
|
||
interface ClassificationDropDownProps { | ||
selectedClassification: Classification[]; | ||
availableFilters: Classification[]; | ||
setSelectedClassification: SetState<Classification[]>; | ||
} | ||
|
||
export const ClassificationDropDown = ({ | ||
selectedClassification, | ||
availableFilters, | ||
setSelectedClassification, | ||
}: ClassificationDropDownProps) => { | ||
const tAllProjects = useTranslations('AllProjects'); | ||
|
||
const handleFilterSelection = (filterItem: Classification): void => { | ||
if (filterItem === 'allProjects') { | ||
setSelectedClassification([]); | ||
} else { | ||
const newFilter = selectedClassification.includes(filterItem) | ||
? selectedClassification.filter( | ||
(classification) => classification !== filterItem | ||
) | ||
: [...selectedClassification, filterItem]; | ||
setSelectedClassification(newFilter); | ||
} | ||
}; | ||
return ( | ||
<> | ||
{availableFilters.length > 0 ? ( | ||
<div className={style.classificationListContainer}> | ||
<button | ||
className={style.filterButton} | ||
onClick={() => handleFilterSelection('allProjects')} | ||
> | ||
<div | ||
className={ | ||
selectedClassification.length === 0 | ||
? style.classificationSelected | ||
: style.classificationUnselected | ||
} | ||
> | ||
{tAllProjects('classificationTypes.allProjects')} | ||
</div> | ||
<hr className={style.hrLine} /> | ||
</button> | ||
<div> | ||
{availableFilters.map((filterItem, index) => { | ||
return ( | ||
<button | ||
key={index} | ||
className={style.filterButton} | ||
onClick={() => handleFilterSelection(filterItem)} | ||
> | ||
<div | ||
className={ | ||
selectedClassification?.includes(filterItem) | ||
? style.classificationSelected | ||
: style.classificationUnselected | ||
} | ||
> | ||
{tAllProjects(`classificationTypes.${filterItem}`)} | ||
</div> | ||
{index !== availableFilters.length - 1 && ( | ||
<hr className={style.hrLine} /> | ||
)} | ||
</button> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
) : ( | ||
<></> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default ClassificationDropDown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Tab, styled } from '@mui/material'; | ||
import themeProperties from '../../theme/themeProperties'; | ||
|
||
const { light, primaryColorNew } = themeProperties; | ||
const CustomMuiTab = styled(Tab)(() => ({ | ||
flexDirection: 'row', | ||
textTransform: 'none', | ||
padding: '14px 0px', | ||
marginLeft: '19px', | ||
color: `${light.selectedMenuItemColorNew}`, | ||
'&.MuiButtonBase-root.MuiTab-root.Mui-selected': { | ||
color: `${primaryColorNew}`, | ||
}, | ||
})); | ||
|
||
export default CustomMuiTab; |
71 changes: 71 additions & 0 deletions
71
src/temp/ProjectListControls/ProjectListControlForMobile.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React, { useState } from 'react'; | ||
import style from './ProjectListControls.module.scss'; | ||
import ProjectListTabForMobile from './ProjectListTabForMobile'; | ||
import { SearchAndFilter } from './ProjectSearchAndFilter'; | ||
import ViewModeTabs from './ViewModeTabs'; | ||
import ClassificationDropDown from './ClassificationDropDown'; | ||
import { ProjectListControlsProps } from '.'; | ||
import ActiveSearchField from './ActiveSearchField'; | ||
import { Classification } from '.'; | ||
|
||
const ProjectListControlForMobile = ({ | ||
availableFilters, | ||
projectCount, | ||
topProjectCount, | ||
}: ProjectListControlsProps) => { | ||
const [isFilterOpen, setIsFilterOpen] = useState(false); | ||
const [isSearching, setIsSearching] = useState(false); | ||
const [selectedClassification, setSelectedClassification] = useState< | ||
Classification[] | ||
>([]); | ||
const [tabSelected, setTabSelected] = useState<'topProjects' | 'allProjects'>( | ||
'topProjects' | ||
); | ||
|
||
return ( | ||
<> | ||
{isSearching ? ( | ||
<div className={style.searchFieldAndViewTabsContainer}> | ||
<ActiveSearchField | ||
setIsFilterOpen={setIsFilterOpen} | ||
setIsSearching={setIsSearching} | ||
/> | ||
<ViewModeTabs | ||
setIsFilterOpen={setIsFilterOpen} | ||
isSearching={isSearching} | ||
/> | ||
</div> | ||
) : ( | ||
<div className={style.projectListControlsMobile}> | ||
<ProjectListTabForMobile | ||
projectCount={projectCount} | ||
topProjectCount={topProjectCount} | ||
tabSelected={tabSelected} | ||
setTabSelected={setTabSelected} | ||
setIsFilterOpen={setIsFilterOpen} | ||
/> | ||
<SearchAndFilter | ||
selectedClassification={selectedClassification} | ||
setIsFilterOpen={setIsFilterOpen} | ||
isFilterOpen={isFilterOpen} | ||
setIsSearching={setIsSearching} | ||
isSearching={isSearching} | ||
/> | ||
<ViewModeTabs | ||
setIsFilterOpen={setIsFilterOpen} | ||
isSearching={isSearching} | ||
/> | ||
</div> | ||
)} | ||
{isFilterOpen && !isSearching && ( | ||
<ClassificationDropDown | ||
selectedClassification={selectedClassification} | ||
setSelectedClassification={setSelectedClassification} | ||
availableFilters={availableFilters} | ||
/> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default ProjectListControlForMobile; |
Oops, something went wrong.