mirror of
https://github.com/outline/outline.git
synced 2026-11-22 14:01:41 +03:00
* 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>
19 lines
664 B
TypeScript
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 };
|
|
}
|