mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-27 04:16:06 +00:00
Applications Search Function
This commit is contained in:
parent
fe9fd02b9a
commit
06b422bfe9
@ -114,6 +114,9 @@ export default function Dashboard() {
|
|||||||
const [isGridLayout, setIsGridLayout] = useState<boolean>(false);
|
const [isGridLayout, setIsGridLayout] = useState<boolean>(false);
|
||||||
const [loading, setLoading] = useState<boolean>(true);
|
const [loading, setLoading] = useState<boolean>(true);
|
||||||
|
|
||||||
|
const [searchTerm, setSearchTerm] = useState<string>("");
|
||||||
|
const [isSearching, setIsSearching] = useState<boolean>(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const savedLayout = Cookies.get("layoutPreference-app");
|
const savedLayout = Cookies.get("layoutPreference-app");
|
||||||
const layout_bool = savedLayout === "grid";
|
const layout_bool = savedLayout === "grid";
|
||||||
@ -211,6 +214,34 @@ export default function Dashboard() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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 (
|
return (
|
||||||
<SidebarProvider>
|
<SidebarProvider>
|
||||||
<AppSidebar />
|
<AppSidebar />
|
||||||
@ -352,6 +383,15 @@ export default function Dashboard() {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="flex flex-col gap-2 mb-4 pt-2">
|
||||||
|
<Input
|
||||||
|
id="application-search"
|
||||||
|
placeholder="Type to search..."
|
||||||
|
value={searchTerm}
|
||||||
|
onChange={(e) => setSearchTerm(e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
{!loading ? (
|
{!loading ? (
|
||||||
<div
|
<div
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user