Repository navigation
Add search to the projects page #1483
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4f817e9
feat(projects): search the project list by name and description
mihow 81a11a2
feat(ui): add a search box to the projects page
mihow 2fb6692
fix(ui): keep the project search box in step with the URL
mihow 4a0d980
test: drop the search test that repeats the draft visibility tests
mihow 13e87cc
test: build the project search test data once per class
mihow 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { SearchIcon } from 'lucide-react' | ||
| import { useEffect, useRef, useState } from 'react' | ||
|
|
||
| const DEBOUNCE_DELAY = 300 | ||
|
|
||
| export const SearchInput = ({ | ||
| label, | ||
| value, | ||
| onChange, | ||
| }: { | ||
| label: string | ||
| value: string | ||
| onChange: (value: string) => void | ||
| }) => { | ||
| const [searchString, setSearchString] = useState(value) | ||
| const timeoutRef = useRef<ReturnType<typeof setTimeout>>() | ||
|
|
||
| // Follow the value when it changes from outside the box, for example on | ||
| // browser Back, and drop any pending change so it cannot restore the old term. | ||
| // A value that only differs by surrounding spaces is the box's own update. | ||
| useEffect(() => { | ||
| clearTimeout(timeoutRef.current) | ||
| setSearchString((current) => (current.trim() === value ? current : value)) | ||
| }, [value]) | ||
|
|
||
| useEffect(() => () => clearTimeout(timeoutRef.current), []) | ||
|
|
||
| const onInputChange = (newSearchString: string) => { | ||
| setSearchString(newSearchString) | ||
| clearTimeout(timeoutRef.current) | ||
| timeoutRef.current = setTimeout(() => { | ||
| if (newSearchString.trim() !== value) { | ||
| onChange(newSearchString.trim()) | ||
| } | ||
| }, DEBOUNCE_DELAY) | ||
| } | ||
|
|
||
| return ( | ||
| <div className="flex items-center h-8 w-56 gap-2 px-4 rounded-full border border-input bg-background focus-within:ring-2 focus-within:ring-ring"> | ||
| <SearchIcon className="w-4 h-4 shrink-0 text-muted-foreground" /> | ||
| <input | ||
| aria-label={label} | ||
| className="w-full h-full pt-0.5 bg-transparent body-small outline-none placeholder:text-muted-foreground" | ||
| placeholder={label} | ||
| type="search" | ||
| value={searchString} | ||
| onChange={(e) => onInputChange(e.target.value)} | ||
| /> | ||
| </div> | ||
| ) | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { useSearchParams } from 'react-router-dom' | ||
| import { SEARCH_PARAM_KEY_PAGE } from './usePagination' | ||
|
|
||
| const SEARCH_PARAM_KEY_SEARCH = 'search' | ||
|
|
||
| export const useSearch = () => { | ||
| const [searchParams, setSearchParams] = useSearchParams() | ||
| const search = searchParams.get(SEARCH_PARAM_KEY_SEARCH) ?? '' | ||
|
|
||
| const setSearch = (search: string) => { | ||
| // New results start from the first page. | ||
| searchParams.delete(SEARCH_PARAM_KEY_PAGE) | ||
| searchParams.delete(SEARCH_PARAM_KEY_SEARCH) | ||
|
|
||
| if (search.length) { | ||
| searchParams.set(SEARCH_PARAM_KEY_SEARCH, search) | ||
| } | ||
|
|
||
| setSearchParams(searchParams) | ||
| } | ||
|
|
||
| return { search, setSearch } | ||
| } |
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.