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:
jaredandClaude Opus 4.8 committed 2026-07-10 22:43:17 -04:00
1 parent fb8e0c6e14
commit 3a1c626bc8
4 files changed
+144 -2

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
// The module evaluates atomWithStorage(..., { getOnInit: true }), which reads
// localStorage at load time. node has none, so install a no-op mock, then import
// dynamically (a static import would hoist above the mock and evaluate too early).
(globalThis as { localStorage?: unknown }).localStorage = {
getItem: () => null,
setItem: () => undefined,
removeItem: () => undefined,
};
const { addRecentSticker } = await import('./recentStickers');
const st = (url: string, shortcode = url, body = url) => ({ url, shortcode, body });
test('addRecentSticker prepends a new sticker', () => {
const out = addRecentSticker([st('a'), st('b')], st('c'));
assert.deepEqual(
out.map((s) => s.url),
['c', 'a', 'b']
);
});
test('addRecentSticker de-dupes by url, moving the existing one to the front', () => {
const out = addRecentSticker([st('a'), st('b'), st('c')], st('c'));
assert.deepEqual(
out.map((s) => s.url),
['c', 'a', 'b']
);
assert.equal(out.length, 3);
});
test('addRecentSticker caps the list at max (newest kept)', () => {
const start = [st('a'), st('b'), st('c')];
const out = addRecentSticker(start, st('d'), 3);
assert.deepEqual(
out.map((s) => s.url),
['d', 'a', 'b']
);
});
test('addRecentSticker ignores an empty url', () => {
const start = [st('a')];
const out = addRecentSticker(start, st(''));
assert.equal(out, start); // returns the same array unchanged
});