-
Notifications
You must be signed in to change notification settings - Fork 46
Global Search #624
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
+551
−198
Merged
Global Search #624
Changes from 8 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e21783e
feat: add search input to top bar with localization support
omdxp 9c939c8
feat: implement search modal and enhance top bar with search function…
omdxp 284361b
feat: enhance search functionality and update contribution types for …
omdxp 926b66b
feat: add localized labels for search contributions, contributors, an…
omdxp 32c87a0
feat: update top bar to include a search button and improve modal dis…
omdxp aeacf86
refactor: update contribution, contributor, and project types for imp…
omdxp 7e05fb9
refactor: update search component to use entity models for improved t…
omdxp ec6df46
feat: enhance search component with loading state and localized messa…
omdxp a20f438
refactor: update import paths for project, contributor, and contribut…
omdxp 622a8cb
feat: add query parameters type to Search endpoint for enhanced reada…
omdxp c5aa5be
refactor: move keyboard event handling to Search component for better…
omdxp 7693ae4
feat: implement useSearchModal hook for improved modal handling in Se…
omdxp b4423aa
refactor: update logo import and adjust button sizes in TopBar for im…
omdxp 9769b26
refactor: rename contribute-card to contribution-card and update impo…
omdxp 7132657
refactor: update search component to use typed responses for projects…
omdxp 2917da6
refactor: update TopBar search input to be read-only and enhance clic…
omdxp 0277c2d
refactor: simplify results handling in Search component and initializ…
omdxp 920b065
refactor: move onKeyDown function inside useEffect for better encapsu…
omdxp 3af1e4e
refactor: update ContributorCard and TopBar components for consistenc…
omdxp 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| import React, { useCallback, useMemo, useState } from "react"; | ||
| import { Locale, useLocale } from "./locale"; | ||
| import ProjectCard from "src/pages/projects/project-card"; | ||
| import ContributorCard from "src/pages/team/contributor-card"; | ||
| import ContributionCard from "src/pages/contribute/contribute-card"; | ||
| import { useSearch } from "src/utils/search"; | ||
| import { ProjectEntity } from "@dzcode.io/models/dist/project"; | ||
| import { ContributorEntity } from "@dzcode.io/models/dist/contributor"; | ||
| import { ContributionEntity } from "@dzcode.io/models/dist/contribution"; | ||
| import { RepositoryEntity } from "@dzcode.io/models/dist/repository"; | ||
|
|
||
| export function Search(): JSX.Element { | ||
| const { localize } = useLocale(); | ||
| const [query, setQuery] = useState(""); | ||
|
|
||
| const { results, isFetching } = useSearch(query); | ||
|
|
||
| const hideModal = useCallback(() => { | ||
| (document.getElementById("search-modal") as HTMLDialogElement).hidePopover(); | ||
| }, []); | ||
|
|
||
| const onSearchInputChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => { | ||
| setQuery(e.target.value); | ||
| }, []); | ||
|
|
||
| const projectsList = useMemo(() => { | ||
| return (results?.searchResults.results || []) | ||
| .filter((result) => result.indexUid === "project") | ||
| .flatMap((projects) => projects.hits) as unknown as Array< | ||
ZibanPirate marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Pick<ProjectEntity, "id" | "name"> & { | ||
| totalRepoContributorCount: number; | ||
| totalRepoScore: number; | ||
| totalRepoStars: number; | ||
| ranking: number; | ||
| } | ||
| >; | ||
| }, [results?.searchResults.results]); | ||
|
|
||
| const contributorsList = useMemo(() => { | ||
| return (results?.searchResults.results || []) | ||
| .filter((result) => result.indexUid === "contributor") | ||
| .flatMap((contributors) => contributors.hits) as unknown as Array< | ||
ZibanPirate marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Pick<ContributorEntity, "id" | "name" | "avatarUrl"> & { | ||
| ranking: number; | ||
| totalContributionScore: number; | ||
| totalRepositoryCount: number; | ||
| } | ||
| >; | ||
| }, [results?.searchResults.results]); | ||
|
|
||
| const contributionsList = useMemo(() => { | ||
| return (results?.searchResults.results || []) | ||
| .filter((result) => result.indexUid === "contribution") | ||
| .flatMap((contributions) => contributions.hits) as unknown as Array< | ||
ZibanPirate marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Pick<ContributionEntity, "id" | "title" | "type" | "url" | "updatedAt" | "activityCount"> & { | ||
| repository: Pick<RepositoryEntity, "id" | "owner" | "name"> & { | ||
| project: Pick<ProjectEntity, "id" | "name">; | ||
| }; | ||
| contributor: Pick<ContributorEntity, "id" | "name" | "username" | "avatarUrl">; | ||
| } | ||
| >; | ||
| }, [results?.searchResults.results]); | ||
|
|
||
| const searchTextOutput = useMemo(() => { | ||
| if (isFetching) { | ||
| return ""; | ||
| } | ||
| if (query === "") { | ||
| return localize("search-type-to-search"); | ||
| } | ||
| if ( | ||
| projectsList.length === 0 && | ||
| contributorsList.length === 0 && | ||
| contributionsList.length === 0 | ||
| ) { | ||
| return localize("search-no-results-found"); | ||
| } | ||
| return ""; | ||
| }, [ | ||
| isFetching, | ||
| query, | ||
| projectsList.length, | ||
| contributorsList.length, | ||
| contributionsList.length, | ||
| localize, | ||
| ]); | ||
|
|
||
| return ( | ||
| <dialog id="search-modal" className="modal"> | ||
| <div className="modal-box w-11/12 max-w-5xl h-[80vh] flex flex-col"> | ||
| <label className="input input-bordered flex items-center gap-2 bg-neutral sticky top-0 z-10"> | ||
| <input | ||
| type="text" | ||
| className="grow h-12" | ||
| placeholder={localize("navbar-section-search")} | ||
| onChange={onSearchInputChange} | ||
| /> | ||
| {isFetching ? ( | ||
| <span className="loading loading-dots loading-lg"></span> | ||
| ) : ( | ||
| <svg | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| viewBox="0 0 16 16" | ||
| fill="currentColor" | ||
| className="h-4 w-4 opacity-70" | ||
| > | ||
| <path | ||
| fillRule="evenodd" | ||
| d="M9.965 11.026a5 5 0 1 1 1.06-1.06l2.755 2.754a.75.75 0 1 1-1.06 1.06l-2.755-2.754ZM10.5 7a3.5 3.5 0 1 1-7 0 3.5 3.5 0 0 1 7 0Z" | ||
| clipRule="evenodd" | ||
| /> | ||
| </svg> | ||
| )} | ||
| </label> | ||
| <div className="overflow-y-auto flex-grow"> | ||
| {searchTextOutput && ( | ||
| <div className="flex justify-center items-center h-full"> | ||
| <p>{searchTextOutput}</p> | ||
| </div> | ||
| )} | ||
| {contributionsList?.length > 0 && ( | ||
| <div className="mt-4"> | ||
| <h3 className="text-lg font-bold"> | ||
| <Locale search-contributions /> | ||
| </h3> | ||
| <div className="flex flex-row flex-wrap gap-4 justify-center p-4 max-w-7xl"> | ||
| {contributionsList.map((contribution) => ( | ||
| <ContributionCard contribution={contribution} key={contribution.id} compact /> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| )} | ||
| {contributorsList?.length > 0 && ( | ||
| <div className="mt-4"> | ||
| <h3 className="text-lg font-bold"> | ||
| <Locale search-contributors /> | ||
| </h3> | ||
| <div className="flex flex-row flex-wrap gap-4 justify-between p-4 max-w-7xl"> | ||
| {contributorsList.map((contributor) => ( | ||
| <ContributorCard | ||
| contributor={contributor} | ||
| key={contributor.id} | ||
| compact | ||
| onClick={hideModal} | ||
| /> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| )} | ||
| {projectsList?.length > 0 && ( | ||
| <div className="mt-4"> | ||
| <h3 className="text-lg font-bold"> | ||
| <Locale search-projects /> | ||
| </h3> | ||
| <div className="flex flex-row flex-wrap gap-4 justify-between p-4 max-w-7xl"> | ||
| {projectsList.map((project) => ( | ||
| <ProjectCard project={project} key={project.id} compact onClick={hideModal} /> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| )} | ||
| </div> | ||
| </div> | ||
| <form method="dialog" className="modal-backdrop"> | ||
| <button>close</button> | ||
| </form> | ||
| </dialog> | ||
| ); | ||
| } | ||
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.
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.