diff --git a/graphite-demo/frontend.jsx b/graphite-demo/frontend.jsx new file mode 100644 index 0000000..dd6a2a3 --- /dev/null +++ b/graphite-demo/frontend.jsx @@ -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
Loading...
; + } + + if (error) { + return
Error: {error}
; + } + + return ( +
+

Task Search

+ setSearchQuery(e.target.value)} + /> + +
+ ); +}; + +export default TaskSearch; \ No newline at end of file