15 const start = performance.now();
16 try {
17 res = await fetch(url);
18 end = performance.now();
19 status = res.status;
25 } catch (e) {
26 end = performance.now();
27 reason = `couldn't fetch: ${e}`;
28 ok = false;
29 }
30
31 useEffect(() => {
32 fetchProblem();
33 }, []);
34
35 const fetchProblem = async () => {
36 setLoading(true);
37 try {
38 const response = await fetch("/problem");
39 if (!response.ok) throw new Error("Failed to fetch problem");
40 const data = await response.json();
41 setProblem(data);
45 setShowCorrectAnswer(false);
46 } catch (error) {
47 console.error("Error fetching problem:", error);
48 setFeedback("Failed to load problem. Please try again.");
49 } finally {
56 setLoading(true);
57 try {
58 const response = await fetch("/check", {
59 method: "POST",
60 headers: { "Content-Type": "application/json" },
139 )}
140 {showCorrectAnswer && (
141 <button onClick={fetchProblem} className="next-button">
142 Try a new problem
143 </button>
150
151async function getUserId() {
152 const resp = await fetch("https://api.val.town/v1/me", {
153 headers: {
154 Authorization: `Bearer ${Deno.env.get("valtown")}`,
201 const tasks = await getPendingTasks();
202 for (const task of tasks) {
203 fetch(`${this.#httpEndpoint}/${task.data.name}`, {
204 method: "POST",
205 body: JSON.stringify({ args: task.data.args }),
216 }
217
218 async fetch(req: Request): Promise<Response> {
219 await this.#ensureMigration();
220
14});
15
16export default queue.fetch.bind(queue);
1const res = await fetch("https://charmaine--f63947e4efa911efbe7fe6cdfca9ef9f.web.val.run/?args=[2,3]");
2console.log(await res.json()); // 5
5async function servePublicFile(path: string): Promise<Response> {
6 const url = new URL("./public/" + path, import.meta.url);
7 const text = await (await fetch(url, {
8 headers: {
9 "User-Agent": "", // to transpile TS to JS
181
182 try {
183 const response = await fetch("/", {
184 method: "POST",
185 body: JSON.stringify({
6 const path = url.pathname;
7
8 const response = await fetch(moduleBase);
9
10 const text = await response.text();
1const res = await fetch("https://charmaine--f63947e4efa911efbe7fe6cdfca9ef9f.web.val.run/", {
2 method: "POST",
3 body: JSON.stringify({ args: [2, 3] }),
5async function servePublicFile(path: string): Promise<Response> {
6 const url = new URL("./public/" + path, import.meta.url);
7 const text = await (await fetch(url, {
8 headers: {
9 "User-Agent": "", // to transpile TS to JS