|
1 |
| -import { useQuery } from '@tanstack/react-query' |
2 |
| -import { memo, useCallback } from 'react' |
| 1 | +import EmojiPicker$, { EmojiStyle } from 'emoji-picker-react' |
| 2 | +import { memo } from 'react' |
3 | 3 | import type { FC } from 'react'
|
4 | 4 |
|
5 |
| -import { Loading } from '~/components/ui/loading' |
6 |
| - |
7 | 5 | export const EmojiPicker: FC<{
|
8 | 6 | onEmojiSelect: (emoji: string) => void
|
9 | 7 | }> = memo(({ onEmojiSelect }) => {
|
10 |
| - const { data, isLoading } = useQuery({ |
11 |
| - queryKey: ['emoji-data'], |
12 |
| - queryFn: () => |
13 |
| - fetch('https://cdn.jsdelivr.net/npm/@emoji-mart/data', { |
14 |
| - next: { |
15 |
| - revalidate: 60 * 60 * 24 * 7, |
16 |
| - }, |
17 |
| - }).then((response) => response.json()), |
18 |
| - |
19 |
| - staleTime: Number.POSITIVE_INFINITY, |
20 |
| - }) |
21 |
| - const handleSelect = useCallback((emoji: any) => { |
22 |
| - return onEmojiSelect(emoji.native) |
23 |
| - }, []) |
24 |
| - |
25 |
| - const handleDivRef = (divEl: HTMLDivElement) => { |
26 |
| - import('emoji-mart').then( |
27 |
| - (m) => |
28 |
| - new m.Picker({ |
29 |
| - ref: { |
30 |
| - current: divEl, |
31 |
| - }, |
32 |
| - data, |
33 |
| - onEmojiSelect: handleSelect, |
34 |
| - maxFrequentRows: 0, |
35 |
| - }), |
36 |
| - ) |
37 |
| - } |
38 |
| - |
39 |
| - if (isLoading) |
40 |
| - return ( |
41 |
| - <Loading className="flex h-[435px] w-[352px] rounded-md bg-slate-100 center dark:bg-neutral-800" /> |
42 |
| - ) |
43 |
| - |
44 | 8 | return (
|
45 |
| - <div className="w-[352px]"> |
46 |
| - <div ref={handleDivRef} /> |
47 |
| - </div> |
| 9 | + <EmojiPicker$ |
| 10 | + onEmojiClick={(e) => { |
| 11 | + onEmojiSelect(e.emoji) |
| 12 | + }} |
| 13 | + emojiStyle={EmojiStyle.NATIVE} |
| 14 | + /> |
48 | 15 | )
|
49 | 16 | })
|
50 | 17 | EmojiPicker.displayName = 'EmojiPicker'
|
0 commit comments