mirror of
https://github.com/block/buzz.git
synced 2026-11-24 10:12:19 +00:00
## Summary - show status and huddle emoji beside names in DMs and message rows - provide accessible tooltips, fallback status emoji, and profile-menu icon replacement - add the desktop status editor with preset durations, a ShadCN calendar, and a capped half-hour time menu ## Validation - desktop checks, typecheck, and file-size guard - 5,802 desktop tests - focused Playwright coverage (3 passed) - E2E build and native Builderlab staging verification Updated visual snapshots are attached in the PR comments. --------- Signed-off-by: kenny lopez <klopez4212@gmail.com> Signed-off-by: Princess Donut <b238ea756dee4d98afa5883fc7f1de61eeabe65bf700e3a5a5a80db5e42e2c2b@buzz.block.builderlab.xyz> Co-authored-by: Princess Donut <b238ea756dee4d98afa5883fc7f1de61eeabe65bf700e3a5a5a80db5e42e2c2b@buzz.block.builderlab.xyz>
80 lines
2.2 KiB
TypeScript
80 lines
2.2 KiB
TypeScript
import * as React from "react";
|
|
|
|
import { useUserStatusQuery } from "@/features/user-status/hooks";
|
|
import type { UserStatusLookup } from "@/shared/api/types";
|
|
import { normalizePubkey } from "@/shared/lib/pubkey";
|
|
|
|
const EMPTY_USER_STATUS_LOOKUP: UserStatusLookup = {};
|
|
|
|
type UserStatusLookupContextValue = {
|
|
lookup: UserStatusLookup;
|
|
register: (pubkey: string) => () => void;
|
|
};
|
|
|
|
const UserStatusLookupContext =
|
|
React.createContext<UserStatusLookupContextValue | null>(null);
|
|
|
|
/** Batches the status lookup shared by every mounted name indicator. */
|
|
export function UserStatusLookupProvider({
|
|
children,
|
|
}: {
|
|
children: React.ReactNode;
|
|
}) {
|
|
const [registrations, setRegistrations] = React.useState<
|
|
ReadonlyMap<string, number>
|
|
>(new Map());
|
|
|
|
const register = React.useCallback((value: string) => {
|
|
const pubkey = normalizePubkey(value);
|
|
if (!pubkey) return () => {};
|
|
|
|
let active = true;
|
|
setRegistrations((current) => {
|
|
const next = new Map(current);
|
|
next.set(pubkey, (next.get(pubkey) ?? 0) + 1);
|
|
return next;
|
|
});
|
|
|
|
return () => {
|
|
if (!active) return;
|
|
active = false;
|
|
setRegistrations((current) => {
|
|
const count = current.get(pubkey) ?? 0;
|
|
if (count === 0) return current;
|
|
const next = new Map(current);
|
|
if (count === 1) next.delete(pubkey);
|
|
else next.set(pubkey, count - 1);
|
|
return next;
|
|
});
|
|
};
|
|
}, []);
|
|
|
|
const pubkeys = React.useMemo(
|
|
() => [...registrations.keys()].sort(),
|
|
[registrations],
|
|
);
|
|
const pubkeysKey = pubkeys.join(":");
|
|
const deferredPubkeys = React.useDeferredValue(pubkeys);
|
|
const deferredPubkeysKey = deferredPubkeys.join(":");
|
|
const queriedPubkeys =
|
|
pubkeysKey === deferredPubkeysKey ? pubkeys : deferredPubkeys;
|
|
const statusQuery = useUserStatusQuery(queriedPubkeys, true);
|
|
const value = React.useMemo(
|
|
() => ({
|
|
lookup: statusQuery.data ?? EMPTY_USER_STATUS_LOOKUP,
|
|
register,
|
|
}),
|
|
[register, statusQuery.data],
|
|
);
|
|
|
|
return (
|
|
<UserStatusLookupContext.Provider value={value}>
|
|
{children}
|
|
</UserStatusLookupContext.Provider>
|
|
);
|
|
}
|
|
|
|
export function useUserStatusLookupContext() {
|
|
return React.useContext(UserStatusLookupContext);
|
|
}
|