-
Notifications
You must be signed in to change notification settings - Fork 418
global-search result rendering on left-side-bar #1560
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
12 commits
Select commit
Hold shift + click to select a range
951a5ed
init
yujonglee 3ae5e91
styling
yujonglee 31c146b
better search algo
yujonglee f0412f8
add highlight
yujonglee 803f59a
add highlights
yujonglee 48939f3
filter
yujonglee 3399854
nits
yujonglee 98827ba
hotkey
yujonglee cbc3c96
fix search
yujonglee 066b7d5
purify
yujonglee 4b07b3b
Update apps/desktop2/src/components/main/sidebar/search/item.tsx
yujonglee af7e945
fmt
yujonglee 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
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
22 changes: 22 additions & 0 deletions
22
apps/desktop2/src/components/main/sidebar/search/empty.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,22 @@ | ||
| import { SearchXIcon } from "lucide-react"; | ||
|
|
||
| import { cn } from "@hypr/ui/lib/utils"; | ||
|
|
||
| export function SearchNoResults() { | ||
| return ( | ||
| <div className={cn(["h-full flex items-center justify-center"])}> | ||
| <div className={cn(["text-center px-4 max-w-xs"])}> | ||
| <div className={cn(["flex justify-center mb-3"])}> | ||
| <SearchXIcon className={cn(["h-10 w-10 text-gray-300"])} /> | ||
| </div> | ||
| <p className={cn(["text-sm font-medium text-gray-700"])}> | ||
| No results found | ||
| </p> | ||
| <p className={cn(["text-xs text-gray-500 mt-2 leading-relaxed"])}> | ||
| Try using different keywords or check your spelling. Results are filtered to show only the most relevant | ||
| matches. | ||
| </p> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
89 changes: 89 additions & 0 deletions
89
apps/desktop2/src/components/main/sidebar/search/group.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,89 @@ | ||
| import { ChevronDownIcon } from "lucide-react"; | ||
| import { useState } from "react"; | ||
|
|
||
| import { cn } from "@hypr/ui/lib/utils"; | ||
| import { type SearchGroup } from "../../../../contexts/search"; | ||
| import { SearchResultItem } from "./item"; | ||
|
|
||
| const ITEMS_PER_PAGE = 3; | ||
| const LOAD_MORE_STEP = 5; | ||
|
|
||
| export function SearchResultGroup({ | ||
| group, | ||
| icon: Icon, | ||
| rank, | ||
| maxScore, | ||
| }: { | ||
| group: SearchGroup; | ||
| icon: React.ComponentType<{ className?: string }>; | ||
| rank: number; | ||
| maxScore: number; | ||
| }) { | ||
| const [visibleCount, setVisibleCount] = useState(ITEMS_PER_PAGE); | ||
|
|
||
| if (group.totalCount === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| const visibleResults = group.results.slice(0, visibleCount); | ||
| const hasMore = group.totalCount > visibleCount; | ||
| const isTopRanked = rank === 1; | ||
|
|
||
| return ( | ||
| <div className={cn(["mb-6"])}> | ||
| <div | ||
| className={cn([ | ||
| "sticky top-0 z-10", | ||
| "px-3 py-2 mb-2", | ||
| "flex items-center gap-2", | ||
| "bg-gray-50 rounded-lg", | ||
| "border-b border-gray-200", | ||
| ])} | ||
| > | ||
| <Icon className={cn(["h-4 w-4 text-gray-600"])} /> | ||
| <h3 | ||
| className={cn([ | ||
| "text-xs font-semibold text-gray-700", | ||
| "uppercase tracking-wider", | ||
| ])} | ||
| > | ||
| {group.title} | ||
| </h3> | ||
| <span className={cn(["text-xs text-gray-500 font-medium"])}> | ||
| ({group.totalCount}) | ||
| </span> | ||
| {isTopRanked && ( | ||
| <span | ||
| className={cn([ | ||
| "ml-auto", | ||
| "px-2 py-0.5", | ||
| "text-[10px] font-semibold", | ||
| "bg-blue-100 text-blue-700", | ||
| "rounded-full", | ||
| ])} | ||
| > | ||
| Best Match | ||
| </span> | ||
| )} | ||
| </div> | ||
| <div className={cn(["space-y-0.5 px-1"])}> | ||
| {visibleResults.map((result) => <SearchResultItem key={result.id} result={result} maxScore={maxScore} />)} | ||
| </div> | ||
| {hasMore && ( | ||
| <button | ||
| onClick={() => setVisibleCount((prev) => prev + LOAD_MORE_STEP)} | ||
| className={cn([ | ||
| "w-full mt-2 px-3 py-2", | ||
| "flex items-center justify-center gap-2", | ||
| "text-xs font-medium text-gray-600", | ||
| "hover:bg-gray-50 active:bg-gray-100", | ||
| "rounded-lg transition-colors", | ||
| ])} | ||
| > | ||
| <span>Load 5 more</span> | ||
| <ChevronDownIcon className={cn(["h-3 w-3"])} /> | ||
| </button> | ||
| )} | ||
| </div> | ||
| ); | ||
| } |
46 changes: 46 additions & 0 deletions
46
apps/desktop2/src/components/main/sidebar/search/index.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,46 @@ | ||
| import { Building2Icon, FileTextIcon, UserIcon } from "lucide-react"; | ||
|
|
||
| import { cn } from "@hypr/ui/lib/utils"; | ||
| import { useSearch } from "../../../../contexts/search"; | ||
| import { SearchNoResults } from "./empty"; | ||
| import { SearchResultGroup } from "./group"; | ||
|
|
||
| const ICON_MAP = { | ||
| session: FileTextIcon, | ||
| human: UserIcon, | ||
| organization: Building2Icon, | ||
| }; | ||
|
|
||
| export function SearchResults() { | ||
| const { results, query } = useSearch(); | ||
|
|
||
| if (!query || !results) { | ||
| return null; | ||
| } | ||
|
|
||
| if (results.totalResults === 0) { | ||
| return <SearchNoResults />; | ||
| } | ||
|
|
||
| return ( | ||
| <div className={cn(["h-full overflow-y-auto"])}> | ||
| <div className={cn(["px-3 py-3"])}> | ||
| <div className={cn(["px-2 py-2 mb-4"])}> | ||
| <p className={cn(["text-xs text-gray-500 font-medium"])}> | ||
| {results.totalResults} result{results.totalResults !== 1 ? "s" : ""} for "{query}" | ||
| </p> | ||
| </div> | ||
|
|
||
| {results.groups.map((group, index) => ( | ||
| <SearchResultGroup | ||
| key={group.key} | ||
| group={group} | ||
| icon={ICON_MAP[group.type]} | ||
| rank={index + 1} | ||
| maxScore={results.maxScore} | ||
| /> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
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.