feat : add searchbar to admin
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
|||||||
PlusIcon,
|
PlusIcon,
|
||||||
RefreshCwIcon,
|
RefreshCwIcon,
|
||||||
RotateCcwIcon,
|
RotateCcwIcon,
|
||||||
|
SearchIcon,
|
||||||
XCircleIcon,
|
XCircleIcon,
|
||||||
Trash2Icon,
|
Trash2Icon,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
@@ -41,6 +42,11 @@ import {
|
|||||||
EmptyHeader,
|
EmptyHeader,
|
||||||
EmptyTitle,
|
EmptyTitle,
|
||||||
} from "@/components/ui/empty";
|
} from "@/components/ui/empty";
|
||||||
|
import {
|
||||||
|
InputGroup,
|
||||||
|
InputGroupAddon,
|
||||||
|
InputGroupInput,
|
||||||
|
} from "@/components/ui/input-group";
|
||||||
import { Spinner } from "@/components/ui/spinner";
|
import { Spinner } from "@/components/ui/spinner";
|
||||||
import { useAdminPresence } from "@/hooks/use-presence";
|
import { useAdminPresence } from "@/hooks/use-presence";
|
||||||
import type { CatalogSyncJob } from "@/lib/catalog/sync";
|
import type { CatalogSyncJob } from "@/lib/catalog/sync";
|
||||||
@@ -71,6 +77,7 @@ export function StructuredDashboard({
|
|||||||
}) {
|
}) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [pending, startTransition] = useTransition();
|
const [pending, startTransition] = useTransition();
|
||||||
|
const [query, setQuery] = useState("");
|
||||||
const [syncJob, setSyncJob] = useState<CatalogSyncJob | null>(null);
|
const [syncJob, setSyncJob] = useState<CatalogSyncJob | null>(null);
|
||||||
const presence = useAdminPresence(null);
|
const presence = useAdminPresence(null);
|
||||||
const catalogReady = Boolean(catalogVersion);
|
const catalogReady = Boolean(catalogVersion);
|
||||||
@@ -81,6 +88,12 @@ export function StructuredDashboard({
|
|||||||
);
|
);
|
||||||
const syncJobId = syncJob?.id;
|
const syncJobId = syncJob?.id;
|
||||||
const syncJobStatus = syncJob?.status;
|
const syncJobStatus = syncJob?.status;
|
||||||
|
const normalizedQuery = query.trim().toLowerCase();
|
||||||
|
const filteredGuides = guides.filter((guide) =>
|
||||||
|
`${guide.name} ${guide.characterKey} ${guide.overview}`
|
||||||
|
.toLowerCase()
|
||||||
|
.includes(normalizedQuery),
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!syncJobId || !syncJobStatus || ["completed", "unchanged", "cancelled", "error"].includes(syncJobStatus)) return;
|
if (!syncJobId || !syncJobStatus || ["completed", "unchanged", "cancelled", "error"].includes(syncJobStatus)) return;
|
||||||
@@ -187,8 +200,21 @@ export function StructuredDashboard({
|
|||||||
</Card>
|
</Card>
|
||||||
) : null}
|
) : null}
|
||||||
{guides.length ? (
|
{guides.length ? (
|
||||||
|
<InputGroup className="h-11 max-w-2xl">
|
||||||
|
<InputGroupAddon>
|
||||||
|
<SearchIcon />
|
||||||
|
</InputGroupAddon>
|
||||||
|
<InputGroupInput
|
||||||
|
value={query}
|
||||||
|
onChange={(event) => setQuery(event.target.value)}
|
||||||
|
placeholder="ค้นหาตัวละคร…"
|
||||||
|
aria-label="ค้นหาตัวละคร"
|
||||||
|
/>
|
||||||
|
</InputGroup>
|
||||||
|
) : null}
|
||||||
|
{filteredGuides.length ? (
|
||||||
<div className="grid gap-5 md:grid-cols-2 xl:grid-cols-3">
|
<div className="grid gap-5 md:grid-cols-2 xl:grid-cols-3">
|
||||||
{guides.map((guide) => (
|
{filteredGuides.map((guide) => (
|
||||||
<Card
|
<Card
|
||||||
key={guide.id}
|
key={guide.id}
|
||||||
className="relative overflow-hidden py-0 transition-colors hover:bg-muted/50"
|
className="relative overflow-hidden py-0 transition-colors hover:bg-muted/50"
|
||||||
@@ -269,6 +295,13 @@ export function StructuredDashboard({
|
|||||||
</Card>
|
</Card>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
) : guides.length ? (
|
||||||
|
<Empty className="border">
|
||||||
|
<EmptyHeader>
|
||||||
|
<EmptyTitle>ไม่พบตัวละคร</EmptyTitle>
|
||||||
|
<EmptyDescription>ลองค้นหาด้วยชื่อตัวละครอื่น</EmptyDescription>
|
||||||
|
</EmptyHeader>
|
||||||
|
</Empty>
|
||||||
) : (
|
) : (
|
||||||
<Empty className="border">
|
<Empty className="border">
|
||||||
<EmptyHeader>
|
<EmptyHeader>
|
||||||
|
|||||||
Reference in New Issue
Block a user