2025-08-04 17:45:44 +02:00
|
|
|
import { AllegatoIframe } from "~/components/allegato-iframe";
|
2025-08-28 18:27:07 +02:00
|
|
|
import { LoadingPage } from "~/components/loading";
|
2025-08-04 17:45:44 +02:00
|
|
|
import { Button } from "~/components/ui/button";
|
|
|
|
|
import { handleDownload } from "~/hooks/filesHooks";
|
2025-08-13 17:29:26 +02:00
|
|
|
import { useTranslation } from "~/providers/I18nProvider";
|
2025-08-28 18:27:07 +02:00
|
|
|
import type { StorageindexId } from "~/schemas/public/Storageindex";
|
|
|
|
|
import { api } from "~/utils/api";
|
2025-08-04 17:45:44 +02:00
|
|
|
|
|
|
|
|
export const FileSection = ({ storageId }: { storageId: StorageindexId }) => {
|
2025-08-28 18:27:07 +02:00
|
|
|
const { data: fileInfos, isLoading } = api.storage.getStorageFromId.useQuery({
|
|
|
|
|
storageId,
|
|
|
|
|
});
|
|
|
|
|
const { mutateAsync: getToken } = api.storage.getStorageToken.useMutation();
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
if (isLoading) return <LoadingPage />;
|
|
|
|
|
if (!fileInfos) return <p>{t.file_section.error}</p>;
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<AllegatoIframe
|
|
|
|
|
allegato={fileInfos.id + fileInfos.ext}
|
|
|
|
|
className="h-full max-h-[70vh] min-h-[60vh]"
|
|
|
|
|
/>
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-28 18:27:07 +02:00
|
|
|
<Button
|
2025-08-29 16:18:32 +02:00
|
|
|
className="underline underline-offset-1 after:content-['_↗']"
|
2025-08-28 18:27:07 +02:00
|
|
|
onClick={() =>
|
|
|
|
|
handleDownload({
|
|
|
|
|
file: fileInfos,
|
|
|
|
|
getToken: async () => await getToken(),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
variant="link"
|
|
|
|
|
>
|
|
|
|
|
{t.file_section.download}
|
|
|
|
|
</Button>
|
|
|
|
|
</>
|
|
|
|
|
);
|
2025-08-04 17:45:44 +02:00
|
|
|
};
|