Skip to content

Commit

Permalink
remove code for capturing the browser window for thumbnail
Browse files Browse the repository at this point in the history
  • Loading branch information
Merkie committed Aug 26, 2024
1 parent edf96e2 commit 788d85f
Showing 1 changed file with 1 addition and 46 deletions.
47 changes: 1 addition & 46 deletions src/routes/app/project/[projectId]/[pageId]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,10 @@
import EditPageModal from '$components/modals/EditPageModal.svelte';
import CreatePageModal from '$components/modals/CreatePageModal.svelte';
import UnsavedChangesModal from '$components/modals/UnsavedChangesModal.svelte';
import { onMount } from 'svelte';
import * as htmlToImage from 'html-to-image';
import { uploadFile } from '$ts/client/presigned-uploads.js';
import { invalidateAll } from '$app/navigation';
import api from '$ts/client/api/index.js';
export let data;
let containerHeight: number; // Needed for CSS tricks
let containerElement: HTMLElement;
$: organizedTiles = (() => {
const newTiles = data.page.tiles!.reduce((acc: Tile[][], tile: Tile) => {
Expand All @@ -40,41 +34,6 @@
return newTiles;
})();
onMount(() => {
if (data.projectId) $LocalSettings.lastVisitedProjectId = data.projectId;
const captureContainer = async () => {
// allow page to render
await new Promise((resolve) => setTimeout(resolve, 3000));
const dataUrl = await htmlToImage.toPng(containerElement, {
quality: 1
});
// Convert data URL to Blob
const response = await fetch(dataUrl);
const blob = await response.blob();
const file = new File([blob], `${data.page.name}.png`, { type: 'image/png' });
const key = await uploadFile(file);
if (data.projectId && key) {
await api.project.edit(data.projectId, {
imageUrl: `/${key}`
});
await invalidateAll();
}
};
// if the project hasn't been updated in the last 2 minutes, update the image
if (
data.project.updatedAt &&
Date.now() - new Date(data.project.updatedAt).getTime() > 2 * 60 * 1000
) {
captureContainer();
}
});
</script>

<svelte:head>
Expand All @@ -85,11 +44,7 @@

{#if !$EditingTiles && $LocalSettings.sentenceBuilder}<SentenceBuilder />{/if}

<div
bind:this={containerElement}
bind:clientHeight={containerHeight}
class="relative flex-1 bg-zinc-100"
>
<div bind:clientHeight={containerHeight} class="relative flex-1 bg-zinc-100">
<div
class="absolute overflow-auto"
style={`height: ${containerHeight}px; width: ${
Expand Down

0 comments on commit 788d85f

Please sign in to comment.