"use client";
import { useQuery } from "@tanstack/react-query";
import api from "@/lib/api";
import type { App, Category } from "@/lib/types";
import { useAuthStore } from "@/stores/auth";
import { AppCard } from "@/components/app-card/app-card";
import { Skeleton } from "@/components/ui/skeleton";
import { Badge } from "@/components/ui/badge";
import Link from "next/link";
import { useSearchParams } from "next/navigation";
import { Sparkles, LayoutGrid } from "lucide-react";
import type { LucideIcon } from "lucide-react";
function SectionHeader({
title,
icon: Icon,
href,
}: {
title: string;
icon?: LucideIcon;
href?: string;
}) {
return (
{Icon && }
{title}
{href && (
查看全部 →
)}
);
}
function AppGridSkeleton({ count = 4 }: { count?: number }) {
return (
{Array.from({ length: count }).map((_, i) => (
))}
);
}
export default function StorePage() {
const searchParams = useSearchParams();
const query = searchParams.get("q") || "";
const { user } = useAuthStore();
const orgId = user?.org_id || "";
const orgParam = orgId ? `org_id=${orgId}` : "";
const { data: categories } = useQuery({
queryKey: ["categories", orgId],
queryFn: () => api.get(`/api/v1/store/categories?${orgParam}`),
});
const { data: featured, isLoading: featuredLoading } = useQuery({
queryKey: ["featured", orgId],
queryFn: () => api.get(`/api/v1/store/featured?${orgParam}`),
enabled: !query,
});
const { data: topApps, isLoading: topLoading } = useQuery({
queryKey: ["topApps", orgId],
queryFn: () => api.get(`/api/v1/store/rankings?${orgParam}`),
enabled: !query,
});
const { data: searchResults, isLoading: searchLoading } = useQuery({
queryKey: ["search", query, orgId],
queryFn: () => api.get<{ items: App[] }>(`/api/v1/store/apps?q=${encodeURIComponent(query)}&${orgParam}`),
enabled: !!query,
});
if (query) {
return (
搜索结果:“{query}”
{searchLoading ? (
) : searchResults?.items?.length ? (
{searchResults.items.map((app) => (
))}
) : (
未找到相关政务应用
)}
);
}
return (
{/* Featured */}
{featuredLoading ? (
) : (
{featured?.map((app) => (
))}
)}
{/* Categories */}
全部
{categories?.map((cat) => (
{cat.name}
{cat.app_count != null && cat.app_count > 0 && (
{cat.app_count}
)}
))}
{/* All Apps */}
{topLoading ? (
) : (
{topApps?.map((app) => (
))}
)}
);
}