import { type ComponentProps, createContext, useContext, useEffect, useRef, useState } from 'react' import { IconArrowBack, IconLoader2, IconMoodSad, IconUpload } from '@tabler/icons-react' import { EmojiPicker, type EmojiPickerListCategoryHeaderProps, type EmojiPickerListEmojiProps, type EmojiPickerListRowProps } from 'frimousse' import { Button } from '@/client/components/ui/button' import { Checkbox } from '@/client/components/ui/checkbox' import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/client/components/ui/tabs' import { useUpdateWorkspaceIcon } from '@/client/features/workspace/settings/api' import { useWorkspaceLayoutCtx } from '@/client/features/workspace/workspace-layout-context' import { IDENTITY_ICON_CHOICES } from '@/client/lib/identity-icon-registry' import { cn } from '@/client/lib/cn' import type { WorkspaceIcon } from '@/lib/types' import { EMOJI_FONT, FAVORITE_EMOJI } from './icon-picker-options' type IconSelection = Exclude const PICKER_ITEM_SIZE = 32 const PICKER_ITEM_GAP = 4 const PICKER_ROW_PADDING = 12 const GROUP_LABEL_CLASS = 'flex pt-4 pb-2 items-center bg-background px-3 text-xs font-medium text-muted-foreground' const SelectedEmojiContext = createContext(null) function withThemeBackground(icon: IconSelection, enabled: boolean): IconSelection { if (enabled) return { ...icon, background: 'theme' } if (icon.type === 'emoji') return { type: 'emoji', value: icon.value } return { type: 'glyph', value: icon.value } } // ── Frimousse list parts (module-level so the virtualized list keeps stable // component identities across re-renders) ─────────────────────────────────── function EmojiCategoryHeader({ category, className, ...props }: EmojiPickerListCategoryHeaderProps) { return (
{category.label}
) } type PickerItemsProps = ComponentProps<'div'> function PickerItems({ className, ...props }: PickerItemsProps) { return
} type PickerItemProps = Omit, 'size' | 'type' | 'variant'> & { selected?: boolean } function PickerItem({ className, selected = false, ...props }: PickerItemProps) { return ( )}
{/* Picker body — fixed height across tabs so the dialog never jumps. */} selectIcon({ type: 'emoji', value: picked.emoji })} // Same-origin emojibase data (vendored under client/vendor/emojibase, // served by server/vendor.ts) — the picker works fully offline. emojibaseUrl="/vendor/emojibase" columns={emojiColumns} className="isolate flex h-72 flex-col overflow-hidden rounded-xl border border-border bg-background" >
setEmojiSearch(e.target.value)} className="h-8 min-w-0 flex-1 appearance-none rounded-md bg-muted px-2.5 text-sm outline-none placeholder:text-muted-foreground" />
Loading emoji… {/* Pinned workspace favorites — rendered inside the scroll area so they read as the first category; hidden while searching so results stay on top. */} {emojiSearch.trim() === '' && (

Favorites

{FAVORITE_EMOJI.map(e => ( selectIcon({ type: 'emoji', value: e })} selected={selection?.type === 'emoji' && selection.value === e} className={EMOJI_FONT} > {e} ))}
)} No emoji found
{IDENTITY_ICON_CHOICES.map(({ id, Icon }) => ( selectIcon({ type: 'glyph', value: id })} selected={selection?.type === 'glyph' && selection.value === id} className="text-muted-foreground aria-pressed:text-accent-foreground" > ))} {mode !== 'upload' && ( )} {updateIcon.error && (

{updateIcon.error.message}

)} { const file = e.target.files?.[0] if (file) selectFile(file) e.target.value = '' }} /> ) }