GameAwards2024PredictionGamemain.tsx9 matches
1213useEffect(() => {
14fetchData();
15}, []);
1617const fetchData = async () => {
18try {
19const response = await fetch("/data");
20if (!response.ok) {
21throw new Error("Failed to fetch data");
22}
23const { categories, allPredictions } = await response.json();
27setIsLoading(false);
28} catch (err) {
29console.error("Error fetching data:", err);
30setError(err.message);
31setIsLoading(false);
183// Data endpoint
184if (request.method === "GET" && new URL(request.url).pathname === "/data") {
185const gistResponse = await fetch(
186"https://gist.githubusercontent.com/bmitchinson/5c3ed5df80977e402113fc33c149ae7e/raw/ea393f1407d31da96623387299fc6e3702f5fb0a/gameawards_24_backend.json",
187);
213const username = segments.pop();
214215// Fetch categories
216const gistResponse = await fetch(
217"https://gist.githubusercontent.com/bmitchinson/5c3ed5df80977e402113fc33c149ae7e/raw/ea393f1407d31da96623387299fc6e3702f5fb0a/gameawards_24_backend.json",
218);
219const categories = await gistResponse.json();
220221// Fetch this user's predictions
222const userResult = await sqlite.execute(
223`SELECT predictions FROM ${KEY}_predictions_${SCHEMA_VERSION} WHERE username = ?`,
cerebras_codermain.tsx4 matches
3637useEffect(() => {
38async function fetchStats() {
39const response = await fetch("/dashboard-stats");
40const data = await response.json();
41setStats(data);
42}
43fetchStats();
44}, []);
45146147try {
148const response = await fetch("/", {
149method: "POST",
150body: JSON.stringify({
dedicatedAmethystLeopardmain.tsx5 matches
1415useEffect(() => {
16fetchStocks();
17}, []);
1819async function fetchStocks() {
20const response = await fetch('/stocks');
21const data = await response.json();
22setStocks(data);
33async function addStock(e) {
34e.preventDefault();
35const response = await fetch('/stocks', {
36method: 'POST',
37headers: {
42
43if (response.ok) {
44fetchStocks();
45setNewStock({
46symbol: '',
5try {
6// Use a public screenshot service that doesn't require authentication
7const screenshotResponse = await fetch(`https://api.urlbox.io/v1/render/screenshot?url=${encodeURIComponent(url)}&width=1280&height=720`);
8
9if (!screenshotResponse.ok) {
cerebras_codermain.tsx4 matches
3637useEffect(() => {
38async function fetchStats() {
39const response = await fetch("/dashboard-stats");
40const data = await response.json();
41setStats(data);
42}
43fetchStats();
44}, []);
45146147try {
148const response = await fetch("/", {
149method: "POST",
150body: JSON.stringify({
1import { fetch } from "https://esm.town/v/std/fetch";
23function fetchJSON(url) {
4return fetch(url).then(res => res.json());
5}
67export let currency = async (desired, base = "usd", amount = 1) => {
8let { rates } = await fetchJSON(`https://open.er-api.com/v6/latest/${base}`);
9if (false && rates && rates[desired.toUpperCase()]) return amount * (rates[desired.toUpperCase()]);
10else {
11let { rates } = await fetchJSON("https://api.coingecko.com/api/v3/exchange_rates");
12return amount * rates[desired.toLowerCase()]?.value / rates[base.toLowerCase()]?.value;
13}
productiveRosePeacockmain.tsx4 matches
3637useEffect(() => {
38async function fetchStats() {
39const response = await fetch("/dashboard-stats");
40const data = await response.json();
41setStats(data);
42}
43fetchStats();
44}, []);
45146147try {
148const response = await fetch("/", {
149method: "POST",
150body: JSON.stringify({
prodigiousBrownImpalamain.tsx4 matches
3637useEffect(() => {
38async function fetchStats() {
39const response = await fetch("/dashboard-stats");
40const data = await response.json();
41setStats(data);
42}
43fetchStats();
44}, []);
45146147try {
148const response = await fetch("/", {
149method: "POST",
150body: JSON.stringify({
BestTime2postmain.tsx1 match
60
61try {
62const response = await fetch("/check-email", {
63method: "POST",
64headers: { "Content-Type": "application/json" },
captivatingPurpleTapirmain.tsx20 matches
1516useEffect(() => {
17fetchStocks();
18fetchOperations();
19}, []);
2021async function fetchStocks() {
22const response = await fetch('/stocks');
23const data = await response.json();
24setStocks(data);
25}
2627async function fetchOperations() {
28const response = await fetch('/operations');
29const data = await response.json();
30setOperations(data);
33async function addStock(e) {
34e.preventDefault();
35const response = await fetch('/stocks', {
36method: 'POST',
37headers: { 'Content-Type': 'application/json' },
38body: JSON.stringify(newStock)
39});
40await fetchStocks();
41await fetchOperations();
42setNewStock({ symbol: '', shares: 0, purchasePrice: 0, sellPrice: 0 });
43}
4445async function deleteStock(symbol: string, shares: number, purchasePrice: number) {
46const response = await fetch('/stocks', {
47method: 'DELETE',
48headers: { 'Content-Type': 'application/json' },
49body: JSON.stringify({ symbol, shares, purchasePrice })
50});
51await fetchStocks();
52await fetchOperations();
53}
5455async function updateStock(stock) {
56const response = await fetch('/stocks', {
57method: 'PUT',
58headers: { 'Content-Type': 'application/json' },
59body: JSON.stringify(stock)
60});
61await fetchStocks();
62await fetchOperations();
63setEditingStock(null);
64}
178stock.shares,
179stock.purchasePrice,
180await fetchStockPrice(stock.symbol),
181stock.sellPrice || null
182]
269}
270271// Existing fetchStockPrice function remains the same
272async function fetchStockPrice(symbol: string): Promise<number> {
273try {
274const response = await fetch(`https://query1.finance.yahoo.com/v8/finance/chart/${symbol}`);
275const data = await response.json();
276return data.chart.result[0].meta.regularMarketPrice;
277} catch {
278return 0; // Default to 0 if price can't be fetched
279}
280}