Repository navigation
feat: add search functionality in chapterDashboard - #2301
Conversation
👇 Click on the image for a new way to code review
Legend |
| const filteredChapter = useMemo( | ||
| () => | ||
| data.dashboardChapters.filter(({ name }) => | ||
| name.toLowerCase().includes(search), | ||
| ), | ||
| [data, search], | ||
| ); |
There was a problem hiding this comment.
Is this failing because it relies on a condition? The hooks run on mount, but the data is got on load?
There was a problem hiding this comment.
RIP performance, I guess 🤣. maybe I can move the logic into the top and create a function that run it, but idk if that is actually worth it, while this works
There was a problem hiding this comment.
To make it work it would need to be put before if (isLoading || error) return <DashboardLoading error={error} />;, as that condition sometimes can render before the useMemo is used it will make the hook error appear. It might not be worth to for useMemo here at all, as search will be changing at each character anyway.
gikf
left a comment
There was a problem hiding this comment.
Works nicely 🚀.
There isn't any issue with complexity, but was there some specific reason for not attempting using useState for the filter string, instead of opting for useReducer?
There's couple nitpicks below.
The search field is not very visually separated from the Add new button. It makes it appear on the first look, like both of them are related.

Moving filter field to it own line might be the quickest way to clearly give them both their own space:

What do you think?
| const filteredChapter = useMemo( | ||
| () => | ||
| data.dashboardChapters.filter(({ name }) => | ||
| name.toLowerCase().includes(search), | ||
| ), | ||
| [data, search], | ||
| ); |
There was a problem hiding this comment.
To make it work it would need to be put before if (isLoading || error) return <DashboardLoading error={error} />;, as that condition sometimes can render before the useMemo is used it will make the hook error appear. It might not be worth to for useMemo here at all, as search will be changing at each character anyway.
Co-authored-by: gikf <60067306+gikf@users.noreply.github.com>
I had more experience with |
Co-authored-by: Krzysztof G. <60067306+gikf@users.noreply.github.com>
With |
ojeytonwilliams
left a comment
There was a problem hiding this comment.
I feel bad asking you to replace the reducer, but it's more than we need here.
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
| ]; | ||
|
|
||
| export const ChaptersPage: NextPageWithLayout = () => { | ||
| const [filterChapter, setFilterChapter] = useState(''); |
There was a problem hiding this comment.
did you know that the type will fail if it's {filterChapter, setFilterChapter}. I have spent a good while on it, trying to use generics, until I gave up and copied hasMore into it.
The failing type is, in hindsight, I should have noticed the array 🤣
[string, Dispatch<setStateAction>]
There was a problem hiding this comment.
hasMore? The code you've written seems fine as is.
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
Requested change was implemented

Update README.md).mainbranch of Chapter.Because of the sort of the data in this PR #2291, I thought maybe a filter function is a due. This should be in Utils later, but for now I am testing it in chapterPages