Spaces:
Running
Running
Commit
·
f78ec48
1
Parent(s):
b8c4528
bugfix
Browse files
src/app/interface/search-input/index.tsx
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import { useState, useTransition } from "react"
|
2 |
import Link from "next/link"
|
3 |
// import throttle from "@jcoreio/async-throttle"
|
4 |
import debounce from "lodash.debounce"
|
@@ -24,6 +24,9 @@ export function SearchInput() {
|
|
24 |
|
25 |
const [searchDraft, setSearchDraft] = useState("")
|
26 |
|
|
|
|
|
|
|
27 |
// called when pressing enter or clicking on search
|
28 |
const debouncedSearch = debounce((query: string) => {
|
29 |
startTransition(async () => {
|
@@ -43,10 +46,11 @@ export function SearchInput() {
|
|
43 |
// TODO: only close the show autocomplete box if we found something
|
44 |
// setShowAutocompleteBox(false)
|
45 |
})
|
46 |
-
},
|
47 |
|
48 |
// called when pressing enter or clicking on search
|
49 |
const handleSearch = () => {
|
|
|
50 |
setSearchQuery(searchDraft)
|
51 |
setShowAutocompleteBox(true)
|
52 |
debouncedSearch(searchDraft)
|
@@ -55,19 +59,20 @@ export function SearchInput() {
|
|
55 |
return (
|
56 |
<div className="flex flex-row flex-grow w-[380px] lg:w-[600px]">
|
57 |
|
58 |
-
<div className="flex flex-row w-full"
|
59 |
-
onClick={() => {
|
60 |
-
handleSearch()
|
61 |
-
}}>
|
62 |
<Input
|
|
|
63 |
placeholder="Search"
|
64 |
className={cn(
|
65 |
`bg-neutral-900 text-neutral-200 dark:bg-neutral-900 dark:text-neutral-200`,
|
66 |
`rounded-l-full rounded-r-none`,
|
|
|
|
|
|
|
|
|
67 |
`border-neutral-700 dark:border-neutral-700 border-r-0`,
|
68 |
|
69 |
)}
|
70 |
-
// disabled={atLeastOnePanelIsBusy}
|
71 |
onFocus={() => {
|
72 |
handleSearch()
|
73 |
}}
|
@@ -76,7 +81,8 @@ export function SearchInput() {
|
|
76 |
}}
|
77 |
onChange={(e) => {
|
78 |
setSearchDraft(e.target.value)
|
79 |
-
|
|
|
80 |
}}
|
81 |
onKeyDown={({ key }) => {
|
82 |
if (key === 'Enter') {
|
@@ -117,11 +123,11 @@ export function SearchInput() {
|
|
117 |
|
118 |
`transition-all duration-200 ease-in-out`,
|
119 |
showAutocompleteBox
|
120 |
-
? `opacity-100 scale-100 mt-11`
|
121 |
-
: `opacity-0 scale-95 mt-6`
|
122 |
)}
|
123 |
>
|
124 |
-
{searchAutocompleteResults.length === 0 ? <div>
|
125 |
{searchAutocompleteResults.map(media => (
|
126 |
<Link key={media.id} href={`/watch?v=${media.id}`}>
|
127 |
<div
|
|
|
1 |
+
import { useRef, useState, useTransition } from "react"
|
2 |
import Link from "next/link"
|
3 |
// import throttle from "@jcoreio/async-throttle"
|
4 |
import debounce from "lodash.debounce"
|
|
|
24 |
|
25 |
const [searchDraft, setSearchDraft] = useState("")
|
26 |
|
27 |
+
const ref = useRef<HTMLInputElement>(null)
|
28 |
+
|
29 |
+
|
30 |
// called when pressing enter or clicking on search
|
31 |
const debouncedSearch = debounce((query: string) => {
|
32 |
startTransition(async () => {
|
|
|
46 |
// TODO: only close the show autocomplete box if we found something
|
47 |
// setShowAutocompleteBox(false)
|
48 |
})
|
49 |
+
}, 500)
|
50 |
|
51 |
// called when pressing enter or clicking on search
|
52 |
const handleSearch = () => {
|
53 |
+
ref.current?.focus()
|
54 |
setSearchQuery(searchDraft)
|
55 |
setShowAutocompleteBox(true)
|
56 |
debouncedSearch(searchDraft)
|
|
|
59 |
return (
|
60 |
<div className="flex flex-row flex-grow w-[380px] lg:w-[600px]">
|
61 |
|
62 |
+
<div className="flex flex-row w-full">
|
|
|
|
|
|
|
63 |
<Input
|
64 |
+
ref={ref}
|
65 |
placeholder="Search"
|
66 |
className={cn(
|
67 |
`bg-neutral-900 text-neutral-200 dark:bg-neutral-900 dark:text-neutral-200`,
|
68 |
`rounded-l-full rounded-r-none`,
|
69 |
+
|
70 |
+
// we increase the line height to better catch the clicks
|
71 |
+
`py-0 h-10 leading-7`,
|
72 |
+
|
73 |
`border-neutral-700 dark:border-neutral-700 border-r-0`,
|
74 |
|
75 |
)}
|
|
|
76 |
onFocus={() => {
|
77 |
handleSearch()
|
78 |
}}
|
|
|
81 |
}}
|
82 |
onChange={(e) => {
|
83 |
setSearchDraft(e.target.value)
|
84 |
+
setShowAutocompleteBox(true)
|
85 |
+
// handleSearch()
|
86 |
}}
|
87 |
onKeyDown={({ key }) => {
|
88 |
if (key === 'Enter') {
|
|
|
123 |
|
124 |
`transition-all duration-200 ease-in-out`,
|
125 |
showAutocompleteBox
|
126 |
+
? `opacity-100 scale-100 mt-11 pointer-events-auto`
|
127 |
+
: `opacity-0 scale-95 mt-6 pointer-events-none`
|
128 |
)}
|
129 |
>
|
130 |
+
{searchAutocompleteResults.length === 0 ? <div>Nothing to show, type something and press enter</div> : null}
|
131 |
{searchAutocompleteResults.map(media => (
|
132 |
<Link key={media.id} href={`/watch?v=${media.id}`}>
|
133 |
<div
|