basic search working
This commit is contained in:
29
src/app/(frontend)/_components/DiplomarbeitSearch.tsx
Normal file
29
src/app/(frontend)/_components/DiplomarbeitSearch.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
"use client";
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Input } from '@/components/ui/input';
|
||||
|
||||
export default function DiplomarbeitSearch() {
|
||||
const [search, setSearch] = useState('');
|
||||
const [results, setResults] = useState<string[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
const timeoutId = setTimeout(async () => {
|
||||
const response = await fetch(`/api/diplomarbeiten?search=${search}`);
|
||||
const data = await response.json();
|
||||
setResults(data.titles || []);
|
||||
}, 500); // 500ms cooldown period
|
||||
|
||||
return () => clearTimeout(timeoutId);
|
||||
}, [search]);
|
||||
|
||||
return (
|
||||
<div className="w-full">
|
||||
<Input type="text" value={search} placeholder="Suche" onChange={(e) => setSearch(e.target.value)} className="w-full" />
|
||||
{results.map((title, index) => (
|
||||
<div key={index}>
|
||||
<h2>{title}</h2>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user