BlueSky & more on desktop
lazurite.stormlightlabs.org/
tauri
rust
typescript
bluesky
appview
atproto
solid
1import { BOOKMARK_CHANGED_EVENT, POST_VIEW_UPDATED_EVENT } from "$/lib/constants/events";
2import type { ViewerState } from "$/lib/types";
3
4export type PostViewUpdateDetail = {
5 likeCount?: number | null;
6 repostCount?: number | null;
7 uri: string;
8 viewer?: Partial<ViewerState> | null;
9};
10
11type BookmarkChangedDetail = { bookmarked: boolean; cid: string; uri: string };
12
13export function emitPostViewUpdated(detail: PostViewUpdateDetail) {
14 globalThis.dispatchEvent(new CustomEvent<PostViewUpdateDetail>(POST_VIEW_UPDATED_EVENT, { detail }));
15}
16
17export function emitBookmarkChanged(detail: BookmarkChangedDetail) {
18 globalThis.dispatchEvent(new CustomEvent<BookmarkChangedDetail>(BOOKMARK_CHANGED_EVENT, { detail }));
19}
20
21export function subscribePostViewUpdated(listener: (detail: PostViewUpdateDetail) => void) {
22 const handler = (event: Event) => listener((event as CustomEvent<PostViewUpdateDetail>).detail);
23 globalThis.addEventListener(POST_VIEW_UPDATED_EVENT, handler);
24 return () => globalThis.removeEventListener(POST_VIEW_UPDATED_EVENT, handler);
25}
26
27export function subscribeBookmarkChanged(listener: (detail: BookmarkChangedDetail) => void) {
28 const handler = (event: Event) => listener((event as CustomEvent<BookmarkChangedDetail>).detail);
29 globalThis.addEventListener(BOOKMARK_CHANGED_EVENT, handler);
30 return () => globalThis.removeEventListener(BOOKMARK_CHANGED_EVENT, handler);
31}