import { ActorSuggestionList, useActorSuggestions } from "$/components/actors/ActorSearch"; import { ActorTypeaheadLoading } from "$/components/actors/ActorTypeaheadLoading"; import { useActorTypeaheadCombobox } from "$/components/actors/hooks/useActorTypeaheadCombobox"; import { Icon } from "$/components/shared/Icon"; import type { ActorSuggestion } from "$/lib/types"; import * as logger from "@tauri-apps/plugin-log"; import { createSignal } from "solid-js"; import type { ProfileSelection } from "../types"; export function ProfilePicker(props: { onSubmit: (selection: ProfileSelection) => void }) { let container: HTMLDivElement | undefined; let input: HTMLInputElement | undefined; const [value, setValue] = createSignal(""); const typeahead = useActorSuggestions({ container: () => container, input: () => input, onError: (error) => logger.warn(`Failed to load profile suggestions: ${String(error)}`), value, }); const combobox = useActorTypeaheadCombobox({ ariaControls: "profile-suggestions", onSelect: submitSuggestion, typeahead, }); function submitManualActor() { const actor = value().trim(); if (!actor) { return; } typeahead.close(); props.onSubmit({ actor }); } function submitSuggestion(suggestion: ActorSuggestion) { typeahead.close(); props.onSubmit({ actor: suggestion.handle, did: suggestion.did, displayName: suggestion.displayName ?? null, handle: suggestion.handle, }); } return (
); }