-
Notifications
You must be signed in to change notification settings - Fork 9
Add filter in portal team view #2016
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
CoolGame8
wants to merge
10
commits into
main
Choose a base branch
from
Add-filter-in-portal-team-view
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2085a67
Add filter in portal team view
CoolGame8 d5d4d4e
Add search functionality to portal teams view
CoolGame8 3ca4fdf
Fix exhaustive-deps warning in team list search effect
CoolGame8 25ca8ab
Merge remote-tracking branch 'origin/main' into Add-filter-in-portal-…
johnmeshulam 75ca3d2
better search
CoolGame8 5ced555
fix team list search
CoolGame8 7dea882
Merge remote-tracking branch 'origin/main' into Add-filter-in-portal-…
CoolGame8 1922494
search bar design
CoolGame8 cc20e74
fixes
CoolGame8 4a3add0
Merge branch 'main' into Add-filter-in-portal-team-view
CoolGame8 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
73 changes: 73 additions & 0 deletions
73
apps/portal/src/app/[locale]/teams/components/team-search-input.tsx
This file contains hidden or 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,73 @@ | ||
| 'use client'; | ||
|
|
||
| import { useRef, useEffect } from 'react'; | ||
| import { TextField, InputAdornment, IconButton } from '@mui/material'; | ||
| import { Search as SearchIcon, Clear as ClearIcon } from '@mui/icons-material'; | ||
|
|
||
| interface TeamSearchInputProps { | ||
| initialValue: string; | ||
| placeholder: string; | ||
| onSearchChange: (value: string) => void; | ||
| onClear: () => void; | ||
| showClearButton: boolean; | ||
| } | ||
|
|
||
| export const TeamSearchInput: React.FC<TeamSearchInputProps> = ({ | ||
| initialValue, | ||
| placeholder, | ||
| onSearchChange, | ||
| onClear, | ||
| showClearButton | ||
| }) => { | ||
| const inputRef = useRef<HTMLInputElement>(null); | ||
| const debounceTimerRef = useRef<NodeJS.Timeout | undefined>(undefined); | ||
|
|
||
| useEffect(() => { | ||
| if (inputRef.current && inputRef.current.value !== initialValue) { | ||
| inputRef.current.value = initialValue; | ||
| } | ||
| }, [initialValue]); | ||
|
|
||
| const handleInput = (value: string) => { | ||
| if (debounceTimerRef.current) { | ||
| clearTimeout(debounceTimerRef.current); | ||
| } | ||
| debounceTimerRef.current = setTimeout(() => { | ||
| onSearchChange(value); | ||
| }, 300); | ||
| }; | ||
|
|
||
| const handleClear = () => { | ||
| if (inputRef.current) { | ||
| inputRef.current.value = ''; | ||
| } | ||
| onClear(); | ||
| }; | ||
|
|
||
| return ( | ||
| <TextField | ||
| fullWidth | ||
| size="small" | ||
| placeholder={placeholder} | ||
| defaultValue={initialValue} | ||
| onChange={e => handleInput(e.target.value)} | ||
| inputRef={inputRef} | ||
| slotProps={{ | ||
| input: { | ||
| startAdornment: ( | ||
| <InputAdornment position="start"> | ||
| <SearchIcon /> | ||
| </InputAdornment> | ||
| ), | ||
| endAdornment: showClearButton && ( | ||
| <InputAdornment position="end"> | ||
| <IconButton size="small" onClick={handleClear} edge="end"> | ||
| <ClearIcon /> | ||
| </IconButton> | ||
| </InputAdornment> | ||
| ) | ||
| } | ||
| }} | ||
| /> | ||
| ); | ||
| }; |
116 changes: 116 additions & 0 deletions
116
apps/portal/src/app/[locale]/teams/components/teams-page-header.tsx
This file contains hidden or 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,116 @@ | ||
| 'use client'; | ||
|
|
||
| import React from 'react'; | ||
| import useSWR from 'swr'; | ||
| import { useRouter, useSearchParams } from 'next/navigation'; | ||
| import { useTranslations } from 'next-intl'; | ||
| import { Box, FormControl, InputLabel, MenuItem, Select, Stack, Typography } from '@mui/material'; | ||
| import { RichText } from '@lems/localization'; | ||
| import { Flag } from '@lems/shared'; | ||
| import { TeamSearchInput } from './team-search-input'; | ||
|
|
||
| export const TeamsPageHeader: React.FC = () => { | ||
| const t = useTranslations('pages.teams'); | ||
| const router = useRouter(); | ||
| const searchParams = useSearchParams(); | ||
| const region = searchParams.get('region') || ''; | ||
| const search = searchParams.get('search') || ''; | ||
|
|
||
| const { data: regions = [] } = useSWR<string[]>('/portal/teams/regions', { | ||
| fallbackData: [] | ||
| }); | ||
|
|
||
| const handleRegionChange = (newRegion: string) => { | ||
| const params = new URLSearchParams(searchParams.toString()); | ||
| if (newRegion) { | ||
| params.set('region', newRegion); | ||
| } else { | ||
| params.delete('region'); | ||
| } | ||
| params.set('page', '1'); | ||
| router.replace(`?${params.toString()}`, { scroll: false }); | ||
| }; | ||
|
|
||
| const handleSearchChange = (searchValue: string) => { | ||
| const params = new URLSearchParams(searchParams.toString()); | ||
| if (searchValue.trim()) { | ||
| params.set('search', searchValue.trim()); | ||
| } else { | ||
| params.delete('search'); | ||
| } | ||
| params.set('page', '1'); | ||
| router.replace(`?${params.toString()}`, { scroll: false }); | ||
| }; | ||
|
|
||
| const handleClearSearch = () => { | ||
| const params = new URLSearchParams(searchParams.toString()); | ||
| params.delete('search'); | ||
| params.set('page', '1'); | ||
| router.replace(`?${params.toString()}`, { scroll: false }); | ||
| }; | ||
|
|
||
| return ( | ||
| <Stack spacing={3} sx={{ mb: 4 }}> | ||
| <Typography | ||
| variant="h3" | ||
| component="h1" | ||
| sx={{ | ||
| fontWeight: 'bold', | ||
| fontSize: { xs: '1.75rem', sm: '2.25rem', md: '2.75rem' } | ||
| }} | ||
| > | ||
| {<RichText>{tags => t.rich('title', tags)}</RichText>} | ||
| </Typography> | ||
|
|
||
| <Box | ||
| sx={{ | ||
| display: 'flex', | ||
| flexDirection: 'row', | ||
| gap: 2, | ||
| alignItems: 'flex-start' | ||
| }} | ||
| > | ||
| <Box sx={{ flex: 1, minWidth: 0 }}> | ||
| <TeamSearchInput | ||
| initialValue={search} | ||
| placeholder={t('search.placeholder')} | ||
| onSearchChange={handleSearchChange} | ||
| onClear={handleClearSearch} | ||
| showClearButton={!!search} | ||
| /> | ||
| </Box> | ||
|
|
||
| <FormControl size="small" sx={{ minWidth: 120, flexShrink: 0 }}> | ||
| <InputLabel>{t('region.label')}</InputLabel> | ||
| <Select | ||
| value={region} | ||
| label={t('region.label')} | ||
| onChange={e => handleRegionChange(e.target.value)} | ||
| renderValue={value => ( | ||
| <Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}> | ||
| {value ? ( | ||
| <> | ||
| <Flag region={value} size={20} /> | ||
| {value} | ||
| </> | ||
| ) : ( | ||
| t('region.all') | ||
| )} | ||
| </Box> | ||
| )} | ||
| > | ||
| <MenuItem value="">{t('region.all')}</MenuItem> | ||
| {regions?.map(r => ( | ||
| <MenuItem key={r} value={r}> | ||
| <Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}> | ||
| <Flag region={r} size={20} /> | ||
| {r} | ||
| </Box> | ||
| </MenuItem> | ||
| ))} | ||
| </Select> | ||
| </FormControl> | ||
| </Box> | ||
| </Stack> | ||
| ); | ||
| }; |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.