an appview-less Bluesky client using Constellation and PDS Queries reddwarf.app
frontend spa bluesky reddwarf microcosm
1import type Agent from "@atproto/api"; 2import { atom, createStore, useAtomValue } from "jotai"; 3import { atomWithStorage } from "jotai/utils"; 4import { useEffect } from "react"; 5 6export const store = createStore(); 7 8export const selectedFeedUriAtom = atomWithStorage<string | null>( 9 "selectedFeedUri", 10 null 11); 12 13//export const feedScrollPositionsAtom = atom<Record<string, number>>({}); 14 15export const feedScrollPositionsAtom = atomWithStorage<Record<string, number>>( 16 "feedscrollpositions", 17 {} 18); 19 20export const likedPostsAtom = atomWithStorage<Record<string, string>>( 21 "likedPosts", 22 {} 23); 24 25export const defaultconstellationURL = "constellation.microcosm.blue"; 26export const constellationURLAtom = atomWithStorage<string>( 27 "constellationURL", 28 defaultconstellationURL 29); 30export const defaultslingshotURL = "slingshot.microcosm.blue"; 31export const slingshotURLAtom = atomWithStorage<string>( 32 "slingshotURL", 33 defaultslingshotURL 34); 35export const defaultImgCDN = "cdn.bsky.app"; 36export const imgCDNAtom = atomWithStorage<string>("imgcdnurl", defaultImgCDN); 37export const defaultVideoCDN = "video.bsky.app"; 38export const videoCDNAtom = atomWithStorage<string>( 39 "videocdnurl", 40 defaultVideoCDN 41); 42 43export const defaulthue = 28; 44export const hueAtom = atomWithStorage<number>("hue", defaulthue); 45 46export const isAtTopAtom = atom<boolean>(true); 47 48type ComposerState = 49 | { kind: "closed" } 50 | { kind: "root" } 51 | { kind: "reply"; parent: string } 52 | { kind: "quote"; subject: string }; 53export const composerAtom = atom<ComposerState>({ kind: "closed" }); 54 55export const agentAtom = atom<Agent | null>(null); 56export const authedAtom = atom<boolean>(false); 57 58export function useAtomCssVar(atom: typeof hueAtom, cssVar: string) { 59 const value = useAtomValue(atom); 60 61 useEffect(() => { 62 document.documentElement.style.setProperty(cssVar, value.toString()); 63 }, [value, cssVar]); 64 65 useEffect(() => { 66 document.documentElement.style.setProperty(cssVar, value.toString()); 67 }, []); 68} 69 70hueAtom.onMount = (setAtom) => { 71 const stored = localStorage.getItem("hue"); 72 if (stored != null) setAtom(Number(stored)); 73}; 74// export function initAtomToCssVar(atom: typeof hueAtom, cssVar: string) { 75// const initial = store.get(atom); 76// console.log("atom get ", initial); 77// document.documentElement.style.setProperty(cssVar, initial.toString()); 78// }