"use client";
import Link from "next/link";
import { ActionButton } from "@/components/ui/action-button";
import ActionConfirmingDialog from "@/components/ui/action-confirming-dialog";
import { Button } from "@/components/ui/button";
import { FullPageSpinner } from "@/components/ui/full-page-spinner";
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
import { toast } from "@/components/ui/use-toast";
import { ASSET_TYPE_TO_ICON } from "@/lib/attachments";
import { useTranslation } from "@/lib/i18n/client";
import { api } from "@/lib/trpc";
import { formatBytes } from "@/lib/utils";
import { ExternalLink, Trash2 } from "lucide-react";
import { useDetachBookmarkAsset } from "@karakeep/shared-react/hooks/assets";
import { getAssetUrl } from "@karakeep/shared/utils/assetUtils";
import {
humanFriendlyNameForAssertType,
isAllowedToDetachAsset,
} from "@karakeep/trpc/lib/attachments";
export default function AssetsSettingsPage() {
const { t } = useTranslation();
const { mutate: detachAsset, isPending: isDetaching } =
useDetachBookmarkAsset({
onSuccess: () => {
toast({
description: "Asset has been deleted!",
});
},
onError: (e) => {
toast({
description: e.message,
variant: "destructive",
});
},
});
const {
data,
isLoading: isAssetsLoading,
fetchNextPage,
hasNextPage,
isFetchingNextPage,
} = api.assets.list.useInfiniteQuery(
{
limit: 20,
},
{
getNextPageParam: (lastPage) => lastPage.nextCursor,
},
);
const assets = data?.pages.flatMap((page) => page.assets) ?? [];
if (isAssetsLoading) {
return
{t("settings.manage_assets.no_assets")}
)} {assets.length > 0 && (