import { q } from "@thorium/context/AppContext"; import { Icon } from "@thorium/ui/Icon"; import { cn } from "@thorium/utils/cn"; import { matchSorter } from "match-sorter"; import { useState } from "react"; import { Button, ComboBox, Group, Input, ListBox, ListBoxItem, Popover, } from "react-aria-components"; export function EventCombobox({ value, onChange, placeholder = "Events", }: { value: { name: string; event: string; input?: any; } | null; onChange: (value: { name: string; event: string; input?: any }) => void; placeholder?: string; className?: string; }) { const [availableEvents] = q.thorium.events.useNetRequest(); const [query, setQuery] = useState(value?.event || ""); const filteredEvents = matchSorter(availableEvents, query, { keys: ["name", "event"], }).map((a) => ({ ...a, key: a.event })); return ( { const event = availableEvents.find((a) => a.event === key)!; if (!event) return; onChange(event); setQuery(event.name); }} onOpenChange={(open) => { setQuery(open ? "" : value?.name || ""); }} aria-label={placeholder} > {(item) => ( {({ isSelected, isFocusVisible, isHovered }) => ( <> {item.name} {isSelected && ( )} )} )} ); }