enzostvs HF Staff commited on
Commit
d738d0d
·
1 Parent(s): 7734a90

random prompt

Browse files
components/editor/ask-ai/fake-ask.tsx CHANGED
@@ -1,33 +1,14 @@
1
  import { useState } from "react";
2
  import { useLocalStorage } from "react-use";
3
- import { ArrowUp, Dice1, Dice6 } from "lucide-react";
4
  import { useRouter } from "next/navigation";
5
 
6
  import { Button } from "@/components/ui/button";
7
- import { useLoginModal } from "@/components/contexts/login-context";
8
  import { PromptBuilder } from "./prompt-builder";
9
  import { EnhancedSettings } from "@/types";
10
  import { Settings } from "./settings";
11
  import classNames from "classnames";
12
-
13
- const prompts = [
14
- "Create a landing page for a SaaS product, with a hero section, a features section, a pricing section, and a call to action section.",
15
- "Create a portfolio website for a designer, with a hero section, a projects section, a about section, and a contact section.",
16
- "Create a blog website for a writer, with a hero section, a blog section, a about section, and a contact section.",
17
- "Create a Tic Tac Toe game, with a game board, a history section, and a score section.",
18
- "Create a Weather App, with a search bar, a weather section, and a forecast section.",
19
- "Create a Calculator, with a calculator section, and a history section.",
20
- "Create a Todo List, with a todo list section, and a history section.",
21
- "Create a Calendar, with a calendar section, and a history section.",
22
- "Create a Music Player, with a music player section, and a history section.",
23
- "Create a Quiz App, with a quiz section, and a history section.",
24
- "Create a Pomodoro Timer, with a timer section, and a history section.",
25
- "Create a Notes App, with a notes section, and a history section.",
26
- "Create a Task Manager, with a task list section, and a history section.",
27
- "Create a Password Generator, with a password generator section, and a history section.",
28
- "Create a Currency Converter, with a currency converter section, and a history section.",
29
- "Create a Dictionary, with a dictionary section, and a history section.",
30
- ];
31
 
