Files
outline/app/hooks/useFrequencyTracker.ts
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

19 lines
664 B
TypeScript

import { useCallback, useState } from "react";
import type { FrequencyTracker } from "@shared/utils/FrequencyTracker";
/**
* Read the most frequent items from a tracker, snapshotted on mount so the
* order does not shift beneath the user while the component remains open.
*
* @param tracker the tracker to read from.
* @returns the most frequent items and a function to track a use of an item.
*/
export default function useFrequencyTracker<T extends string>(
tracker: FrequencyTracker<T>
) {
const [frequent] = useState(() => tracker.frequent);
const track = useCallback((item: T) => tracker.track(item), [tracker]);
return { frequent, track };
}