-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathsearchModeSelector.tsx
More file actions
169 lines (155 loc) · 7.61 KB
/
searchModeSelector.tsx
File metadata and controls
169 lines (155 loc) · 7.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
'use client';
import { KeyboardShortcutHint } from "@/app/components/keyboardShortcutHint";
import { useDomain } from "@/hooks/useDomain";
import { Select, SelectContent, SelectItemNoItemText, SelectTrigger, SelectValue } from "@/components/ui/select";
import { Separator } from "@/components/ui/separator";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { cn } from "@/lib/utils";
import { MessageCircleIcon, SearchIcon } from "lucide-react";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { useCallback, useState } from "react";
import { useHotkeys } from "react-hotkeys-hook";
export type SearchMode = "precise" | "agentic";
const PRECISE_SEARCH_DOCS_URL = "https://docs.sourcebot.dev/docs/features/search/overview";
// @todo: point this to the actual docs page
const AGENTIC_SEARCH_DOCS_URL = "https://docs.sourcebot.dev/docs/features/ask/overview";
export interface SearchModeSelectorProps {
searchMode: SearchMode;
className?: string;
}
export const SearchModeSelector = ({
searchMode,
className,
}: SearchModeSelectorProps) => {
const domain = useDomain();
const [focusedSearchMode, setFocusedSearchMode] = useState<SearchMode>(searchMode);
const router = useRouter();
const onSearchModeChanged = useCallback((value: SearchMode) => {
router.push(`/${domain}/${value === "precise" ? "search" : "chat"}`);
}, [domain, router]);
useHotkeys("mod+i", (e) => {
e.preventDefault();
onSearchModeChanged("agentic");
}, {
enableOnFormTags: true,
enableOnContentEditable: true,
description: "Switch to agentic search",
});
useHotkeys("mod+p", (e) => {
e.preventDefault();
onSearchModeChanged("precise");
}, {
enableOnFormTags: true,
enableOnContentEditable: true,
description: "Switch to precise search",
});
return (
<div className={cn("flex flex-row items-center", className)}>
<Select
value={searchMode}
onValueChange={(value) => {
onSearchModeChanged(value as SearchMode);
}}
>
<SelectTrigger
className="flex flex-row items-center h-6 mt-0.5 font-mono font-semibold text-xs p-0 w-fit border-none bg-inherit rounded-md"
>
{searchMode === "precise" ? (
<SearchIcon className="w-4 h-4 text-muted-foreground mr-1.5" />
) : (
<MessageCircleIcon className="w-4 h-4 text-muted-foreground mr-1.5" />
)}
<SelectValue>
{searchMode === "precise" ? "Code Search" : "Ask"}
</SelectValue>
</SelectTrigger>
<SelectContent
className="overflow-visible relative"
>
<Tooltip
delayDuration={100}
open={focusedSearchMode === "precise"}
>
<TooltipTrigger asChild>
<div
onMouseEnter={() => setFocusedSearchMode("precise")}
onFocus={() => setFocusedSearchMode("precise")}
>
<SelectItemNoItemText
value="precise"
className="cursor-pointer"
>
<div className="flex flex-row items-center justify-between w-full gap-1.5">
<span>Search</span>
<div className="flex flex-row items-center gap-2">
<Separator orientation="vertical" className="h-4" />
<KeyboardShortcutHint shortcut="mod+p" />
</div>
</div>
</SelectItemNoItemText>
<TooltipContent
side="right"
className="w-64 z-50"
sideOffset={8}
>
<div className="flex flex-col gap-2">
<p className="font-semibold">Code Search</p>
<Separator orientation="horizontal" className="w-full my-0.5" />
<p>Search for exact matches using regular expressions and filters.</p>
<Link
href={PRECISE_SEARCH_DOCS_URL}
className="text-link hover:underline"
>
Docs
</Link>
</div>
</TooltipContent>
</div>
</TooltipTrigger>
</Tooltip>
<Tooltip delayDuration={100} open={focusedSearchMode === "agentic"}>
<TooltipTrigger asChild>
<div
onMouseEnter={() => setFocusedSearchMode("agentic")}
onFocus={() => setFocusedSearchMode("agentic")}
>
<SelectItemNoItemText
value="agentic"
className="cursor-pointer"
>
<div className="flex flex-row items-center justify-between w-full gap-1.5">
<span>Ask</span>
<div className="flex flex-row items-center gap-2">
<Separator orientation="vertical" className="h-4" />
<KeyboardShortcutHint shortcut="mod+i" />
</div>
</div>
</SelectItemNoItemText>
</div>
</TooltipTrigger>
<TooltipContent
side="right"
className="w-64 z-50"
sideOffset={8}
>
<div className="flex flex-col gap-2">
<div className="flex flex-row items-center gap-2">
<p className="font-semibold">Ask Sourcebot</p>
</div>
<Separator orientation="horizontal" className="w-full my-0.5" />
<p>Use natural language to search, summarize and understand your codebase using a reasoning agent.</p>
<Link
href={AGENTIC_SEARCH_DOCS_URL}
className="text-link hover:underline"
>
Docs
</Link>
</div>
</TooltipContent>
</Tooltip>
</SelectContent>
</Select>
</div>
)
}