an appview-less Bluesky client using Constellation and PDS Queries reddwarf.app
frontend spa bluesky reddwarf microcosm
at main 1.1 kB view raw
1import { useAtom } from "jotai"; 2import { useCallback } from "react"; 3 4import { type LikeRecord,useLikeMutationQueue as useLikeMutationQueueFromProvider } from "~/providers/LikeMutationQueueProvider"; 5import { useAuth } from "~/providers/UnifiedAuthProvider"; 6 7import { internalLikedPostsAtom } from "./atoms"; 8 9export function useFastLike(target: string, cid: string) { 10 const { agent } = useAuth(); 11 const { fastState, fastToggle, backfillState } = useLikeMutationQueueFromProvider(); 12 13 const liked = fastState(target); 14 const toggle = () => fastToggle(target, cid); 15 /** 16 * 17 * @deprecated dont use it yet, will cause infinite rerenders 18 */ 19 const backfill = () => agent?.did && backfillState(target, agent.did); 20 21 return { liked, toggle, backfill }; 22} 23 24export function useFastSetLikesFromFeed() { 25 const [_, setLikedPosts] = useAtom(internalLikedPostsAtom); 26 27 const setFastState = useCallback( 28 (target: string, record: LikeRecord | null) => 29 setLikedPosts((prev) => ({ ...prev, [target]: record })), 30 [setLikedPosts] 31 ); 32 33 return { setFastState }; 34}