Spaces:
Build error
Build error
Commit ·
75d68a7
1
Parent(s): fd73f4a
Create src/components/grabber/SearchBar.tsx (#6)
Browse files- Create src/components/grabber/SearchBar.tsx (0b7668848ec33a1f7d4227c721798fd8a95f26d7)
src/components/grabber/SearchBar.tsx
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useState } from 'react';
|
| 2 |
+
import { Button } from '@/components/ui/button';
|
| 3 |
+
import { Input } from '@/components/ui/input';
|
| 4 |
+
import { searchPosts } from '../../lib/grabber/search.functions';
|
| 5 |
+
|
| 6 |
+
export function SearchBar({ onResults }: { onResults: (posts: any[]) => void }) {
|
| 7 |
+
const [tags, setTags] = useState('');
|
| 8 |
+
const [page, setPage] = useState(1);
|
| 9 |
+
const [limit, setLimit] = useState(40);
|
| 10 |
+
const [loading, setLoading] = useState(false);
|
| 11 |
+
|
| 12 |
+
const handleSearch = async () => {
|
| 13 |
+
setLoading(true);
|
| 14 |
+
const result = await searchPosts({ siteId: 'e621', tags, page, limit });
|
| 15 |
+
if (result.posts) onResults(result.posts);
|
| 16 |
+
setLoading(false);
|
| 17 |
+
};
|
| 18 |
+
|
| 19 |
+
return (
|
| 20 |
+
<div className="flex flex-wrap gap-4 items-center p-4 border rounded-lg bg-card">
|
| 21 |
+
<Input placeholder="rating:safe fluffy ..." value={tags} onChange={(e) => setTags(e.target.value)} />
|
| 22 |
+
<Input type="number" className="w-20" value={limit} onChange={(e) => setLimit(Number(e.target.value))} />
|
| 23 |
+
<Button onClick={handleSearch} disabled={loading}>
|
| 24 |
+
{loading ? 'Searching...' : 'Search'}
|
| 25 |
+
</Button>
|
| 26 |
+
</div>
|
| 27 |
+
);
|
| 28 |
+
}
|