Public
hn_notifier
Viewing readonly version: 1384View latest version
Script
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/** @jsxImportSource https://esm.sh/react@18.2.0 */
import React, { createContext, type ReactNode, useContext, useEffect, useState } from "https://esm.sh/react@18.2.0";
import { $api } from "https://esm.town/v/nbbaier/hn_notifier/backend/fetchClient.ts";
import type { DBItem } from "https://esm.town/v/nbbaier/hn_notifier/shared/types.ts";
interface ItemsContextType {
items: DBItem[];
isLoading: boolean;
saveUrl: (id: number) => Promise<void>;
}
const fetchUrls = async () => {
const { data, error } = await $api<DBItem[]>("/list");
return data ?? [];
};
const saveUrl = async (id: number) => {
const res = await $api<DBItem[]>("/follow", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ id }),
});
};
const ItemsContext = createContext<ItemsContextType>({
items: [],
isLoading: false,
saveUrl: async () => {
throw new Error("addItem function not implemented");
},
});
interface ItemsProviderProps {