85}
8687const response = await fetch("/grade-card", {
88method: "POST",
89headers: { "Content-Type": "application/json" },
274275if (request.method === "OPTIONS") {
276// Handle CORS preflight requests if needed (though likely not necessary for same-origin val fetches)
277return new Response(null, { headers: { "Allow": "POST, OPTIONS" } });
278}
25leaderboard: [], // Stores top scores for the current topic, e.g., [90, 85, 80]
26stage: "topic-selection", // 'topic-selection', 'study', 'quiz', 'results'
27loadingMessage: null, // e.g., "Fetching study material..."
28error: null, // Stores error messages for display
29});
36// --- API Interaction Functions ---
3738const fetchStudyMaterial = useCallback(async (topic) => {
39setLoading(`Generating study material for "${topic}"...`);
40try {
41const response = await fetch("/generate-study-material", {
42method: "POST",
43headers: { "Content-Type": "application/json" },
59}));
60} catch (error) {
61console.error("Error fetching study material:", error);
62setError(`Failed to generate study material: ${error.message}`);
63// Optionally revert stage if needed
70setLoading(`Generating quiz for "${state.selectedTopic}"...`);
71try {
72const response = await fetch("/generate-quiz", {
73method: "POST",
74headers: { "Content-Type": "application/json" },
136137// Submit to backend for leaderboard update
138const response = await fetch("/submit-quiz-results", {
139method: "POST",
140headers: { "Content-Type": "application/json" },
179const handleTopicSelect = (topic) => {
180if (state.loadingMessage) return; // Prevent action while loading
181// No need to set selectedTopic here, fetchStudyMaterial does it on success
182fetchStudyMaterial(topic);
183};
184539});
540541// Fetch leaderboard (Top 10 distinct scores for this topic)
542const leaderboardResults = await sqlite.execute({
543sql: `SELECT DISTINCT score FROM ${RESULTS_TABLE} WHERE topic = ? ORDER BY score DESC LIMIT 10`,
homerepairmain.tsx1 match
231232try {
233const response = await fetch("/execute-command", {
234method: "POST",
235headers: { "Content-Type": "application/json" },
email_capture_system_2App.tsx11 matches
19const [activeTab, setActiveTab] = useState('projects');
2021// Fetch initial data
22useEffect(() => {
23const fetchData = async () => {
24try {
25setLoading(true);
26
27// Fetch projects
28const projectsRes = await fetch(`${API_BASE_URL}/projects`);
29const projectsData = await projectsRes.json();
30
35setProjects(projectsData.data || []);
36
37// Fetch subscribers
38const subscribersRes = await fetch(`${API_BASE_URL}/subscribers`);
39const subscribersData = await subscribersRes.json();
40
46
47} catch (err) {
48console.error('Error fetching data:', err);
49setError(err.message);
50} finally {
53};
54
55fetchData();
56}, []);
5761setLoading(true);
62
63const response = await fetch(`${API_BASE_URL}/projects`, {
64method: 'POST',
65headers: {
90const updateProject = async (id, updates) => {
91try {
92const response = await fetch(`${API_BASE_URL}/projects/${id}`, {
93method: 'PATCH',
94headers: {
128const getProjectSubscribers = async (projectId) => {
129try {
130const response = await fetch(`${API_BASE_URL}/projects/${projectId}/subscribers`);
131const data = await response.json();
132
285});
286287export default api.fetch;
54});
5556export default app.fetch;
57
32// Initialize with demo data
33useEffect(() => {
34// Simulate API fetch
35setLoading(true);
36setTimeout(() => {
250// View user profile
251const viewProfile = (userId) => {
252// In a real app, fetch the user profile
253// For demo, use current user's profile if it's their profile
254if (userId === currentUser.id) {
dailySlackRoundupmain.tsx2 matches
1import { fetch } from "https://esm.town/v/std/fetch";
2import { getDayName } from "https://esm.town/v/stevekrouse/getDayName?v=2";
3import process from "node:process";
45export const dailySlackRoundup = (async () => {
6const res = await fetch(process.env.BRAINBOT_WEBHOOK_URL, {
7method: "POST",
8body: JSON.stringify({
tangledRSSmain.tsx7 matches
9try {
10// Resolve handle to DID
11const handleResolveResponse = await fetch(
12`https://bsky.social/xrpc/com.atproto.identity.resolveHandle?handle=${handle}`,
13);
14const { did } = await handleResolveResponse.json();
1516// Fetch DID document
17const didDocResponse = await fetch(`https://plc.directory/${did}`);
18const didDoc = await didDocResponse.json();
19const serviceEndpoint = didDoc.service[0].serviceEndpoint;
2021// Fetch all records
22const allRecords = await fetchAllRecords(serviceEndpoint, did);
2324// Generate RSS feed
35}
3637async function fetchAllRecords(serviceEndpoint: string, did: string): Promise<any[]> {
38const allRecords: any[] = [];
39let cursor = "";
46if (cursor) url.searchParams.set("cursor", cursor);
4748const response = await fetch(url.toString());
49const data = await response.json();
50