Spaces:
Running
Running
avoid empty name project
Browse files- hooks/useAi.ts +9 -3
hooks/useAi.ts
CHANGED
@@ -10,6 +10,7 @@ import { api } from "@/lib/api";
|
|
10 |
import { useRouter } from "next/navigation";
|
11 |
import { useUser } from "./useUser";
|
12 |
import { LivePreviewRef } from "@/components/editor/live-preview";
|
|
|
13 |
|
14 |
export const useAi = (onScrollToBottom?: () => void, livePreviewRef?: React.RefObject<LivePreviewRef | null>) => {
|
15 |
const client = useQueryClient();
|
@@ -198,10 +199,15 @@ export const useAi = (onScrollToBottom?: () => void, livePreviewRef?: React.RefO
|
|
198 |
}
|
199 |
|
200 |
const newPages = formatPages(contentResponse);
|
201 |
-
|
|
|
|
|
|
|
202 |
setPages(newPages);
|
203 |
-
setLastSavedPages([...newPages]);
|
204 |
-
|
|
|
|
|
205 |
setPrompts([...prompts, prompt]);
|
206 |
|
207 |
return { success: true, pages: newPages };
|
|
|
10 |
import { useRouter } from "next/navigation";
|
11 |
import { useUser } from "./useUser";
|
12 |
import { LivePreviewRef } from "@/components/editor/live-preview";
|
13 |
+
import { isTheSameHtml } from "@/lib/compare-html-diff";
|
14 |
|
15 |
export const useAi = (onScrollToBottom?: () => void, livePreviewRef?: React.RefObject<LivePreviewRef | null>) => {
|
16 |
const client = useQueryClient();
|
|
|
199 |
}
|
200 |
|
201 |
const newPages = formatPages(contentResponse);
|
202 |
+
let projectName = contentResponse.match(/<<<<<<< PROJECT_NAME_START ([\s\S]*?) >>>>>>> PROJECT_NAME_END/)?.[1]?.trim();
|
203 |
+
if (!projectName) {
|
204 |
+
projectName = prompt.substring(0, 40).replace(/[^a-zA-Z0-9]/g, "-").slice(0, 40);
|
205 |
+
}
|
206 |
setPages(newPages);
|
207 |
+
setLastSavedPages([...newPages]);
|
208 |
+
if (newPages.length > 0 && !isTheSameHtml(newPages[0].html)) {
|
209 |
+
createNewProject(prompt, newPages, projectName, isLoggedIn);
|
210 |
+
}
|
211 |
setPrompts([...prompts, prompt]);
|
212 |
|
213 |
return { success: true, pages: newPages };
|