Spaces:
Running
Running
update UI
Browse files- components/spaces/index.tsx +42 -20
components/spaces/index.tsx
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
"use client";
|
| 2 |
-
import { useEffect, useState } from "react";
|
| 3 |
import { useRouter } from "next/navigation";
|
| 4 |
import { useTheme } from "next-themes";
|
| 5 |
-
import { MdDarkMode, MdLightMode } from "react-icons/md";
|
| 6 |
|
| 7 |
import { SpaceProps } from "@/utils/type";
|
| 8 |
import { SpaceIcon } from "@/components/space_icon";
|
|
@@ -21,7 +21,6 @@ export const Spaces: React.FC<{ spaces: SpaceProps[] }> = ({ spaces }) => {
|
|
| 21 |
useEffect(() => {
|
| 22 |
router.push("/?sort=" + sort);
|
| 23 |
}, [sort, router]);
|
| 24 |
-
|
| 25 |
|
| 26 |
const handleSelectGpu = (gpu: string) => {
|
| 27 |
if (selectedGpu === gpu) {
|
|
@@ -31,13 +30,17 @@ export const Spaces: React.FC<{ spaces: SpaceProps[] }> = ({ spaces }) => {
|
|
| 31 |
setSelectedGpu(gpu);
|
| 32 |
};
|
| 33 |
|
| 34 |
-
const filteredSpaces =
|
| 35 |
-
|
|
|
|
|
|
|
| 36 |
space.title?.toLowerCase().includes(searchQuery.trim().toLowerCase()) ||
|
| 37 |
-
space.authorData?.name
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
return (
|
| 42 |
<section className="flex h-screen overflow-auto">
|
| 43 |
<div className="w-full container px-6 py-10 lg:py-20 mx-auto space-y-10 lg:space-y-14">
|
|
@@ -68,18 +71,37 @@ export const Spaces: React.FC<{ spaces: SpaceProps[] }> = ({ spaces }) => {
|
|
| 68 |
Discover spaces with zero GPU usage on 🤗 Hugging Face Spaces.
|
| 69 |
</p>
|
| 70 |
</div>
|
| 71 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
</header>
|
| 73 |
-
<div className="flex items-center justify-between mb-4">
|
| 74 |
-
<input
|
| 75 |
-
type="text"
|
| 76 |
-
placeholder="Search spaces..."
|
| 77 |
-
className="w-full rounded-md border border-gray-300 dark:border-slate-700 bg-white dark:bg-slate-800 text-gray-700 dark:text-slate-200 px-4 py-2 focus:outline-none focus:ring-2 focus:ring-purple-600 dark:focus:ring-purple-400"
|
| 78 |
-
value={searchQuery}
|
| 79 |
-
onChange={(e) => setSearchQuery(e.target.value)}
|
| 80 |
-
/>
|
| 81 |
-
</div>
|
| 82 |
<div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4 pb-10">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
{filteredSpaces?.map((space: SpaceProps) => (
|
| 84 |
<Space
|
| 85 |
key={space.id}
|
|
@@ -92,4 +114,4 @@ export const Spaces: React.FC<{ spaces: SpaceProps[] }> = ({ spaces }) => {
|
|
| 92 |
</div>
|
| 93 |
</section>
|
| 94 |
);
|
| 95 |
-
};
|
|
|
|
| 1 |
"use client";
|
| 2 |
+
import { useEffect, useMemo, useState } from "react";
|
| 3 |
import { useRouter } from "next/navigation";
|
| 4 |
import { useTheme } from "next-themes";
|
| 5 |
+
import { MdDarkMode, MdLightMode, MdSearch } from "react-icons/md";
|
| 6 |
|
| 7 |
import { SpaceProps } from "@/utils/type";
|
| 8 |
import { SpaceIcon } from "@/components/space_icon";
|
|
|
|
| 21 |
useEffect(() => {
|
| 22 |
router.push("/?sort=" + sort);
|
| 23 |
}, [sort, router]);
|
|
|
|
| 24 |
|
| 25 |
const handleSelectGpu = (gpu: string) => {
|
| 26 |
if (selectedGpu === gpu) {
|
|
|
|
| 30 |
setSelectedGpu(gpu);
|
| 31 |
};
|
| 32 |
|
| 33 |
+
const filteredSpaces = useMemo(() => {
|
| 34 |
+
if (!searchQuery) return spaces;
|
| 35 |
+
return spaces.filter(
|
| 36 |
+
(space) =>
|
| 37 |
space.title?.toLowerCase().includes(searchQuery.trim().toLowerCase()) ||
|
| 38 |
+
space.authorData?.name
|
| 39 |
+
?.toLowerCase()
|
| 40 |
+
.includes(searchQuery.trim().toLowerCase())
|
| 41 |
+
);
|
| 42 |
+
}, [spaces, searchQuery]);
|
| 43 |
+
|
| 44 |
return (
|
| 45 |
<section className="flex h-screen overflow-auto">
|
| 46 |
<div className="w-full container px-6 py-10 lg:py-20 mx-auto space-y-10 lg:space-y-14">
|
|
|
|
| 71 |
Discover spaces with zero GPU usage on 🤗 Hugging Face Spaces.
|
| 72 |
</p>
|
| 73 |
</div>
|
| 74 |
+
<div className="flex items-center justify-end gap-2">
|
| 75 |
+
<div className="relative">
|
| 76 |
+
<MdSearch className="absolute left-2.5 top-2.5 w-5 h-5 text-gray-600 dark:text-slate-400 z-[1]" />
|
| 77 |
+
<input
|
| 78 |
+
type="text"
|
| 79 |
+
placeholder="Search spaces..."
|
| 80 |
+
className="border-[3px] text-gray-600 dark:text-slate-300 text-sm rounded-full outline-none border-gray-50 drop-shadow-sm bg-white dark:bg-slate-900 dark:border-slate-800 ring-[1px] ring-gray-200 dark:ring-slate-700 px-2.5 pl-8 py-1.5"
|
| 81 |
+
value={searchQuery}
|
| 82 |
+
onChange={(e) => setSearchQuery(e.target.value)}
|
| 83 |
+
/>
|
| 84 |
+
</div>
|
| 85 |
+
<Sort value={sort} onChange={setSort} />
|
| 86 |
+
</div>
|
| 87 |
</header>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
<div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4 pb-10">
|
| 89 |
+
{filteredSpaces.length === 0 && (
|
| 90 |
+
<div className="col-span-full flex items-center flex-col justify-center gap-2">
|
| 91 |
+
<p className="text-neutral-500 font-regular text-base dark:text-slate-300">
|
| 92 |
+
No spaces found.
|
| 93 |
+
</p>
|
| 94 |
+
<button
|
| 95 |
+
className="text-sm text-gray-500 underline dark:text-slate-500"
|
| 96 |
+
onClick={() => {
|
| 97 |
+
setSearchQuery("");
|
| 98 |
+
setSelectedGpu(undefined);
|
| 99 |
+
}}
|
| 100 |
+
>
|
| 101 |
+
Reset filters
|
| 102 |
+
</button>
|
| 103 |
+
</div>
|
| 104 |
+
)}
|
| 105 |
{filteredSpaces?.map((space: SpaceProps) => (
|
| 106 |
<Space
|
| 107 |
key={space.id}
|
|
|
|
| 114 |
</div>
|
| 115 |
</section>
|
| 116 |
);
|
| 117 |
+
};
|