import { Dialog } from "@kobalte/core/dialog" import { Component, Show, createEffect, createSignal } from "solid-js" import { useI18n } from "../lib/i18n" interface SessionRenameDialogProps { open: boolean currentTitle: string sessionLabel?: string isSubmitting?: boolean onRename: (nextTitle: string) => Promise | void onClose: () => void } const SessionRenameDialog: Component = (props) => { const { t } = useI18n() const [title, setTitle] = createSignal("") const inputId = `session-rename-${Math.random().toString(36).slice(2)}` let inputRef: HTMLInputElement | undefined createEffect(() => { if (!props.open) return setTitle(props.currentTitle ?? "") }) createEffect(() => { if (!props.open) return if (typeof window === "undefined" || typeof window.requestAnimationFrame !== "function") return window.requestAnimationFrame(() => { inputRef?.focus() inputRef?.select() }) }) const isSubmitting = () => Boolean(props.isSubmitting) const isRenameDisabled = () => isSubmitting() || !title().trim() async function handleRename(event?: Event) { event?.preventDefault() if (isRenameDisabled()) return await props.onRename(title().trim()) } const description = () => { if (props.sessionLabel && props.sessionLabel.trim()) { return t("sessionRenameDialog.description.withLabel", { label: props.sessionLabel }) } return t("sessionRenameDialog.description.default") } return ( { if (!open && !isSubmitting()) { props.onClose() } }} >
{t("sessionRenameDialog.title")} {description()}
{ inputRef = element }} type="text" dir="auto" value={title()} onInput={(event) => setTitle(event.currentTarget.value)} placeholder={t("sessionRenameDialog.input.placeholder")} class="w-full px-3 py-2 text-sm bg-surface-base border border-base rounded text-primary focus-ring-accent" />
) } export default SessionRenameDialog