44 const generateNextMessage = async () => {
45 const currentSpeaker = conversation.length % 2 === 0 ? 1 : 2;
46 const res = await fetch("?nextMessage=true", {
47 method: "POST",
48 body: JSON.stringify({
28
29 useEffect(() => {
30 fetchSavedSnippets();
31 }, []);
32
33 async function fetchSavedSnippets() {
34 const response = await fetch("/snippets");
35 const snippets = await response.json();
36 setSavedSnippets(snippets);
39 async function handleSave() {
40 if (!code) return;
41 const response = await fetch("/snippets", {
42 method: "POST",
43 headers: { "Content-Type": "application/json" },
45 });
46 if (response.ok) {
47 fetchSavedSnippets();
48 }
49 }
50
51 async function handleDelete(id: number) {
52 const response = await fetch(`/snippets/${id}`, { method: "DELETE" });
53 if (response.ok) {
54 setSavedSnippets(snippets => snippets.filter(s => s.id !== id));
61
62 try {
63 const response = await fetch("/", {
64 method: "POST",
65 body: JSON.stringify({ prompt, currentCode: code }),
25
26 try {
27 const response = await fetch("/", {
28 method: "POST",
29 body: JSON.stringify({ prompt, currentCode: code }),
25
26 try {
27 const response = await fetch("/", {
28 method: "POST",
29 body: JSON.stringify({ prompt, currentCode: code }),
23
24 try {
25 const response = await fetch("/", {
26 method: "POST",
27 body: JSON.stringify({ prompt, currentCode: code }),
25
26 try {
27 const response = await fetch("/", {
28 method: "POST",
29 body: JSON.stringify({ prompt, currentCode: code }),
25
26 try {
27 const response = await fetch("/", {
28 method: "POST",
29 body: JSON.stringify({ prompt, currentCode: code }),
36 const generateNextMessage = async () => {
37 const currentSpeaker = conversation.length % 2 === 0 ? 1 : 2;
38 const res = await fetch("?nextMessage=true", {
39 method: "POST",
40 body: JSON.stringify({
25
26 try {
27 const response = await fetch("/", {
28 method: "POST",
29 body: JSON.stringify({ prompt, currentCode: code }),
25
26 try {
27 const response = await fetch("/", {
28 method: "POST",
29 body: JSON.stringify({ prompt, currentCode: code }),