Files
Tom MoorandClaude Fable 5 73f960a544 fix: Invalid sort comparator for frequently used items (#13258)
* fix: Invalid sort comparator for frequently used items (#13241)

Extracts frequency tracking for icons, emojis, and code languages into a
shared FrequencyTracker with a spec-compliant, stable sort.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Snapshot frequently used icons while picker is open

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Sync frequent custom emojis to tracked ids, preserving order

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-02 08:43:28 -04:00

28 lines
754 B
TypeScript

import { emojiSkinToneKey, iconFrequencies } from "./utils";
import useFrequencyTracker from "~/hooks/useFrequencyTracker";
import usePersistedState from "~/hooks/usePersistedState";
import { EmojiSkinTone, IconType } from "@shared/types";
const skinToneKeys = {
[IconType.Custom]: "",
[IconType.Emoji]: emojiSkinToneKey,
[IconType.SVG]: "",
};
export const useIconState = (type: IconType) => {
const [emojiSkinTone, setEmojiSkinTone] = usePersistedState<EmojiSkinTone>(
skinToneKeys[type],
EmojiSkinTone.Default
);
const { frequent: frequentIcons, track: incrementIconCount } =
useFrequencyTracker(iconFrequencies[type]);
return {
emojiSkinTone,
setEmojiSkinTone,
incrementIconCount,
frequentIcons,
};
};