31
32 try {
33 const serverResponse = await fetch("/query", {
34 method: "POST",
35 body: JSON.stringify({ query }),
30
31 useEffect(() => {
32 fetchUserData();
33 fetchAd();
34 }, []);
35
36 const fetchUserData = async () => {
37 const response = await fetch("/user");
38 const userData = await response.json();
39 setUser(userData);
42 };
43
44 const fetchAd = async () => {
45 const response = await fetch("/ad");
46 const adData = await response.json();
47 setAdContent(adData.content);
52 setIsLoading(true);
53 try {
54 const response = await fetch("/generate", {
55 method: "POST",
56 headers: { "Content-Type": "application/json" },
62 } else {
63 setGeneratedContent(data.content);
64 fetchUserData(); // Refresh user data to update usage
65 }
66 } catch (error) {
72
73 const handleUpgrade = async (tier) => {
74 const response = await fetch("/upgrade", {
75 method: "POST",
76 headers: { "Content-Type": "application/json" },
79 const data = await response.json();
80 if (data.success) {
81 fetchUserData();
82 } else {
83 alert("Upgrade failed. Please try again.");
98
99 const updateUserSettings = async (settings) => {
100 const response = await fetch("/updateSettings", {
101 method: "POST",
102 headers: { "Content-Type": "application/json" },
105 const data = await response.json();
106 if (data.success) {
107 fetchUserData();
108 } else {
109 alert("Failed to update settings. Please try again.");
183
184 try {
185 const response = await fetch("/", {
186 method: "POST",
187 body: JSON.stringify({
8
9 useEffect(() => {
10 async function fetchStatus() {
11 try {
12 const response = await fetch('https://api.spacetraders.io/v2/');
13 if (!response.ok) throw new Error('Failed to fetch status');
14 const data = await response.json();
15 setStatus(data);
18 }
19 }
20 fetchStatus();
21 }, []);
22
182
183 try {
184 const response = await fetch("/", {
185 method: "POST",
186 body: JSON.stringify({
182
183 try {
184 const response = await fetch("/", {
185 method: "POST",
186 body: JSON.stringify({
182
183 try {
184 const response = await fetch("/", {
185 method: "POST",
186 body: JSON.stringify({
14 start = performance.now();
15 try {
16 const res = await fetch(url);
17 end = performance.now();
18 status = res.status;
25 } catch (e) {
26 end = performance.now();
27 reason = `couldn't fetch: ${e}`;
28 ok = false;
29 console.log(`Website down (${url}): ${reason} (${end - start}ms)`);
182
183 try {
184 const response = await fetch("/", {
185 method: "POST",
186 body: JSON.stringify({
69
70 try {
71 const response = await fetch("/transcribe", {
72 method: "POST",
73 body: formData,