mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-05-19 16:13:19 +00:00
add frontend for search
This commit is contained in:
parent
cf5fd1d6c9
commit
0f15ae198f
1 changed files with 56 additions and 0 deletions
56
graphite-demo/frontend.jsx
Normal file
56
graphite-demo/frontend.jsx
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import React, { useEffect, useState } from 'react';
|
||||
|
||||
const TaskSearch = () => {
|
||||
const [tasks, setTasks] = useState([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState(null);
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
setLoading(true);
|
||||
fetch(`/search?query=${encodeURIComponent(searchQuery)}`)
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok');
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
setTasks(data);
|
||||
setLoading(false);
|
||||
})
|
||||
.catch(error => {
|
||||
setError(error.message);
|
||||
setLoading(false);
|
||||
});
|
||||
}, [searchQuery]); // Depend on searchQuery
|
||||
|
||||
if (loading) {
|
||||
return <div>Loading...</div>;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return <div>Error: {error}</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h2>Task Search</h2>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search tasks..."
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
/>
|
||||
<ul>
|
||||
{tasks.map(task => (
|
||||
<li key={task.id}>
|
||||
<p>{task.description}</p>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default TaskSearch;
|
||||
Loading…
Add table
Add a link
Reference in a new issue