Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions apps/admin/app/dashboard/catalog/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,17 @@ export default function CatalogPage() {
const q = searchParams?.get('q') ?? undefined;

const {
data: items = [],
data: result,
isLoading,
isError,
} = useQuery({
queryKey: queryKeys.admin.catalog(q),
queryFn: () => getCatalogItems({ q }),
});

const items = result?.data ?? [];
const total = result?.total ?? 0;

return (
<div>
<div className="mb-6">
Expand Down Expand Up @@ -174,7 +177,8 @@ export default function CatalogPage() {
</Table>
</div>
<p className="text-xs text-muted-foreground">
{items.length.toLocaleString()} item{items.length !== 1 ? 's' : ''}
{items.length.toLocaleString()} of {total.toLocaleString()} item
{total !== 1 ? 's' : ''}
{q ? ` matching "${q}"` : ''}
</p>
</>
Expand Down
59 changes: 44 additions & 15 deletions apps/admin/app/dashboard/packs/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import { SearchInput } from 'admin-app/components/search-input';
import { type AdminPack, deletePack, getPacks } from 'admin-app/lib/api';
import { formatDate } from 'admin-app/lib/date';
import { queryKeys } from 'admin-app/lib/queryKeys';
import { cn } from 'admin-app/lib/utils';
import { useSearchParams } from 'next/navigation';
import { useState } from 'react';

function TableSkeleton() {
return (
Expand All @@ -41,22 +43,28 @@ function TableSkeleton() {

function PackRow({ pack }: { pack: AdminPack }) {
const queryClient = useQueryClient();
const isDeleted = pack.deleted;

const { mutateAsync: handleDelete } = useMutation({
mutationFn: () => deletePack(pack.id),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: queryKeys.admin.packs() });
queryClient.invalidateQueries({ queryKey: ['admin', 'packs'] });
},
});
Comment on lines 48 to 53
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The invalidateQueries key here uses queryKeys.admin.packs() (=> ['admin','packs', undefined]) but the list query is keyed by queryKeys.admin.packs(q) (and should also include includeDeleted). As written, the cache invalidation may not refresh the list the user is viewing. Invalidate using a stable prefix like ['admin','packs'], and include includeDeleted in the list query key.

Copilot uses AI. Check for mistakes.

return (
<TableRow className="hover:bg-muted/20">
<TableRow className={cn('hover:bg-muted/20', isDeleted && 'opacity-50')}>
<TableCell>
<div>
<p className="text-sm font-medium">{pack.name}</p>
{pack.description && (
<p className="text-xs text-muted-foreground line-clamp-1">{pack.description}</p>
)}
{isDeleted && (
<p className="text-xs text-destructive">
Deleted {pack.deletedAt ? formatDate(new Date(pack.deletedAt)) : ''}
</p>
)}
</div>
</TableCell>
<TableCell>
Expand All @@ -69,7 +77,10 @@ function PackRow({ pack }: { pack: AdminPack }) {
</TableCell>
<TableCell>
<span
className={`text-xs font-medium ${pack.isPublic ? 'text-green-500' : 'text-muted-foreground'}`}
className={cn(
'text-xs font-medium',
pack.isPublic ? 'text-green-500' : 'text-muted-foreground',
)}
>
{pack.isPublic ? 'Public' : 'Private'}
</span>
Expand All @@ -80,13 +91,15 @@ function PackRow({ pack }: { pack: AdminPack }) {
</span>
</TableCell>
<TableCell>
<DeleteButton
label={pack.name}
description="The pack will be soft-deleted and hidden from all users."
onConfirm={async () => {
await handleDelete();
}}
/>
{!isDeleted && (
<DeleteButton
label={pack.name}
description="The pack will be soft-deleted and hidden from all users."
onConfirm={async () => {
await handleDelete();
}}
/>
)}
</TableCell>
</TableRow>
);
Expand All @@ -95,16 +108,20 @@ function PackRow({ pack }: { pack: AdminPack }) {
export default function PacksPage() {
const searchParams = useSearchParams();
const q = searchParams?.get('q') ?? undefined;
const [includeDeleted, setIncludeDeleted] = useState(false);

const {
data: packs = [],
data: result,
isLoading,
isError,
} = useQuery({
queryKey: queryKeys.admin.packs(q),
queryFn: () => getPacks({ q }),
queryKey: [...queryKeys.admin.packs(q), { includeDeleted }],
queryFn: () => getPacks({ q, includeDeleted }),
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.

const packs = result?.data ?? [];
const total = result?.total ?? 0;

return (
<div>
<div className="mb-6">
Expand All @@ -114,7 +131,18 @@ export default function PacksPage() {
</p>
</div>
<div className="space-y-4">
<SearchInput placeholder="Search by name, owner, or category…" />
<div className="flex items-center gap-4">
<SearchInput placeholder="Search by name, owner, or category…" />
<label className="flex items-center gap-2 text-sm text-muted-foreground cursor-pointer select-none">
<input
type="checkbox"
checked={includeDeleted}
onChange={(e) => setIncludeDeleted(e.target.checked)}
className="rounded"
/>
Show deleted
</label>
</div>
{isError ? (
<p className="text-sm text-destructive py-4">
Failed to load packs. Check that the API is reachable.
Expand Down Expand Up @@ -159,7 +187,8 @@ export default function PacksPage() {
</Table>
</div>
<p className="text-xs text-muted-foreground">
{packs.length.toLocaleString()} pack{packs.length !== 1 ? 's' : ''}
{packs.length.toLocaleString()} of {total.toLocaleString()} pack
{total !== 1 ? 's' : ''}
{q ? ` matching "${q}"` : ''}
</p>
</>
Expand Down
10 changes: 7 additions & 3 deletions apps/admin/app/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,25 @@ export default function DashboardPage() {
queryFn: getStats,
});

const { data: users = [], isLoading: usersLoading } = useQuery({
const { data: usersResult, isLoading: usersLoading } = useQuery({
queryKey: queryKeys.admin.users(5),
queryFn: () => getUsers({ limit: 5 }),
});

const { data: packs = [], isLoading: packsLoading } = useQuery({
const { data: packsResult, isLoading: packsLoading } = useQuery({
queryKey: queryKeys.admin.packs(5),
queryFn: () => getPacks({ limit: 5 }),
});

const { data: catalog = [], isLoading: catalogLoading } = useQuery({
const { data: catalogResult, isLoading: catalogLoading } = useQuery({
queryKey: queryKeys.admin.catalog(5),
queryFn: () => getCatalogItems({ limit: 5 }),
});

const users = usersResult?.data ?? [];
const packs = packsResult?.data ?? [];
const catalog = catalogResult?.data ?? [];

const isLoading = statsLoading || usersLoading || packsLoading || catalogLoading;
const isError = !isLoading && !stats;

Expand Down
Loading
Loading