Files
classroomio/apps/website/src/lib/features/tools/progress/download-button.svelte
T

52 lines
1.4 KiB
Svelte
Raw Normal View History

2024-09-30 01:36:12 +01:00
<script lang="ts">
import { toPng } from 'html-to-image';
import { nodeStore, htmlBody, openModal } from './store';
2025-12-20 12:44:59 +01:00
import { Button } from '@cio/ui/base/button';
2024-09-30 01:36:12 +01:00
export let isDisabled: boolean;
export let isDownloading: boolean;
export let text: string = 'Generate Progress Report';
function convertToPng() {
isDownloading = true;
$openModal.showFullscreenButton = false;
const fileName = `${$htmlBody.name} - ${$htmlBody.mood.text} (ClassroomIO_com)`;
if ($nodeStore) {
setTimeout(() => {
toPng($nodeStore, {
width: 500,
height: 500,
quality: 1
})
.then((dataUrl) => {
const link = document.createElement('a');
link.download = fileName;
link.href = dataUrl;
link.click();
})
.catch((error) => {
console.error('Oops, something went wrong!', error);
})
.finally(() => {
isDownloading = false;
2024-10-10 19:24:47 +01:00
$openModal.showFullscreenButton = false;
2024-09-30 01:36:12 +01:00
});
}, 300);
} else {
console.error('Node is not defined');
}
}
</script>
2025-12-20 12:44:59 +01:00
<Button
2024-09-30 01:36:12 +01:00
type="button"
2025-12-20 12:44:59 +01:00
disabled={isDownloading || !isDisabled}
onclick={convertToPng}
loading={isDownloading}
class="{text === 'Generate Progress Report' ? 'block md:hidden' : ''} mt-5 w-full"
2024-09-30 01:36:12 +01:00
>
2025-12-20 12:44:59 +01:00
{isDownloading ? 'Loading...' : text}
</Button>