Elffuss BraidHub

kikocis/continue public

main · 1.5 KiBRawPermalink
1import { useState } from "react";
2import { useDispatch } from "react-redux";
3import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice";
4import { GenerationScreen } from "./GenerationScreen";
5import { InputScreen } from "./InputScreen";
6
7type Screen = "input" | "generation";
8
9export function GenerateRuleDialog() {
10 const dispatch = useDispatch();
11 const [screen, setScreen] = useState<Screen>("input");
12 const [inputPrompt, setInputPrompt] = useState("");
13 const [isManualMode, setIsManualMode] = useState(false);
14
15 const closeDialog = () => {
16 setScreen("input");
17 setInputPrompt("");
18 setIsManualMode(false);
19 dispatch(setDialogMessage(undefined));
20 dispatch(setShowDialog(false));
21 };
22
23 const handleGenerate = (prompt: string) => {
24 setInputPrompt(prompt);
25 setIsManualMode(false);
26 setScreen("generation");
27 };
28
29 const handleManualWrite = () => {
30 setIsManualMode(true);
31 setScreen("generation");
32 };
33
34 const handleBack = () => {
35 setScreen("input");
36 };
37
38 const handleSuccess = () => {
39 closeDialog();
40 };
41
42 if (screen === "input") {
43 return (
44 <InputScreen
45 inputPrompt={inputPrompt}
46 onInputChange={setInputPrompt}
47 onGenerate={handleGenerate}
48 onCancel={closeDialog}
49 onManualWrite={handleManualWrite}
50 />
51 );
52 }
53
54 return (
55 <GenerationScreen
56 inputPrompt={inputPrompt}
57 onBack={handleBack}
58 onSuccess={handleSuccess}
59 isManualMode={isManualMode}
60 />
61 );
62}