-
Notifications
You must be signed in to change notification settings - Fork 413
/
CreationPanel.tsx
219 lines (217 loc) · 8.18 KB
/
CreationPanel.tsx
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import { CheckIcon } from "@radix-ui/react-icons";
import { Popover, PopoverTrigger, PopoverContent } from "../../ui/popover";
import {
Command,
CommandInput,
CommandEmpty,
CommandGroup,
CommandItem,
} from "../../ui/command";
import React, { useState } from "react";
import { getFile } from "../../../lib/api.service";
import { Snippet } from "../../../lib/search";
import { cn } from "../../../lib/utils";
import { Button } from "../../ui/button";
import { FileChangeRequest } from "../../../lib/types";
import { FaPlus } from "react-icons/fa6";
import { FileChangeRequestsState } from "../../../state/fcrAtoms";
import { useRecoilState } from "recoil";
const CreationPanel = ({
filePath,
repoName,
files,
directories,
setCurrentTab,
}: {
filePath: string;
repoName: string;
files: { label: string; name: string }[];
directories: { label: string; name: string }[];
setCurrentTab: React.Dispatch<React.SetStateAction<"planning" | "coding">>;
}) => {
const [hidePanel, setHidePanel] = useState(true);
const [openModify, setOpenModify] = useState(false);
const [openCreate, setOpenCreate] = useState(false);
const [fileChangeRequests, setFileChangeRequests] = useRecoilState(
FileChangeRequestsState,
);
return (
<div
id="creation-panel-wrapper"
onMouseEnter={() => setHidePanel(false)}
onMouseLeave={() => setHidePanel(true)}
>
<div id="creation-panel-plus-sign-wraper" hidden={!hidePanel}>
<div className="flex flex-row w-full h-[80px] overflow-auto items-center mb-4">
<Button
variant="outline"
className="w-full h-full justify-center overflow-hidden bg-zinc-800 hover:bg-zinc-900 items-center"
>
<FaPlus className="mr-2" />
</Button>
</div>
</div>
<div id="creation-panel-actions-panel-wrapper" hidden={hidePanel}>
<div
id="creation-panel-actions-panel"
className="flex flex-row w-full h-[80px] mb-4 border rounded items-center"
>
<Popover open={openModify} onOpenChange={setOpenModify}>
<div className="w-full h-full overflow-auto">
<PopoverTrigger asChild>
<Button
variant="outline"
role="combobox"
aria-expanded={openModify}
className="border rounded-none w-full h-full bg-zinc-800 hover:bg-zinc-900 text-lg"
>
Modify file
</Button>
</PopoverTrigger>
</div>
<PopoverContent className="w-full p-0 text-left">
<Command>
<CommandInput
placeholder="Search for a file to modify..."
className="h-9"
/>
<CommandEmpty>No file found.</CommandEmpty>
<CommandGroup>
{files.map((file: any) => (
<CommandItem
key={file.value}
value={file.value}
onSelect={async (currentValue) => {
// ensure file is not already included
if (
fileChangeRequests.some(
(fcr: FileChangeRequest) =>
fcr.snippet.file === file.value,
)
) {
return;
}
const contents =
(await getFile(repoName, file.value)).contents || "";
setFileChangeRequests((prev: FileChangeRequest[]) => {
let snippet = {
file: file.value,
start: 0,
end: contents.split("\n").length,
entireFile: contents,
content: contents, // this is the slice based on start and end, remeber to change this
} as Snippet;
return [
...prev,
{
snippet,
changeType: "modify",
newContents: contents,
hideMerge: true,
instructions: "",
isLoading: false,
readOnlySnippets: {},
diff: "",
status: "idle",
} as FileChangeRequest,
];
});
setOpenModify(false);
}}
>
{file.label}
<CheckIcon
className={cn(
"ml-auto h-4 w-4",
filePath === file.value ? "opacity-100" : "opacity-0",
)}
/>
</CommandItem>
))}
</CommandGroup>
</Command>
</PopoverContent>
</Popover>
<Popover open={openCreate} onOpenChange={setOpenCreate}>
<div className="w-full h-full overflow-auto">
<PopoverTrigger asChild>
<Button
variant="outline"
role="combobox"
aria-expanded={openCreate}
className="border-2 border-black-900 rounded-none w-full h-full bg-zinc-800 hover:bg-zinc-900 text-lg"
>
Create file
</Button>
</PopoverTrigger>
</div>
<PopoverContent className="w-full p-0 text-left">
<Command>
<CommandInput
placeholder="Search for a directory..."
className="h-9"
/>
<CommandEmpty>No directory found.</CommandEmpty>
<CommandGroup>
{directories.map((dir: any) => (
<CommandItem
key={dir.value}
value={dir.value}
onSelect={async (currentValue) => {
setFileChangeRequests((prev: FileChangeRequest[]) => {
let snippet = {
file: dir.value,
start: 0,
end: 0,
entireFile: "",
content: "",
} as Snippet;
return [
...prev,
{
snippet,
changeType: "create",
newContents: "",
hideMerge: true,
instructions: "",
isLoading: false,
readOnlySnippets: {},
diff: "",
status: "idle",
} as FileChangeRequest,
];
});
setOpenCreate(false);
}}
>
{dir.label}
<CheckIcon
className={cn(
"ml-auto h-4 w-4",
filePath === dir.value ? "opacity-100" : "opacity-0",
)}
/>
</CommandItem>
))}
</CommandGroup>
</Command>
</PopoverContent>
</Popover>
<div className="w-full h-full overflow-auto">
<Button
variant="outline"
role="combobox"
className="border rounded-none w-full h-full bg-zinc-800 hover:bg-zinc-900 text-lg"
onClick={() => {
setCurrentTab("planning");
}}
>
Create plan
</Button>
</div>
</div>
</div>
</div>
);
};
export default CreationPanel;