diff --git a/app/dashboard/applications/Applications.tsx b/app/dashboard/applications/Applications.tsx index 119198b..62c1fb9 100644 --- a/app/dashboard/applications/Applications.tsx +++ b/app/dashboard/applications/Applications.tsx @@ -114,6 +114,9 @@ export default function Dashboard() { const [isGridLayout, setIsGridLayout] = useState(false); const [loading, setLoading] = useState(true); + const [searchTerm, setSearchTerm] = useState(""); + const [isSearching, setIsSearching] = useState(false); + useEffect(() => { const savedLayout = Cookies.get("layoutPreference-app"); const layout_bool = savedLayout === "grid"; @@ -210,6 +213,34 @@ export default function Dashboard() { console.log(error.response.data); } }; + + const searchApplications = async () => { + try { + setIsSearching(true); + const response = await axios.post<{ results: Application[] }>( + "/api/applications/search", + { searchterm: searchTerm } + ); + setApplications(response.data.results); + setIsSearching(false); + } catch (error: any) { + console.error("Search error:", error.response?.data); + setIsSearching(false); + } + }; + + useEffect(() => { + const delayDebounce = setTimeout(() => { + if (searchTerm.trim() === "") { + getApplications(); + } else { + searchApplications(); + } + }, 300); + + return () => clearTimeout(delayDebounce); + }, [searchTerm]); + return ( @@ -352,6 +383,15 @@ export default function Dashboard() { )} +
+ setSearchTerm(e.target.value)} + /> +
+
{!loading ? (