Spaces:
Runtime error
Runtime error
fix mobile resuts componenent
Browse files- frontend/src/lib/Result.svelte +12 -13
- frontend/src/lib/utils.ts +3 -1
- frontend/src/routes/index.svelte +3 -7
frontend/src/lib/Result.svelte
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
<script lang="ts">
|
2 |
-
import { colors } from '$lib/utils';
|
3 |
import type { Board } from '../types';
|
4 |
import { fade } from 'svelte/transition';
|
5 |
-
export let message: string | null = null;
|
6 |
export let board: Board;
|
7 |
export let currentRowIndex: number;
|
8 |
export let imagePaths: string[];
|
9 |
|
|
|
10 |
import domtoimage from 'dom-to-image';
|
11 |
const imageBaseUrl = import.meta.env.MODE === 'development' ? 'http://localhost:7860/' : '';
|
12 |
|
@@ -20,8 +20,7 @@
|
|
20 |
try {
|
21 |
await navigator.clipboard.write([
|
22 |
new ClipboardItem({
|
23 |
-
'image/png': domtoimage.toBlob(node)
|
24 |
-
})
|
25 |
]);
|
26 |
copyState = true;
|
27 |
setTimeout(() => (copyState = false), 1000);
|
@@ -39,18 +38,16 @@
|
|
39 |
<!-- Modal made with tailwind -->
|
40 |
<div class="modal relative z-2" transition:fade>
|
41 |
<div class="message">
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
<div class="grid grid-cols-3 gap-2
|
46 |
{#each imagePaths as image}
|
47 |
<div>
|
48 |
<img src={imageBaseUrl + image} alt="" class="w-full h-full" />
|
49 |
</div>
|
50 |
{/each}
|
51 |
</div>
|
52 |
-
<pre class="text-[0.5rem]" />
|
53 |
-
|
54 |
<svg
|
55 |
class="w-full"
|
56 |
viewBox="0 0 {board[0].length * (p + s)} {board.length * (p + s)}"
|
@@ -69,9 +66,12 @@
|
|
69 |
{/each}
|
70 |
{/each}
|
71 |
</svg>
|
|
|
|
|
|
|
72 |
</div>
|
73 |
</div>
|
74 |
-
<p>
|
75 |
Copy the result to clipboard
|
76 |
<button class="min-w-[6ch]" on:click={() => writeClipDOM(elToShare)}>
|
77 |
{!copyState ? 'Copy' : 'Copied'}
|
@@ -91,8 +91,7 @@
|
|
91 |
|
92 |
<style lang="postcss" scoped>
|
93 |
.message {
|
94 |
-
@apply
|
95 |
-
p-10 z-20 rounded-md -translate-x-1/2 transition-opacity duration-300 ease-in-out;
|
96 |
}
|
97 |
.modal {
|
98 |
@apply fixed top-0 left-0 w-screen min-h-screen z-10 bg-black bg-opacity-80 backdrop-blur-sm;
|
|
|
1 |
<script lang="ts">
|
2 |
+
import { colors, cheersMessages } from '$lib/utils';
|
3 |
import type { Board } from '../types';
|
4 |
import { fade } from 'svelte/transition';
|
|
|
5 |
export let board: Board;
|
6 |
export let currentRowIndex: number;
|
7 |
export let imagePaths: string[];
|
8 |
|
9 |
+
const message = cheersMessages[currentRowIndex];
|
10 |
import domtoimage from 'dom-to-image';
|
11 |
const imageBaseUrl = import.meta.env.MODE === 'development' ? 'http://localhost:7860/' : '';
|
12 |
|
|
|
20 |
try {
|
21 |
await navigator.clipboard.write([
|
22 |
new ClipboardItem({
|
23 |
+
'image/png': domtoimage.toBlob(node, {bgcolor: "#000"})})
|
|
|
24 |
]);
|
25 |
copyState = true;
|
26 |
setTimeout(() => (copyState = false), 1000);
|
|
|
38 |
<!-- Modal made with tailwind -->
|
39 |
<div class="modal relative z-2" transition:fade>
|
40 |
<div class="message">
|
41 |
+
<div class="border-0">
|
42 |
+
<div class="p-3" bind:this={elToShare}>
|
43 |
+
<h2 class="text-center uppercase tracking-widest font-extrabold">{message}</h2>
|
44 |
+
<div class="grid grid-cols-3 gap-2 p-3">
|
45 |
{#each imagePaths as image}
|
46 |
<div>
|
47 |
<img src={imageBaseUrl + image} alt="" class="w-full h-full" />
|
48 |
</div>
|
49 |
{/each}
|
50 |
</div>
|
|
|
|
|
51 |
<svg
|
52 |
class="w-full"
|
53 |
viewBox="0 0 {board[0].length * (p + s)} {board.length * (p + s)}"
|
|
|
66 |
{/each}
|
67 |
{/each}
|
68 |
</svg>
|
69 |
+
<p class="text-[0.6rem] font-extralight text-gray-300 opacity-50">
|
70 |
+
https://huggingface.co/spaces/huggingface-projects/wordalle
|
71 |
+
</p>
|
72 |
</div>
|
73 |
</div>
|
74 |
+
<p class="p-3 font-normal text-base">
|
75 |
Copy the result to clipboard
|
76 |
<button class="min-w-[6ch]" on:click={() => writeClipDOM(elToShare)}>
|
77 |
{!copyState ? 'Copy' : 'Copied'}
|
|
|
91 |
|
92 |
<style lang="postcss" scoped>
|
93 |
.message {
|
94 |
+
@apply text-white bg-black bg-opacity-80 font-semibold p-10 z-20 rounded-md transition-opacity duration-300 ease-in-out mx-auto max-w-lg;
|
|
|
95 |
}
|
96 |
.modal {
|
97 |
@apply fixed top-0 left-0 w-screen min-h-screen z-10 bg-black bg-opacity-80 backdrop-blur-sm;
|
frontend/src/lib/utils.ts
CHANGED
@@ -31,4 +31,6 @@ export const colors = {
|
|
31 |
[LetterState.PRESENT]: '#ffc80a',
|
32 |
[LetterState.ABSENT]: '#d9d9d9',
|
33 |
[LetterState.INITIAL]: '#5d5d5d'
|
34 |
-
};
|
|
|
|
|
|
31 |
[LetterState.PRESENT]: '#ffc80a',
|
32 |
[LetterState.ABSENT]: '#d9d9d9',
|
33 |
[LetterState.INITIAL]: '#5d5d5d'
|
34 |
+
};
|
35 |
+
|
36 |
+
export const cheersMessages = ['Genius', 'Magnificent', 'Impressive', 'Splendid', 'Great', 'Phew'];
|
frontend/src/routes/index.svelte
CHANGED
@@ -28,7 +28,6 @@
|
|
28 |
// Feedback state: message and shake
|
29 |
let message = '';
|
30 |
let grid = '';
|
31 |
-
let result = '';
|
32 |
let shakeRowIndex = -1;
|
33 |
let success = false;
|
34 |
// Handle keyboard input.
|
@@ -117,9 +116,6 @@
|
|
117 |
if (currentRow.every((tile) => tile.state === LetterState.CORRECT)) {
|
118 |
// yay!
|
119 |
setTimeout(() => {
|
120 |
-
result = ['Genius', 'Magnificent', 'Impressive', 'Splendid', 'Great', 'Phew'][
|
121 |
-
currentRowIndex
|
122 |
-
];
|
123 |
success = true;
|
124 |
}, totalTime);
|
125 |
} else if (currentRowIndex < board.length - 1) {
|
@@ -164,8 +160,8 @@
|
|
164 |
{#if message}
|
165 |
<Message {message} />
|
166 |
{/if}
|
167 |
-
{#if
|
168 |
-
<Result {board} {currentRowIndex} {imagePaths}
|
169 |
{/if}
|
170 |
<!-- <div class="message" transition:fade>
|
171 |
{message}
|
@@ -174,7 +170,7 @@
|
|
174 |
{/if}
|
175 |
</div> -->
|
176 |
<!-- {/if} -->
|
177 |
-
<header
|
178 |
<h1 class="text-3xl font-bold text-center">WORDALLE</h1>
|
179 |
</header>
|
180 |
<div class="grid grid-cols-3 gap-2 max-w-md mx-auto p-3">
|
|
|
28 |
// Feedback state: message and shake
|
29 |
let message = '';
|
30 |
let grid = '';
|
|
|
31 |
let shakeRowIndex = -1;
|
32 |
let success = false;
|
33 |
// Handle keyboard input.
|
|
|
116 |
if (currentRow.every((tile) => tile.state === LetterState.CORRECT)) {
|
117 |
// yay!
|
118 |
setTimeout(() => {
|
|
|
|
|
|
|
119 |
success = true;
|
120 |
}, totalTime);
|
121 |
} else if (currentRowIndex < board.length - 1) {
|
|
|
160 |
{#if message}
|
161 |
<Message {message} />
|
162 |
{/if}
|
163 |
+
{#if success}
|
164 |
+
<Result {board} {currentRowIndex} {imagePaths} />
|
165 |
{/if}
|
166 |
<!-- <div class="message" transition:fade>
|
167 |
{message}
|
|
|
170 |
{/if}
|
171 |
</div> -->
|
172 |
<!-- {/if} -->
|
173 |
+
<header>
|
174 |
<h1 class="text-3xl font-bold text-center">WORDALLE</h1>
|
175 |
</header>
|
176 |
<div class="grid grid-cols-3 gap-2 max-w-md mx-auto p-3">
|