[llvm-branch-commits] [llvm] Add frontend for search (PR #107210)

Sam Tebbs via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Sep 4 03:05:14 PDT 2024


https://github.com/SamTebbs33 created https://github.com/llvm/llvm-project/pull/107210

None

>From 8296e727435492d4a5b49deea76c098d6f54081f Mon Sep 17 00:00:00 2001
From: Samuel Tebbs <samuel.tebbs at arm.com>
Date: Wed, 4 Sep 2024 11:05:17 +0100
Subject: [PATCH] Add frontend for search

---
 graphite-demo/frontend.jsx | 56 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 graphite-demo/frontend.jsx

diff --git a/graphite-demo/frontend.jsx b/graphite-demo/frontend.jsx
new file mode 100644
index 00000000000000..dd6a2a3ba66cc5
--- /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 <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;
\ No newline at end of file



More information about the llvm-branch-commits mailing list