- Note: Format these exactly as you want them on the title card and video filename.
+ Tip: Start typing and select from suggestions for correct formatting, or type freely.
{/* Private (no YouTube upload) mode */}
@@ -390,29 +470,31 @@ export function JobSubmission({ onJobCreated }: JobSubmissionProps) {
- Note: Format these exactly as you want them on the title card and video filename.
+ Tip: Start typing and select from suggestions for correct formatting, or type freely.
{/* Private (no YouTube upload) mode */}
@@ -473,24 +555,26 @@ export function JobSubmission({ onJobCreated }: JobSubmissionProps) {
- Note: Format these exactly as you want them on the title card and video filename.
+ Tip: Start typing and select from suggestions for correct formatting, or type freely.
+ {/* Community version check banner */}
+ {communityData?.has_community && !communityDismissed && (
+ setCommunityDismissed(true)}
+ />
+ )}
+
{/* Display As toggle (optional) */}
- onTitleChange(e.target.value)}
+ onChange={onTitleChange}
+ onSelect={(s) => {
+ onTitleChange(s.label)
+ // Overwrite artist with the canonical name from the selected track
+ if (s.data?.artist_name) {
+ onArtistChange(s.data.artist_name)
+ }
+ }}
+ fetchSuggestions={fetchTrackSuggestions}
disabled={disabled}
style={{ backgroundColor: 'var(--secondary)', borderColor: 'var(--card-border)', color: 'var(--text)' }}
/>
+ {/* Community version banner */}
+ {communityData?.has_community && !communityDismissed && (
+ setCommunityDismissed(true)}
+ />
+ )}
+
{/* Tip callout */}
void
+ /** Called when a suggestion is selected */
+ onSelect?: (suggestion: AutocompleteSuggestion) => void
+ /** Async function to fetch suggestions for a query */
+ fetchSuggestions: (query: string) => Promise
+ /** Minimum characters before fetching suggestions */
+ minChars?: number
+ /** Debounce delay in ms */
+ debounceMs?: number
+ /** Input placeholder */
+ placeholder?: string
+ /** Disable the input */
+ disabled?: boolean
+ /** HTML id for the input */
+ id?: string
+ /** data-testid for testing */
+ "data-testid"?: string
+ /** Inline style for the input element */
+ style?: React.CSSProperties
+ /** Additional className for the input */
+ className?: string
+}
+
+export function AutocompleteInput({
+ value,
+ onChange,
+ onSelect,
+ fetchSuggestions,
+ minChars = 2,
+ debounceMs = 300,
+ placeholder,
+ disabled,
+ id,
+ "data-testid": dataTestId,
+ style,
+ className,
+}: AutocompleteInputProps) {
+ const [open, setOpen] = useState(false)
+ const [suggestions, setSuggestions] = useState([])
+ const [isLoading, setIsLoading] = useState(false)
+ const inputRef = useRef(null)
+ const debounceRef = useRef | null>(null)
+ // Track whether the user just selected a suggestion to avoid re-fetching
+ const justSelectedRef = useRef(false)
+
+ const doFetch = useCallback(
+ async (query: string) => {
+ if (query.length < minChars) {
+ setSuggestions([])
+ setOpen(false)
+ return
+ }
+
+ setIsLoading(true)
+ try {
+ const results = await fetchSuggestions(query)
+ setSuggestions(results)
+ setOpen(results.length > 0)
+ } catch {
+ setSuggestions([])
+ setOpen(false)
+ } finally {
+ setIsLoading(false)
+ }
+ },
+ [fetchSuggestions, minChars]
+ )
+
+ // Debounced fetch on value change
+ useEffect(() => {
+ if (justSelectedRef.current) {
+ justSelectedRef.current = false
+ return
+ }
+
+ if (debounceRef.current) {
+ clearTimeout(debounceRef.current)
+ }
+
+ if (value.length < minChars) {
+ setSuggestions([])
+ setOpen(false)
+ return
+ }
+
+ debounceRef.current = setTimeout(() => {
+ doFetch(value)
+ }, debounceMs)
+
+ return () => {
+ if (debounceRef.current) {
+ clearTimeout(debounceRef.current)
+ }
+ }
+ }, [value, doFetch, debounceMs, minChars])
+
+ function handleSelect(suggestion: AutocompleteSuggestion) {
+ justSelectedRef.current = true
+ onChange(suggestion.label)
+ onSelect?.(suggestion)
+ setOpen(false)
+ setSuggestions([])
+ // Re-focus input after selection
+ inputRef.current?.focus()
+ }
+
+ function handleInputChange(e: React.ChangeEvent) {
+ onChange(e.target.value)
+ }
+
+ function handleKeyDown(e: React.KeyboardEvent) {
+ // Let cmdk handle arrow keys and enter when popover is open
+ if (open && (e.key === "ArrowDown" || e.key === "ArrowUp")) {
+ // Don't prevent - let the event bubble to Command
+ return
+ }
+ if (e.key === "Escape") {
+ setOpen(false)
+ }
+ }
+
+ return (
+
+
+