32
  export const FakeAskAi = () => {
33
  const router = useRouter();
@@ -51,7 +32,9 @@ export const FakeAskAi = () => {
51
  const randomPrompt = () => {
52
  setRandomPromptLoading(true);
53
  setTimeout(() => {
54
- setPrompt(prompts[Math.floor(Math.random() * prompts.length)]);
 
 
55
  setRandomPromptLoading(false);
56
  }, 400);
57
  };
 
1
  import { useState } from "react";
2
  import { useLocalStorage } from "react-use";
3
+ import { ArrowUp, Dice6 } from "lucide-react";
4
  import { useRouter } from "next/navigation";
5
 
6
  import { Button } from "@/components/ui/button";
 
7
  import { PromptBuilder } from "./prompt-builder";
8
  import { EnhancedSettings } from "@/types";
9
  import { Settings } from "./settings";
10
  import classNames from "classnames";
11
+ import { PROMPTS_FOR_AI } from "@/lib/prompts";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  export const FakeAskAi = () => {
14
  const router = useRouter();
 
32
  const randomPrompt = () => {
33
  setRandomPromptLoading(true);
34
  setTimeout(() => {
35
+ setPrompt(
36
+ PROMPTS_FOR_AI[Math.floor(Math.random() * PROMPTS_FOR_AI.length)]
37
+ );
38
  setRandomPromptLoading(false);
39
  }, 400);
40
  };
components/editor/ask-ai/index.tsx CHANGED
@@ -1,6 +1,6 @@
1
  import { useRef, useState } from "react";
2
  import classNames from "classnames";
3
- import { ArrowUp, ChevronDown, CircleStop } from "lucide-react";
4
  import { useLocalStorage, useUpdateEffect, useMount } from "react-use";
5
  import { toast } from "sonner";
6
 
@@ -20,6 +20,7 @@ import { useLoginModal } from "@/components/contexts/login-context";
20
  import { Settings } from "./settings";
21
  import { useProModal } from "@/components/contexts/pro-context";
22
  import { MAX_FREE_PROJECTS } from "@/lib/utils";
 
23
 
24
  export const AskAi = ({
25
  project,
@@ -69,12 +70,7 @@ export const AskAi = ({
69
  );
70
  const [think, setThink] = useState("");
71
  const [openThink, setOpenThink] = useState(false);
72
-
73
- const handleThink = (think: string) => {
74
- setThink(think);
75
- setIsThinking(true);
76
- setOpenThink(true);
77
- };
78
 
79
  useMount(() => {
80
  if (promptStorage && promptStorage.trim() !== "") {
@@ -152,6 +148,16 @@ export const AskAi = ({
152
  }
153
  }, [think]);
154
 
 
 
 
 
 
 
 
 
 
 
155
  return (
156
  <div className="p-3 w-full">
157
  <div className="relative bg-neutral-800 border border-neutral-700 rounded-2xl ring-[4px] focus-within:ring-neutral-500/30 focus-within:border-neutral-600 ring-transparent z-20 w-full group">
@@ -261,6 +267,20 @@ export const AskAi = ({
261
  }
262
  }}
263
  />
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
  </div>
265
  <div className="flex items-center justify-between gap-2 px-4 pb-3 mt-2">
266
  <div className="flex-1 flex items-center justify-start gap-1.5 flex-wrap">
@@ -276,7 +296,7 @@ export const AskAi = ({
276
  />
277
  {!isNew && <Uploader project={project} />}
278
  {isNew && <ReImagine onRedesign={(md) => callAi(md)} />}
279
- {!isNew && <Selector />}
280
  </div>
281
  <div className="flex items-center justify-end gap-2">
282
  <Button
 
1
  import { useRef, useState } from "react";
2
  import classNames from "classnames";
3
+ import { ArrowUp, ChevronDown, CircleStop, Dice6 } from "lucide-react";
4
  import { useLocalStorage, useUpdateEffect, useMount } from "react-use";
5
  import { toast } from "sonner";
6
 
 
20
  import { Settings } from "./settings";
21
  import { useProModal } from "@/components/contexts/pro-context";
22
  import { MAX_FREE_PROJECTS } from "@/lib/utils";
23
+ import { PROMPTS_FOR_AI } from "@/lib/prompts";
24
 
25
  export const AskAi = ({
26
  project,
 
70
  );
71
  const [think, setThink] = useState("");
72
  const [openThink, setOpenThink] = useState(false);
73
+ const [randomPromptLoading, setRandomPromptLoading] = useState(false);
 
 
 
 
 
74
 
75
  useMount(() => {
76
  if (promptStorage && promptStorage.trim() !== "") {
 
148
  }
149
  }, [think]);
150
 
151
+ const randomPrompt = () => {
152
+ setRandomPromptLoading(true);
153
+ setTimeout(() => {
154
+ setPrompt(
155
+ PROMPTS_FOR_AI[Math.floor(Math.random() * PROMPTS_FOR_AI.length)]
156
+ );
157
+ setRandomPromptLoading(false);
158
+ }, 400);
159
+ };
160
+
161
  return (
162
  <div className="p-3 w-full">
163
  <div className="relative bg-neutral-800 border border-neutral-700 rounded-2xl ring-[4px] focus-within:ring-neutral-500/30 focus-within:border-neutral-600 ring-transparent z-20 w-full group">
 
267
  }
268
  }}
269
  />
270
+ {isNew && !isAiWorking && isSameHtml && (
271
+ <Button
272
+ size="iconXs"
273
+ variant="outline"
274
+ className="!rounded-md -translate-y-2 -translate-x-4"
275
+ onClick={() => randomPrompt()}
276
+ >
277
+ <Dice6
278
+ className={classNames("size-4", {
279
+ "animate-spin animation-duration-500": randomPromptLoading,
280
+ })}
281
+ />
282
+ </Button>
283
+ )}
284
  </div>
285
  <div className="flex items-center justify-between gap-2 px-4 pb-3 mt-2">
286
  <div className="flex-1 flex items-center justify-start gap-1.5 flex-wrap">
 
296
  />
297
  {!isNew && <Uploader project={project} />}
298
  {isNew && <ReImagine onRedesign={(md) => callAi(md)} />}
299
+ {!isNew && !isSameHtml && <Selector />}
300
  </div>
301
  <div className="flex items-center justify-end gap-2">
302
  <Button
components/editor/index.tsx CHANGED
@@ -58,7 +58,7 @@ export const AppEditor = ({
58
  });
59
 
60
  useEffect(() => {
61
- if (hasUnsavedChanges && !isAiWorking) {
62
  setShowSavePopup(true);
63
  } else {
64
  setShowSavePopup(false);
 
58
  });
59
 
60
  useEffect(() => {
61
+ if (hasUnsavedChanges && !isAiWorking && project?.name) {
62
  setShowSavePopup(true);
63
  } else {
64
  setShowSavePopup(false);
components/my-projects/index.tsx CHANGED
@@ -91,9 +91,9 @@ export function MyProjects() {
91
  Create Project
92
  </div>
93
  )}
94
- {projects.map((project: ProjectType) => (
95
  <ProjectCard
96
- key={project.name}
97
  project={project}
98
  onDelete={() => onDelete(project)}
99
  />
 
91
  Create Project
92
  </div>
93
  )}
94
+ {projects.map((project: ProjectType, index: number) => (
95
  <ProjectCard
96
+ key={index}
97
  project={project}
98
  onDelete={() => onDelete(project)}
99
  />
lib/prompts.ts CHANGED
@@ -146,4 +146,23 @@ ${NEW_PAGE_START}index.html${NEW_PAGE_END}
146
  </html>
147
  \`\`\`
148
  IMPORTANT: While creating a new page, UPDATE ALL THE OTHERS (using the UPDATE_PAGE_START and SEARCH/REPLACE format) pages to add or replace the link to the new page, otherwise the user will not be able to navigate to the new page. (Dont use onclick to navigate, only href)
149
- No need to explain what you did. Just return the expected result.`
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  </html>
147
  \`\`\`
148
  IMPORTANT: While creating a new page, UPDATE ALL THE OTHERS (using the UPDATE_PAGE_START and SEARCH/REPLACE format) pages to add or replace the link to the new page, otherwise the user will not be able to navigate to the new page. (Dont use onclick to navigate, only href)
149
+ No need to explain what you did. Just return the expected result.`
150
+
151
+ export const PROMPTS_FOR_AI = [
152
+ "Create a landing page for a SaaS product, with a hero section, a features section, a pricing section, and a call to action section.",
153
+ "Create a portfolio website for a designer, with a hero section, a projects section, a about section, and a contact section.",
154
+ "Create a blog website for a writer, with a hero section, a blog section, a about section, and a contact section.",
155
+ "Create a Tic Tac Toe game, with a game board, a history section, and a score section.",
156
+ "Create a Weather App, with a search bar, a weather section, and a forecast section.",
157
+ "Create a Calculator, with a calculator section, and a history section.",
158
+ "Create a Todo List, with a todo list section, and a history section.",
159
+ "Create a Calendar, with a calendar section, and a history section.",
160
+ "Create a Music Player, with a music player section, and a history section.",
161
+ "Create a Quiz App, with a quiz section, and a history section.",
162
+ "Create a Pomodoro Timer, with a timer section, and a history section.",
163
+ "Create a Notes App, with a notes section, and a history section.",
164
+ "Create a Task Manager, with a task list section, and a history section.",
165
+ "Create a Password Generator, with a password generator section, and a history section.",
166
+ "Create a Currency Converter, with a currency converter section, and a history section.",
167
+ "Create a Dictionary, with a dictionary section, and a history section.",
168
+ ];