Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
- Created backend/Dockerfile for Express API server - Created frontend/Dockerfile with Nginx for static files - Added nginx.conf to proxy /api/* to backend - Created docker-compose.microservices.yml for multi-container setup - Added .dockerignore files for both frontend and backend - Updated .woodpecker.yaml to fix registry URL and use separate Dockerfiles - Added CORS support to backend for microservices mode - Updated README with dual-mode deployment instructions - Frontend copies to frontend/public/ for Nginx serving - CI/CD pipeline now builds separate images for frontend and backend
46 lines
1.0 KiB
JavaScript
46 lines
1.0 KiB
JavaScript
import { useState, useEffect } from 'react';
|
|
|
|
function Search() {
|
|
const [query, setQuery] = useState('');
|
|
const [results, setResults] = useState([]);
|
|
|
|
useEffect(() => {
|
|
if (query.trim() === '') {
|
|
setResults([]);
|
|
return;
|
|
}
|
|
|
|
const fetchSuggestions = async () => {
|
|
try {
|
|
const res = await fetch(`/search?q=${encodeURIComponent(query)}`);
|
|
const data = await res.json();
|
|
setResults(data);
|
|
} catch (err) {
|
|
console.error('Failed to fetch suggestions:', err);
|
|
}
|
|
};
|
|
|
|
fetchSuggestions();
|
|
}, [query]);
|
|
|
|
return (
|
|
<div className="search-container">
|
|
<input
|
|
type="text"
|
|
placeholder="Search..."
|
|
value={query}
|
|
onChange={e => setQuery(e.target.value)}
|
|
/>
|
|
{results.length > 0 && (
|
|
<div className="autocomplete-box">
|
|
{results.map((res, i) => (
|
|
<div key={i} className="suggestion">{res}</div>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default Search;
|