feat: Add emoji usage tracking hook and integrate with EmojiBoard for usage statistics
This commit is contained in:
@@ -22,6 +22,7 @@ import { preventScrollWithArrowKey, stopPropagation } from '../../utils/keyboard
|
||||
import { useRelevantImagePacks } from '../../hooks/useImagePacks';
|
||||
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
||||
import { useRecentEmoji } from '../../hooks/useRecentEmoji';
|
||||
import { useEmojiUsage } from '../../hooks/useEmojiUsage';
|
||||
import { isUserId, mxcUrlToHttp } from '../../utils/matrix';
|
||||
import { editableActiveElement, targetFromEvent } from '../../utils/dom';
|
||||
import { useAsyncSearch, UseAsyncSearchOptions } from '../../hooks/useAsyncSearch';
|
||||
@@ -378,13 +379,30 @@ export function EmojiBoard({
|
||||
addToRecentEmoji = true,
|
||||
}: EmojiBoardProps) {
|
||||
const mx = useMatrixClient();
|
||||
const { trackEmojiUsage, getMostUsedEmoji } = useEmojiUsage();
|
||||
|
||||
const emojiTab = tab === EmojiBoardTab.Emoji;
|
||||
const usage = emojiTab ? ImageUsage.Emoticon : ImageUsage.Sticker;
|
||||
|
||||
// Get default emoji - use most used or fallback to slight_smile
|
||||
const defaultPreview = useMemo((): PreviewData => {
|
||||
if (!emojiTab) return undefined;
|
||||
|
||||
const mostUsedShortcode = getMostUsedEmoji();
|
||||
if (mostUsedShortcode) {
|
||||
// Find emoji by shortcode
|
||||
const emoji = emojis.find((e) => e.shortcode === mostUsedShortcode);
|
||||
if (emoji) {
|
||||
return { key: emoji.unicode, shortcode: emoji.shortcode };
|
||||
}
|
||||
}
|
||||
// Fallback to default
|
||||
return DefaultEmojiPreview;
|
||||
}, [emojiTab, getMostUsedEmoji]);
|
||||
|
||||
const previewAtom = useMemo(
|
||||
() => createPreviewDataAtom(emojiTab ? DefaultEmojiPreview : undefined),
|
||||
[emojiTab]
|
||||
() => createPreviewDataAtom(defaultPreview),
|
||||
[defaultPreview]
|
||||
);
|
||||
const activeGroupIdAtom = useMemo(() => atom<string | undefined>(undefined), []);
|
||||
const setActiveGroupId = useSetAtom(activeGroupIdAtom);
|
||||
@@ -439,6 +457,10 @@ export function EmojiBoard({
|
||||
onEmojiSelect?.(emojiInfo.data, emojiInfo.shortcode);
|
||||
if (!evt.altKey && !evt.shiftKey && addToRecentEmoji) {
|
||||
addRecentEmoji(mx, emojiInfo.data);
|
||||
// Track emoji usage for favorites
|
||||
trackEmojiUsage(emojiInfo.shortcode).catch((err) => {
|
||||
console.error('Failed to track emoji usage:', err);
|
||||
});
|
||||
}
|
||||
}
|
||||
if (emojiInfo.type === EmojiType.CustomEmoji) {
|
||||
|
||||
Reference in New Issue
Block a user