Skip to content
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

feat(sort-filter): search project by name #533

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

NicoSerranoP
Copy link
Member

@NicoSerranoP NicoSerranoP commented Dec 6, 2024

Description
I am activating the new feature to search projects by name using the search bar. Behind the scenes what I am doing is I am taking the registryAddress and the search bar input and sending it to the server to perform a search. The server fetches all the metadata objects and add them to the projects. Later on it filters them comparing the search value and the metadata.name value.

Considerations
This current implementation performs the search on the server because it avoids problems with React <InfiniteLoading> and useinfiniteQuery in the client side. These two use pagination for better data efficiency and I did not want to break that feature.

Changes made

  • Implement search projects by name feature
  • Improve server fetching for performance
  • Housekeeping to delete console.log errors
  • Housekeeping to prevent hydration errors

@ctrlc03 @kittybest @crisgarner @0xmad what do you think? 😊

Copy link

vercel bot commented Dec 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
maci-platform ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 17, 2024 5:47pm

@0xmad
Copy link
Collaborator

0xmad commented Dec 9, 2024

You can use useInfiniteQuery for pagination support and throttling or debouncing support with useDeferredValue to not send requests every time you type something in a search bar. Current solution is not optimized if we have a big number of projects and it sends the requests on every search input change.

Copy link
Contributor

@kittybest kittybest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot! Just have a comment

Comment on lines 44 to +46
options={["name_asc", "name_desc"]}
value={`${orderBy}_${sortOrder}`}
onChange={async (sort) => {
const [order, sorting] = sort.split("_") as [OrderBy, SortOrder];

await setFilter({ orderBy: order, sortOrder: sorting }).catch();
}}
onChange={onChangeSortByDropdown}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we should have all the sortLabels back? including the time_asc and time_desc

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just moved the onChangeSortByDropdown code above to use it with useCallback to make it a bit more efficient 😊

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My question is this sort only contains these two:
image

There should be time_asc and time_desc as well, now there's only options={["name_asc", "name_desc"]}, and it's not actually working even if I change the sortBy value.
But of course we could put this another issue.

@aguzmant103 aguzmant103 linked an issue Dec 10, 2024 that may be closed by this pull request
@NicoSerranoP
Copy link
Member Author

You can use useInfiniteQuery for pagination support and throttling or debouncing support with useDeferredValue to not send requests every time you type something in a search bar. Current solution is not optimized if we have a big number of projects and it sends the requests on every search input change.

I added the useDeferredValue in the Projects.tsx component. Is that okay? 😊

@0xmad
Copy link
Collaborator

0xmad commented Dec 11, 2024

You can use useInfiniteQuery for pagination support and throttling or debouncing support with useDeferredValue to not send requests every time you type something in a search bar. Current solution is not optimized if we have a big number of projects and it sends the requests on every search input change.

I added the useDeferredValue in the Projects.tsx component. Is that okay? 😊

You still need to use useInfiniteQuery for pagination support. Also, there are some configuration for requests optimization.
Imagine if you have a big number of projects and they all starts with your search input value. You fetch them all but you only need one page of results.

@NicoSerranoP
Copy link
Member Author

@kittybest @0xmad hi guys! 😊

I added the fixes for your current comments and also pushed my housekeeping fixes to prevent console errors. Could you review the file changes? I added a comment to each file to explain a bit more what I was doing.

After your final approval I will squash the commits to merge this PR

Thank you for your help :)

Copy link
Collaborator

@0xmad 0xmad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NicoSerranoP thanks, just some changes requested

packages/interface/src/components/ImageUpload.tsx Outdated Show resolved Hide resolved
Comment on lines 24 to 25
// eslint-disable-next-line @typescript-eslint/no-unused-vars
ref: PolymorphicRef<ElementType>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't use this ref, you don't need to add it as second param

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried but I am getting a console log error saying that forwardRef needs a function that receives two parameters and it is not possible to remove the second one (ref). What I did is change its name to _ and removed the types

control={control}
name={name}
render={({ field: { value, onChange, ...field } }) => (
// eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

div shouldn't have onClick handlers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This div contains the upload image button and the div icon. I tried to change <div> to <button> but it didn't work (we cannot have nested buttons)

packages/interface/src/components/ImageUpload.tsx Outdated Show resolved Hide resolved
packages/interface/src/components/ImageUpload.tsx Outdated Show resolved Hide resolved
packages/interface/src/components/ImageUpload.tsx Outdated Show resolved Hide resolved
packages/interface/src/utils/fetchProjects.ts Outdated Show resolved Hide resolved
feat(sort-filter): get projects with metadata from server

feat(sort-filter): search by name on the server

fix(frontend): fix small react bugs

fix(frontend): fix favicon.svg call in html meta

fix(main): view projects button as router and not link

fix(form): prevent undefined url call

fix(frontend): activate ssr to prevent hydration errors

fix(search): useDeferredValue to lag behind on search

fix(image): prevent console.log error

fix(image): pr comments

fix(search): single if

/**
* Fetch all approved projects with metadata
* @param registryAddress
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's another param called search

Copy link
Contributor

@kittybest kittybest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for also the housekeeping! But maybe split the housekeeping part in another PR better in the future? make single PR only focus on single stuff.
For this PR is totally fine :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

Implement project search in registries branch
3 participants