Experiment to rebuild Diffuse using web applets.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 33 lines 1.0 kB view raw
1import { signal } from "spellcaster"; 2import * as IDB from "idb-keyval"; 3 4import { fetchHandles, fetchHandlesList } from "./common"; 5import { IDB_HANDLES } from "./constants"; 6 7//////////////////////////////////////////// 8// SIGNALS 9//////////////////////////////////////////// 10export const [mounts, setMounts] = signal(await fetchHandlesList()); 11 12//////////////////////////////////////////// 13// ACTIONS 14//////////////////////////////////////////// 15export const mount = async () => { 16 await showDirectoryPicker() 17 .then(async (handle) => { 18 const existingHandles = await fetchHandles(); 19 const id = crypto.randomUUID(); 20 21 await handle.requestPermission({ mode: "read" }); 22 await IDB.set(IDB_HANDLES, { ...existingHandles, [id]: handle }); 23 setMounts(await fetchHandlesList()); 24 }) 25 .catch(() => {}); 26}; 27 28export const unmount = async (handleId: string) => { 29 const handles = await fetchHandles(); 30 delete handles[handleId]; 31 await IDB.set(IDB_HANDLES, { ...handles }); 32 setMounts(await fetchHandlesList()); 33};