feat(stickers): "recently used" row in the sticker picker

The emoji and GIF pickers both have a "Recent" row, but the sticker tab of the
shared EmojiBoard did not — you had to hunt through packs to re-send a sticker.
Add recent stickers, mirroring recentGifs:

- New state/recentStickers.ts (localStorage cinny_recent_stickers_v1, deduped by
  url, capped 16) + pure addRecentSticker with 4 unit tests.
- EmojiBoard: a "Recent" group in stickerGroupItems and a RecentClock sidebar
  icon in StickerSidebar, shown only when recents exist. Entries are rebuilt into
  minimal PackImageReaders (StickerItem needs only url/shortcode/body) so they
  render + re-send like pack stickers.
- Recorded on select in the shared delegated click handler, covering both the
  grouped and search paths.

Blast radius is the sticker tab only (reactions/status use the emoji tab).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-10 22:43:17 -04:00
co-authored by Claude Opus 4.8
parent fb8e0c6e14
commit 3a1c626bc8
4 changed files with 144 additions and 2 deletions
+50
View File
@@ -0,0 +1,50 @@
import { atom } from 'jotai';
import { atomWithStorage, createJSONStorage } from 'jotai/utils';
export type RecentSticker = {
/** mxc:// url of the sticker image. */
url: string;
shortcode: string;
body?: string;
};
const STORAGE_KEY = 'cinny_recent_stickers_v1';
const MAX_RECENT_STICKERS = 16;
// getOnInit reads localStorage synchronously so the Recent group is present on the
// first render of the sticker picker (no flash of the empty default).
const internalAtom = atomWithStorage<RecentSticker[]>(
STORAGE_KEY,
[],
createJSONStorage(() => localStorage),
{ getOnInit: true },
);
/**
* Global atom: the most recently sent stickers, newest first, deduped by url,
* capped at MAX_RECENT_STICKERS. Backed by localStorage (device-local
* convenience), mirroring `recentGifsAtom`.
*/
export const recentStickersAtom = atom(
(get): RecentSticker[] => get(internalAtom),
(_get, set, updater: RecentSticker[] | ((prev: RecentSticker[]) => RecentSticker[])) => {
set(internalAtom, (prev) => {
const prevList = Array.isArray(prev) ? prev : [];
return typeof updater === 'function' ? updater(prevList) : updater;
});
}
);
/**
* Prepend a sticker: ignores an empty url, de-dupes by url (moving an existing
* entry to the front), and caps the list at `max`. Pure — returns a new array.
*/
export const addRecentSticker = (
prev: RecentSticker[],
sticker: RecentSticker,
max = MAX_RECENT_STICKERS
): RecentSticker[] => {
if (!sticker.url) return prev;
const withoutDupe = prev.filter((s) => s.url !== sticker.url);
return [sticker, ...withoutDupe].slice(0, max);
};