feat: move emoji picker from ResourceBrowser into item editor form
All checks were successful
Deploy / build-and-deploy (push) Successful in 1m48s

This commit is contained in:
2026-06-15 02:58:18 +03:00
parent 0c35693598
commit 6a4be6b939
2 changed files with 61 additions and 118 deletions

View File

@@ -5,7 +5,7 @@ import { Card, CardContent } from "./ui/card";
import { Button } from "./ui/button"; import { Button } from "./ui/button";
import { Input } from "./ui/input"; import { Input } from "./ui/input";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./ui/select"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./ui/select";
import { SOUND_CATEGORIES, EMOJIS } from "@/lib/bingo-data"; import { SOUND_CATEGORIES } from "@/lib/bingo-data";
import { Badge } from "./ui/badge"; import { Badge } from "./ui/badge";
import { ResourceBrowser, DragData } from "./ResourceBrowser"; import { ResourceBrowser, DragData } from "./ResourceBrowser";
import { playSoundOnce } from "@/lib/sounds"; import { playSoundOnce } from "@/lib/sounds";
@@ -27,43 +27,52 @@ type Campaign = {
gridSize: number; gridSize: number;
}; };
function EmojiPicker({ value, onChange }: { value: string; onChange: (v: string) => void }) { const EMOJI_LIST = [
const [open, setOpen] = useState(false); "😀", "😂", "🤣", "😍", "🥰", "😘", "😊", "😎", "🤩", "🥳", "🤯", "😱",
const ref = useRef<HTMLDivElement>(null); "😈", "🤡", "💀", "👻", "👽", "🤖", "🎃", "😺", "🙈", "🙉", "🙊", "💩",
"🔥", "🌊", "💥", "💫", "⭐", "🌟", "✨", "⚡", "☄️", "💧", "🧊", "🌋",
"🎉", "🎊", "🎈", "🎁", "🏆", "🥇", "💎", "🔮", "🪄", "🧨", "🔫", "⚔️",
"🛡️", "🚀", "🛸", "🚁", "⚓", "🌀", "🌈", "🌪️", "☢️", "☣️", "⚕️", "🧬",
"💉", "💊", "🩸", "🧪", "🔬", "🔭", "📡", "🎯", "🎲", "♟️", "🧩", "🎭",
"🎵", "🎶", "🎺", "📯", "🔔", "🎤", "🎧", "📢", "📣", "🔊", "🔇", "💤",
"💣", "🔪", "🪦", "⚰️", "🪤", "🧲", "🗝️", "🔑", "🔓", "🔒", "🛠️", "⛓️",
"🧹", "🪠", "🔧", "⚙️", "📦", "📀", "💿", "📹", "📸", "📷", "🖼️", "🎨",
"🍺", "🍻", "🍷", "🥃", "🍸", "🍹", "🧉", "🍕", "🍔", "🌭", "🍿", "🧀",
"🥜", "🌶️", "🍄", "🥚", "🧅", "🥕", "🥦", "🫁", "🧠", "👀", "👁️", "🫀",
"💋", "🫂", "🤝", "👍", "👎", "👊", "✊", "🤛", "🤜", "👆", "👇", "🖕",
"💪", "🦵", "🦶", "👂", "👃", "🧑‍🚀", "🧑‍🔧", "🧑‍⚕️", "🧑‍✈️", "🧑‍🏫", "🧑‍🎤", "🧑‍🍳",
"🐶", "🐱", "🐭", "🐹", "🐰", "🦊", "🐻", "🐼", "🐨", "🐯", "🦁", "🐮",
"🦈", "🐙", "🦑", "🐋", "🐬", "🦭", "🐊", "🦎", "🐍", "🐢", "🦖", "🦕",
"🦟", "🦗", "🐛", "🪱", "🦋", "🐌", "🐞", "🐜", "🦂", "🕷️", "🦀", "🪸",
];
useEffect(() => { function EmojiPickerGrid({ value, onChange }: { value: string; onChange: (v: string) => void }) {
function handleClick(e: MouseEvent) { const [search, setSearch] = useState("");
if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false); const filtered = search ? EMOJI_LIST.filter(e => e.includes(search)) : EMOJI_LIST;
}
document.addEventListener("mousedown", handleClick);
return () => document.removeEventListener("mousedown", handleClick);
}, []);
return ( return (
<div ref={ref} className="relative"> <div className="space-y-2">
<button <input
type="button" type="text"
onClick={() => setOpen(!open)} placeholder="Search emoji..."
className="w-10 h-10 flex items-center justify-center text-xl rounded border border-slate-700/50 bg-slate-800/50 hover:bg-slate-700/50 cursor-pointer" value={search}
> onChange={e => setSearch(e.target.value)}
{value || "?"} className="w-full bg-slate-800/60 border border-slate-700/30 rounded px-2 py-1 text-[10px] font-mono text-slate-200 placeholder:text-slate-600 outline-none focus:border-cyan-500/50"
</button> />
{open && ( <div className="flex flex-wrap gap-1 max-h-36 overflow-y-auto">
<div className="absolute top-full left-0 mt-1 z-50 bg-slate-900 border border-slate-700/50 rounded-lg p-2 shadow-xl w-[280px]"> {filtered.map(e => (
<div className="grid grid-cols-8 gap-1"> <button
{EMOJIS.map(e => ( key={e}
<button type="button"
key={e} onClick={() => onChange(e)}
type="button" className={`w-7 h-7 flex items-center justify-center text-sm rounded hover:bg-slate-700/60 cursor-pointer active:scale-90 transition-transform ${
onClick={() => { onChange(e); setOpen(false); }} e === value ? "bg-cyan-700/50 ring-1 ring-cyan-400" : ""
className={`w-8 h-8 flex items-center justify-center text-base rounded hover:bg-slate-700 cursor-pointer ${e === value ? "bg-cyan-700/50 ring-1 ring-cyan-400" : ""}`} }`}
> >
{e} {e}
</button> </button>
))} ))}
</div> </div>
</div>
)}
</div> </div>
); );
} }
@@ -95,15 +104,7 @@ export function ItemEditor({ campaign }: { campaign: Campaign }) {
useEffect(() => { fetchItems(); }, [campaign.id]); useEffect(() => { fetchItems(); }, [campaign.id]);
// Listen for emoji-select from ResourceBrowser EmojisTab
useEffect(() => {
const handler = (e: Event) => {
const detail = (e as CustomEvent).detail;
if (detail?.emoji) setEditEmoji(detail.emoji);
};
window.addEventListener("emoji-select", handler);
return () => window.removeEventListener("emoji-select", handler);
}, []);
const updateItem = async (item: Item) => { const updateItem = async (item: Item) => {
await fetch(`/api/campaigns/${campaign.id}/items`, { await fetch(`/api/campaigns/${campaign.id}/items`, {
@@ -259,20 +260,22 @@ export function ItemEditor({ campaign }: { campaign: Campaign }) {
</button> </button>
</div> </div>
</div> </div>
<div className="flex-1 min-w-[150px]">
<label className="text-[9px] font-mono text-slate-600 uppercase">Text</label>
<Input
placeholder="Reactor explodes"
value={editText}
onChange={e => setEditText(e.target.value)}
className="font-mono text-sm"
/>
</div>
<div>
<label className="text-[9px] font-mono text-slate-600 uppercase">Emoji click to select</label>
<EmojiPickerGrid value={editEmoji} onChange={setEditEmoji} />
</div>
<div className="flex flex-wrap gap-2 items-end"> <div className="flex flex-wrap gap-2 items-end">
<div className="flex-1 min-w-[150px]">
<label className="text-[9px] font-mono text-slate-600 uppercase">Text</label>
<Input
placeholder="Reactor explodes"
value={editText}
onChange={e => setEditText(e.target.value)}
className="font-mono text-sm"
/>
</div>
<div>
<label className="text-[9px] font-mono text-slate-600 uppercase">Emoji</label>
<EmojiPicker value={editEmoji} onChange={setEditEmoji} />
</div>
<div className="w-32"> <div className="w-32">
<label className="text-[9px] font-mono text-slate-600 uppercase">Sound</label> <label className="text-[9px] font-mono text-slate-600 uppercase">Sound</label>
<Select <Select

View File

@@ -33,58 +33,7 @@ export type DragData =
| { type: "image"; url: string; originalName: string } | { type: "image"; url: string; originalName: string }
| { type: "emoji"; emoji: string }; | { type: "emoji"; emoji: string };
// ─── Emoji Picker (inline, searchable) ──────────────────────────────
const EMOJI_LIST = [
"😀", "😂", "🤣", "😍", "🥰", "😘", "😊", "😎", "🤩", "🥳", "🤯", "😱",
"😈", "🤡", "💀", "👻", "👽", "🤖", "🎃", "😺", "🙈", "🙉", "🙊", "💩",
"🔥", "🌊", "💥", "💫", "⭐", "🌟", "✨", "⚡", "☄️", "💧", "🧊", "🌋",
"🎉", "🎊", "🎈", "🎁", "🏆", "🥇", "💎", "🔮", "🪄", "🧨", "🔫", "⚔️",
"🛡️", "🚀", "🛸", "🚁", "⚓", "🌀", "🌈", "🌪️", "☢️", "☣️", "⚕️", "🧬",
"💉", "💊", "🩸", "🧪", "🔬", "🔭", "📡", "🎯", "🎲", "♟️", "🧩", "🎭",
"🎵", "🎶", "🎺", "📯", "🔔", "🎤", "🎧", "📢", "📣", "🔊", "🔇", "💤",
"💣", "🔪", "🪦", "⚰️", "🪤", "🧲", "🗝️", "🔑", "🔓", "🔒", "🛠️", "⛓️",
"🧹", "🪠", "🔧", "⚙️", "📦", "📀", "💿", "📹", "📸", "📷", "🖼️", "🎨",
"🍺", "🍻", "🍷", "🥃", "🍸", "🍹", "🧉", "🍕", "🍔", "🌭", "🍿", "🧀",
"🥜", "🌶️", "🍄", "🥚", "🧅", "🥕", "🥦", "🫁", "🧠", "👀", "👁️", "🫀",
"💋", "🫂", "🤝", "👍", "👎", "👊", "✊", "🤛", "🤜", "👆", "👇", "🖕",
"💪", "🦵", "🦶", "👂", "👃", "🧑‍🚀", "🧑‍🔧", "🧑‍⚕️", "🧑‍✈️", "🧑‍🏫", "🧑‍🎤", "🧑‍🍳",
"🐶", "🐱", "🐭", "🐹", "🐰", "🦊", "🐻", "🐼", "🐨", "🐯", "🦁", "🐮",
"🦈", "🐙", "🦑", "🐋", "🐬", "🦭", "🐊", "🦎", "🐍", "🐢", "🦖", "🦕",
"🦟", "🦗", "🐛", "🪱", "🦋", "🐌", "🐞", "🐜", "🦂", "🕷️", "🦀", "🪸",
];
function EmojiPickerGrid({ onSelect }: { onSelect: (emoji: string) => void }) {
const [search, setSearch] = useState("");
const filtered = search ? EMOJI_LIST.filter(e => e.includes(search)) : EMOJI_LIST;
return (
<div className="space-y-2">
<input
type="text"
placeholder="Search emoji..."
value={search}
onChange={e => setSearch(e.target.value)}
className="w-full bg-slate-800/60 border border-slate-700/30 rounded px-2 py-1.5 text-xs font-mono text-slate-200 placeholder:text-slate-600 outline-none focus:border-cyan-500/50"
/>
<div className="grid grid-cols-10 gap-1 max-h-48 overflow-y-auto">
{filtered.map(e => (
<button
key={e}
draggable
onDragStart={ev => {
ev.dataTransfer.setData("application/json", JSON.stringify({ type: "emoji", emoji: e } satisfies DragData));
}}
onClick={() => onSelect(e)}
className="w-8 h-8 flex items-center justify-center text-base rounded hover:bg-slate-700/60 cursor-pointer active:scale-90 transition-transform"
>
{e}
</button>
))}
</div>
</div>
);
}
// ─── Sounds Tab ───────────────────────────────────────────────────── // ─── Sounds Tab ─────────────────────────────────────────────────────
@@ -376,7 +325,7 @@ function FreesoundRow({ name, duration, onPreview, onImport }: {
// ─── Main ResourceBrowser ─────────────────────────────────────────── // ─── Main ResourceBrowser ───────────────────────────────────────────
type Tab = "sounds" | "images" | "emojis"; type Tab = "sounds" | "images";
export function ResourceBrowser({ visible, onClose }: { visible: boolean; onClose: () => void }) { export function ResourceBrowser({ visible, onClose }: { visible: boolean; onClose: () => void }) {
const [tab, setTab] = useState<Tab>("sounds"); const [tab, setTab] = useState<Tab>("sounds");
@@ -390,7 +339,6 @@ export function ResourceBrowser({ visible, onClose }: { visible: boolean; onClos
{([ {([
{ key: "sounds" as const, label: "🔊 Sounds" }, { key: "sounds" as const, label: "🔊 Sounds" },
{ key: "images" as const, label: "🖼️ Images" }, { key: "images" as const, label: "🖼️ Images" },
{ key: "emojis" as const, label: "😀 Emojis" },
]).map(t => ( ]).map(t => (
<button <button
key={t.key} key={t.key}
@@ -414,17 +362,9 @@ export function ResourceBrowser({ visible, onClose }: { visible: boolean; onClos
<div className="max-h-72 overflow-y-auto"> <div className="max-h-72 overflow-y-auto">
{tab === "sounds" && <SoundsTab />} {tab === "sounds" && <SoundsTab />}
{tab === "images" && <ImagesTab />} {tab === "images" && <ImagesTab />}
{tab === "emojis" && <EmojisTab />}
</div> </div>
</div> </div>
); );
} }
function EmojisTab() {
const handleSelect = (emoji: string) => {
// Dispatch a custom event so ItemEditor can pick it up
window.dispatchEvent(new CustomEvent("emoji-select", { detail: { emoji } }));
};
return <div className="p-3"><EmojiPickerGrid onSelect={handleSelect} /></div>;
}