Elffuss BraidHub

kikocis/continue public

main · 8.9 KiBRawPermalink
1import {
2 DocumentArrowUpIcon,
3 LinkIcon,
4 NumberedListIcon,
5 PaintBrushIcon,
6 TableCellsIcon,
7} from "@heroicons/react/24/outline";
8import { useContext, useMemo } from "react";
9import { useNavigate } from "react-router-dom";
10import Shortcut from "../../../components/gui/Shortcut";
11import { Card } from "../../../components/ui";
12import { IdeMessengerContext } from "../../../context/IdeMessenger";
13import { useAppDispatch, useAppSelector } from "../../../redux/hooks";
14import { setOnboardingCard } from "../../../redux/slices/uiSlice";
15import { saveCurrentSession } from "../../../redux/thunks/session";
16import { isJetBrains } from "../../../util";
17import { ROUTES } from "../../../util/navigation";
18import { ConfigHeader } from "../components/ConfigHeader";
19import { ConfigRow } from "../components/ConfigRow";
20
21interface KeyboardShortcutProps {
22 shortcut: string;
23 description: string;
24 isEven: boolean;
25}
26
27function KeyboardShortcut(props: KeyboardShortcutProps) {
28 return (
29 <div
30 className={`flex flex-col items-start p-3 sm:flex-row sm:items-center ${props.isEven ? "" : "bg-vsc-editor-background/50"}`}
31 >
32 <div className="w-full flex-grow pb-2 pr-4 sm:w-auto sm:pb-0">
33 <span className="block break-words text-sm">{props.description}:</span>
34 </div>
35 <div className="flex-shrink-0 whitespace-nowrap">
36 <Shortcut>{props.shortcut}</Shortcut>
37 </div>
38 </div>
39 );
40}
41
42// Shortcut strings will be rendered correctly based on the platform by the Shortcut component
43const vscodeShortcuts: Omit<KeyboardShortcutProps, "isEven">[] = [
44 {
45 shortcut: "cmd '",
46 description: "Toggle Selected Model",
47 },
48 {
49 shortcut: "cmd I",
50 description: "Edit highlighted code",
51 },
52 {
53 shortcut: "cmd L",
54 description:
55 "New Chat / New Chat With Selected Code / Close Continue Sidebar If Chat Already In Focus",
56 },
57 {
58 shortcut: "cmd backspace",
59 description: "Cancel response",
60 },
61 {
62 shortcut: "cmd shift I",
63 description: "Toggle inline edit focus",
64 },
65 {
66 shortcut: "cmd shift L",
67 description:
68 "Focus Current Chat / Add Selected Code To Current Chat / Close Continue Sidebar If Chat Already In Focus",
69 },
70 {
71 shortcut: "cmd shift R",
72 description: "Debug Terminal",
73 },
74 {
75 shortcut: "cmd shift backspace",
76 description: "Reject Diff",
77 },
78 {
79 shortcut: "cmd shift enter",
80 description: "Accept Diff",
81 },
82 {
83 shortcut: "alt cmd N",
84 description: "Reject Top Change in Diff",
85 },
86 {
87 shortcut: "alt cmd Y",
88 description: "Accept Top Change in Diff",
89 },
90 {
91 shortcut: "cmd K cmd A",
92 description: "Toggle Autocomplete Enabled",
93 },
94 {
95 shortcut: "cmd alt space",
96 description: "Force an Autocomplete Trigger",
97 },
98 {
99 shortcut: "cmd K cmd M",
100 description: "Toggle Full Screen",
101 },
102];
103
104const jetbrainsShortcuts: Omit<KeyboardShortcutProps, "isEven">[] = [
105 {
106 shortcut: "cmd '",
107 description: "Toggle Selected Model",
108 },
109 {
110 shortcut: "cmd I",
111 description: "Edit highlighted code",
112 },
113 {
114 shortcut: "cmd J",
115 description:
116 "New Chat / New Chat With Selected Code / Close Continue Sidebar If Chat Already In Focus",
117 },
118 {
119 shortcut: "cmd backspace",
120 description: "Cancel response",
121 },
122 {
123 shortcut: "cmd shift I",
124 description: "Toggle inline edit focus",
125 },
126 {
127 shortcut: "cmd shift J",
128 description:
129 "Focus Current Chat / Add Selected Code To Current Chat / Close Continue Sidebar If Chat Already In Focus",
130 },
131 {
132 shortcut: "cmd shift backspace",
133 description: "Reject Diff",
134 },
135 {
136 shortcut: "cmd shift enter",
137 description: "Accept Diff",
138 },
139 {
140 shortcut: "alt shift J",
141 description: "Quick Input",
142 },
143 {
144 shortcut: "alt cmd J",
145 description: "Toggle Sidebar",
146 },
147];
148
149export function HelpSection() {
150 const ideMessenger = useContext(IdeMessengerContext);
151 const navigate = useNavigate();
152 const dispatch = useAppDispatch();
153
154 const currentSession = useAppSelector((state) => state.session);
155
156 const shortcuts = useMemo(() => {
157 return isJetBrains() ? jetbrainsShortcuts : vscodeShortcuts;
158 }, []);
159
160 const handleViewSessionData = async () => {
161 const sessionData = await ideMessenger.request("history/load", {
162 id: currentSession.id,
163 });
164
165 if (sessionData.status === "success") {
166 await ideMessenger.request("showVirtualFile", {
167 name: `${sessionData.content.title}.json`,
168 content: JSON.stringify(sessionData.content, null, 2),
169 });
170 }
171 };
172
173 return (
174 <div className="flex flex-col">
175 <ConfigHeader title="Help Center" />
176 <div className="space-y-6">
177 {/* Resources */}
178 <div>
179 <h3 className="mb-3 text-base font-medium">Resources</h3>
180 <Card className="!p-0">
181 <div className="flex flex-col">
182 <ConfigRow
183 title="Continue Hub"
184 description="Visit hub.continue.dev to explore custom agents and blocks"
185 icon={LinkIcon}
186 onClick={() =>
187 ideMessenger.post("openUrl", "https://hub.continue.dev/")
188 }
189 />
190
191 <ConfigRow
192 title="Documentation"
193 description="Learn how to configure and use Continue"
194 icon={LinkIcon}
195 onClick={() =>
196 ideMessenger.post("openUrl", "https://docs.continue.dev/")
197 }
198 />
199
200 <ConfigRow
201 title="Have an issue?"
202 description="Let us know on GitHub and we'll do our best to resolve it"
203 icon={LinkIcon}
204 onClick={() =>
205 ideMessenger.post(
206 "openUrl",
207 "https://github.com/continuedev/continue/issues/new/choose",
208 )
209 }
210 />
211
212 <ConfigRow
213 title="Join the community!"
214 description="Join us on Discord to stay up-to-date on the latest developments"
215 icon={LinkIcon}
216 onClick={() =>
217 ideMessenger.post("openUrl", "https://discord.gg/vapESyrFmJ")
218 }
219 />
220 </div>
221 </Card>
222 </div>
223
224 {/* Tools */}
225 <div>
226 <h3 className="mb-3 text-base font-medium">Tools</h3>
227 <Card className="!p-0">
228 <div className="flex flex-col">
229 <ConfigRow
230 title="Token usage"
231 description="Daily token usage across models"
232 icon={TableCellsIcon}
233 onClick={() => navigate(ROUTES.STATS)}
234 />
235
236 {currentSession.history.length > 0 &&
237 !currentSession.isStreaming && (
238 <ConfigRow
239 title="View current session history"
240 description="Open the current chat session file for troubleshooting"
241 icon={NumberedListIcon}
242 onClick={handleViewSessionData}
243 />
244 )}
245
246 <ConfigRow
247 title="Quickstart"
248 description="Reopen the quickstart and tutorial file"
249 icon={DocumentArrowUpIcon}
250 onClick={async () => {
251 navigate("/");
252 // Used to clear the chat panel before showing onboarding card
253 await dispatch(
254 saveCurrentSession({
255 openNewSession: true,
256 generateTitle: true,
257 }),
258 );
259 dispatch(
260 setOnboardingCard({
261 show: true,
262 activeTab: undefined,
263 }),
264 );
265 ideMessenger.post("showTutorial", undefined);
266 }}
267 />
268
269 {process.env.NODE_ENV === "development" && (
270 <ConfigRow
271 title="Theme Test Page"
272 description="Development page for testing themes"
273 icon={PaintBrushIcon}
274 onClick={async () => {
275 navigate(ROUTES.THEME);
276 }}
277 />
278 )}
279 </div>
280 </Card>
281 </div>
282
283 {/* Keyboard Shortcuts */}
284 <div>
285 <h3 className="mb-3 text-base font-medium">Keyboard Shortcuts</h3>
286 <Card className="!p-0">
287 <div className="overflow-hidden rounded-md border border-gray-600">
288 {shortcuts.map((shortcut, i) => {
289 return (
290 <KeyboardShortcut
291 key={i}
292 shortcut={shortcut.shortcut}
293 description={shortcut.description}
294 isEven={i % 2 === 0}
295 />
296 );
297 })}
298 </div>
299 </Card>
300 </div>
301 </div>
302 </div>
303 );
304}