-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTopNav.jsx
55 lines (52 loc) · 1.97 KB
/
TopNav.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import React from "react";
import { useState, useEffect } from "react";
import axios from "./axios";
import { Link } from "react-router-dom";
const TopNav = () => {
const [query , setquery] = useState("");
const [searches , setsearches]= useState([]);
const GetSearches = async () =>{
try {
const {data} = await axios.get(`/search/multi?query=${query}`);
console.log(data);
setsearches(data.results);
} catch (error) {
console.log("Error:", error);
}
};
useEffect(() => {
GetSearches();
},[query]);
return (
<div className="w-[80%] h-[10vh] relative flex justify-start items-center ml-[15%]">
<i className ="text-zinc-400 text-3xl ri-search-line"></i>
<input
onChange={(e)=> setquery(e.target.value)}
className="w-[50%] text-zinc-200 mx-10 p-5 text-xl outline-none border-none bg-transparent"
type ="text"
placeholder="Search anything"
/>
{query.length>0 &&(
<i onClick ={() => setquery("")}
class ="text-zinc-400 text-3xl ri-close-fill"></i>
)}
<div className="absolute w-[50%] max-h-[50vh] bg-zinc-100 top-[100%] left-[5%] overflow-auto">
{searches.map((s,i) => (
<Link
key={i}
className="hover:text-black hover:bg-zinc-300 font-semibold
text-zinc-600 inline-block p-10 w-[100%] flex justify-start
items-center border-b-2 border-zinc-100">
<img className="w-[10vh] h-[10vh] object-cover rounded mr-5"
src={`https://image.tmdb.org/t/p/original/${
s.backdrop_path || s.profile_path
}`}
alt=""/>
<span>{s.name || s.title || s.original_name || s.original_title}</span>
</Link>
))}
</div>
</div>
);
};
export default TopNav;