Skip to content

Commit 5a97eaf

Browse files
committed
add create repo
1 parent 43c94c7 commit 5a97eaf

3 files changed

Lines changed: 85 additions & 77 deletions

File tree

app/api/repo/route.ts

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NextResponse } from "next/server";
1+
import { NextRequest, NextResponse } from "next/server";
22
import { getEnvVariables } from "../utils";
33

44
export async function GET() {
@@ -22,39 +22,41 @@ export async function GET() {
2222
return NextResponse.json({ result: repositories }, { status: 200 })
2323
} catch (err) {
2424
console.error(err)
25-
return NextResponse.json((err as Error).message, { status: 400 })
25+
return NextResponse.json((err as Error).message, { status: 400 })
2626
}
2727
}
2828

29-
// export async function POST(request: NextRequest) {
30-
31-
// const repo_url = request.nextUrl.searchParams.get('url');
32-
33-
// try {
34-
35-
// if (!repo_url) {
36-
// throw new Error("URL parameter is missing");
37-
// }
38-
39-
// const { url, token } = getEnvVariables();
40-
41-
// const result = await fetch(`${url}/process_repo`, {
42-
// method: 'POST',
43-
// body: JSON.stringify({ repo_url, ignore: ["./.github", "./sbin", "./.git", "./deps", "./bin", "./build"] }),
44-
// headers: {
45-
// "Authorization": token,
46-
// 'Content-Type': 'application/json'
47-
// },
48-
// cache: 'no-store'
49-
// });
50-
51-
// if (!result.ok) {
52-
// throw new Error(await result.text());
53-
// }
54-
55-
// return NextResponse.json({ message: "success" }, { status: 200 });
56-
// } catch (err) {
57-
// console.error(err)
58-
// return NextResponse.json((err as Error).message, { status: 400 });
59-
// }
60-
// }
29+
export async function POST(request: NextRequest) {
30+
31+
const repo_url = request.nextUrl.searchParams.get('url');
32+
33+
try {
34+
35+
if (!repo_url) {
36+
throw new Error("URL parameter is missing");
37+
}
38+
39+
const { url, token } = getEnvVariables();
40+
41+
const isLocal = repo_url.startsWith("file://")
42+
43+
const result = await fetch(`${url}/${isLocal ? "analyze_folder" : "process_repo"}`, {
44+
method: 'POST',
45+
body: JSON.stringify({ repo_url, ignore: ["./.github", "./sbin", "./.git", "./deps", "./bin", "./build"] }),
46+
headers: {
47+
"Authorization": token,
48+
'Content-Type': 'application/json'
49+
},
50+
cache: 'no-store'
51+
});
52+
53+
if (!result.ok) {
54+
throw new Error(await result.text());
55+
}
56+
57+
return NextResponse.json({ message: "success" }, { status: 200 });
58+
} catch (err) {
59+
console.error(err)
60+
return NextResponse.json((err as Error).message, { status: 400 });
61+
}
62+
}

app/components/dataPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const excludedProperties = [
1616
"expand",
1717
"collapsed",
1818
"isPath",
19-
"isPathStartEnd",
19+
"isPathSelected",
2020
"visible",
2121
"index",
2222
"__indexColor",

app/page.tsx

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { GraphContext } from './components/provider';
1212
import Image from 'next/image';
1313
import { DropdownMenu, DropdownMenuContent, DropdownMenuLabel, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
1414
import { prepareArg } from './utils';
15+
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog';
16+
import { Progress } from '@/components/ui/progress';
1517

1618
export type PathNode = {
1719
id?: number
@@ -92,6 +94,7 @@ export default function Home() {
9294
title: "Uh oh! Something went wrong.",
9395
description: await result.text(),
9496
})
97+
setIsSubmit(false)
9598
return
9699
}
97100

@@ -209,50 +212,53 @@ export default function Home() {
209212
}
210213
</DropdownMenuContent>
211214
</DropdownMenu>
212-
{/* <Dialog open={createOpen} onOpenChange={setCreateOpen}>
213-
<DialogTrigger asChild>
214-
<button
215-
className="h-full bg-black p-4 text-white rounded-lg"
216-
title="Create new project"
217-
>
218-
<p>Create new project</p>
219-
</button>
220-
</DialogTrigger>
221-
<DialogContent className='max-w-[26%] gap-8'>
222-
<DialogHeader>
223-
<DialogTitle>{!isSubmit ? "CREATE A NEW PROJECT" : "THANK YOU FOR A NEW REQUEST"}</DialogTitle>
224-
</DialogHeader>
225-
<DialogDescription className='text-warp'>
215+
{
216+
process.env.NEXT_PUBLIC_LOCAL_MODE &&
217+
<Dialog open={createOpen} onOpenChange={setCreateOpen}>
218+
<DialogTrigger asChild>
219+
<button
220+
className="h-full bg-black p-4 text-white rounded-lg"
221+
title="Create new project"
222+
>
223+
<p>Create new project</p>
224+
</button>
225+
</DialogTrigger>
226+
<DialogContent className='sm:max-w-[500px]'>
227+
<DialogHeader>
228+
<DialogTitle>{!isSubmit ? "CREATE A NEW PROJECT" : "THANK YOU FOR A NEW REQUEST"}</DialogTitle>
229+
</DialogHeader>
230+
<DialogDescription className='text-black'>
231+
{
232+
!isSubmit
233+
? "Please provide the URL of the project to connect and start querying data"
234+
: "Processing your graph, this could take a while. We appreciate your patience"
235+
}
236+
</DialogDescription>
226237
{
227-
!isSubmit
228-
? "Please provide the URL of the model to connect and start querying data"
229-
: "Processing your graph, this could take a while. We appreciate your patience"
238+
!isSubmit ?
239+
<form className='flex flex-col gap-4'>
240+
<input
241+
className='border p-3 rounded-lg'
242+
type="text"
243+
value={createURL}
244+
onChange={(e) => setCreateURL(e.target.value)}
245+
placeholder="Type Project URL (File:// or https://)"
246+
/>
247+
<div className='flex flex-row-reverse'>
248+
<button
249+
className='bg-black p-3 text-white rounded-lg'
250+
type='submit'
251+
title='Create Project'
252+
>
253+
<p>Create</p>
254+
</button>
255+
</div>
256+
</form>
257+
: <Progress value={0} />
230258
}
231-
</DialogDescription>
232-
{
233-
!isSubmit ?
234-
<form className='flex flex-col gap-4' onSubmit={onCreateRepo}>
235-
<input
236-
className='border p-3 rounded-lg'
237-
type="text"
238-
value={createURL}
239-
onChange={(e) => setCreateURL(e.target.value)}
240-
placeholder="Type URL"
241-
/>
242-
<div className='flex flex-row-reverse'>
243-
<button
244-
className='bg-black p-3 text-white rounded-lg'
245-
type='submit'
246-
title='Create Project'
247-
>
248-
<p>Create</p>
249-
</button>
250-
</div>
251-
</form>
252-
: <Progress value={0} />
253-
}
254-
</DialogContent>
255-
</Dialog> */}
259+
</DialogContent>
260+
</Dialog>
261+
}
256262
</ul>
257263
</div>
258264
<div className='h-2.5 bg-gradient-to-r from-[#EC806C] via-[#B66EBD] to-[#7568F2]' />

0 commit comments

Comments
 (0)