37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
import { useState } from 'react';
|
|
import { useNavigate } from 'react-router-dom';
|
|
|
|
|
|
|
|
const ResearchBar = () => {
|
|
|
|
const navigate = useNavigate();
|
|
const [value, setValue] = useState("");
|
|
|
|
const search = async (query) => {
|
|
const results = await fetchData(query, false);
|
|
console.log(results);
|
|
navigate('/morceaux', { state: { searchResults: results } });
|
|
}
|
|
|
|
const fetchData = async (query, preview) => {
|
|
const response = await fetch(`https://localhost:7292/api/Search?query=${query}&preview=${preview}&deep=true`);
|
|
const json = await response.json();
|
|
return { json };
|
|
}
|
|
|
|
const handleValueChange = async (value) => {
|
|
setValue(value);
|
|
}
|
|
|
|
return (
|
|
<div className="research-container">
|
|
<input className="research-input" value={value} onChange={(e) => handleValueChange(e.target.value)} placeholder="Rechercher..."></input>
|
|
<button className="research-btn" onClick={() => search(value)}>
|
|
<div className="fa fa-search" />
|
|
</button>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default ResearchBar; |