Spaces:
Runtime error
Runtime error
keyboard evens to save and restart
Browse files
frontend/src/lib/Result.svelte
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
import { colors, cheersMessages } from '$lib/utils';
|
| 3 |
import type { Board } from '../types';
|
| 4 |
import { fade } from 'svelte/transition';
|
| 5 |
-
import { createEventDispatcher } from 'svelte';
|
| 6 |
|
| 7 |
const dispatch = createEventDispatcher();
|
| 8 |
|
|
@@ -14,6 +14,7 @@
|
|
| 14 |
import domtoimage from 'dom-to-image';
|
| 15 |
const imageBaseUrl = import.meta.env.MODE === 'development' ? 'http://localhost:7860/' : '';
|
| 16 |
|
|
|
|
| 17 |
let elToShare: HTMLDivElement;
|
| 18 |
let disableDownload: boolean = false;
|
| 19 |
async function saveFile(node: HTMLDivElement) {
|
|
@@ -38,13 +39,24 @@
|
|
| 38 |
console.log(err.name, err.message);
|
| 39 |
}
|
| 40 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
const s = 10;
|
| 42 |
const p = 1;
|
| 43 |
const rx = s / 10;
|
| 44 |
</script>
|
| 45 |
|
| 46 |
<!-- Modal made with tailwind -->
|
| 47 |
-
<div class="modal relative z-2" transition:fade>
|
| 48 |
<div class="message">
|
| 49 |
<div class="border-0">
|
| 50 |
<div class="p-3" bind:this={elToShare}>
|
|
@@ -81,7 +93,11 @@
|
|
| 81 |
</div>
|
| 82 |
</div>
|
| 83 |
<div class="p-3 px-6 flex text-base">
|
| 84 |
-
<button
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
{!disableDownload ? 'SAVE SCREENSHOT' : 'SAVING..'}
|
| 86 |
</button>
|
| 87 |
<button class="flex-1 ml-1" on:click={() => dispatch('restart')}> TRY AGAIN </button>
|
|
|
|
| 2 |
import { colors, cheersMessages } from '$lib/utils';
|
| 3 |
import type { Board } from '../types';
|
| 4 |
import { fade } from 'svelte/transition';
|
| 5 |
+
import { createEventDispatcher, onMount } from 'svelte';
|
| 6 |
|
| 7 |
const dispatch = createEventDispatcher();
|
| 8 |
|
|
|
|
| 14 |
import domtoimage from 'dom-to-image';
|
| 15 |
const imageBaseUrl = import.meta.env.MODE === 'development' ? 'http://localhost:7860/' : '';
|
| 16 |
|
| 17 |
+
let modalEl: HTMLDivElement;
|
| 18 |
let elToShare: HTMLDivElement;
|
| 19 |
let disableDownload: boolean = false;
|
| 20 |
async function saveFile(node: HTMLDivElement) {
|
|
|
|
| 39 |
console.log(err.name, err.message);
|
| 40 |
}
|
| 41 |
}
|
| 42 |
+
const onKeyup = (e: KeyboardEvent) => {
|
| 43 |
+
if (e.key === 'Escape') {
|
| 44 |
+
dispatch('restart');
|
| 45 |
+
} else if (e.key === ' ') {
|
| 46 |
+
saveFile(elToShare);
|
| 47 |
+
}
|
| 48 |
+
};
|
| 49 |
+
onMount(() => {
|
| 50 |
+
window.addEventListener('keyup', onKeyup);
|
| 51 |
+
return () => window.removeEventListener('keyup', onKeyup);
|
| 52 |
+
});
|
| 53 |
const s = 10;
|
| 54 |
const p = 1;
|
| 55 |
const rx = s / 10;
|
| 56 |
</script>
|
| 57 |
|
| 58 |
<!-- Modal made with tailwind -->
|
| 59 |
+
<div bind:this={modalEl} class="modal relative z-2" transition:fade>
|
| 60 |
<div class="message">
|
| 61 |
<div class="border-0">
|
| 62 |
<div class="p-3" bind:this={elToShare}>
|
|
|
|
| 93 |
</div>
|
| 94 |
</div>
|
| 95 |
<div class="p-3 px-6 flex text-base">
|
| 96 |
+
<button
|
| 97 |
+
disabled={disableDownload}
|
| 98 |
+
class="min-w-[15ch] flex-1 mr-1"
|
| 99 |
+
on:click={() => saveFile(elToShare)}
|
| 100 |
+
>
|
| 101 |
{!disableDownload ? 'SAVE SCREENSHOT' : 'SAVING..'}
|
| 102 |
</button>
|
| 103 |
<button class="flex-1 ml-1" on:click={() => dispatch('restart')}> TRY AGAIN </button>
|