From b9372060545870c0569b56e0265b9e5825136b69 Mon Sep 17 00:00:00 2001 From: Jakob Ankarhem Date: Sun, 20 Feb 2022 13:46:34 +0100 Subject: [PATCH] changes to share modal content --- src/components/CountdownTimer.svelte | 4 +- src/components/Modal/Modal.svelte | 2 +- src/components/Modal/ShareModalContent.svelte | 105 ++++++++++-------- .../api/words/statistics/current.json.ts | 23 +++- 4 files changed, 82 insertions(+), 52 deletions(-) diff --git a/src/components/CountdownTimer.svelte b/src/components/CountdownTimer.svelte index a613874..ccd2c97 100644 --- a/src/components/CountdownTimer.svelte +++ b/src/components/CountdownTimer.svelte @@ -32,6 +32,6 @@ .padStart(2, '0'); -
- {`${hoursLeft}:${minutesLeft}:${secondsLeft}`} +
+ {`${hoursLeft}h ${minutesLeft}m ${secondsLeft}s`}
diff --git a/src/components/Modal/Modal.svelte b/src/components/Modal/Modal.svelte index 839afc3..9740835 100644 --- a/src/components/Modal/Modal.svelte +++ b/src/components/Modal/Modal.svelte @@ -29,7 +29,7 @@
-
+
diff --git a/src/components/Modal/ShareModalContent.svelte b/src/components/Modal/ShareModalContent.svelte index ce9c141..2fc968a 100644 --- a/src/components/Modal/ShareModalContent.svelte +++ b/src/components/Modal/ShareModalContent.svelte @@ -1,6 +1,6 @@ -
-
-
- Lösningsdistribution för Swerdle #{wordId} -
-
- {#await fetchDistribution()} +
+

+ Utmana dina vänner +

+
+ {#if $gameState.state === GameState.Won} + Skryt om ditt resultat genom att klicka på dela knappen 👇! + {:else} + Dela din besvikelse över hur orimligt svårt ordet var med knappen 👇! + {/if} +
+ + (Avslöjar ej dina gissningar) +

+ Hur har det gått för andra? +

+ {#await stats then data} +
+ Dagens ord + + {data.word} + har spelats av {data.total.played} personer + varav + {data.total.won} var har klarat ordet. +
+ {/await} +
+
+
+ {#await stats} {:then data} {#if data.total === 0} @@ -86,14 +104,15 @@ {:else} {#each data.distribution as distItem}
{distItem.rowIndex + 1}
@@ -101,14 +120,12 @@ {/if} {/await}
+ Antal gissningar (vunna spel)
-

Nästa ord kommer om:

- - + Nästa ord kommer snart! + +
diff --git a/src/routes/api/words/statistics/current.json.ts b/src/routes/api/words/statistics/current.json.ts index 43ecf13..397f35f 100644 --- a/src/routes/api/words/statistics/current.json.ts +++ b/src/routes/api/words/statistics/current.json.ts @@ -11,22 +11,35 @@ interface Distribution { export async function get() { const currentWord = getCurrentWordRow(); - const distributionArray = db.query( + const wonGamesPerRowIndex = db.query( 'SELECT rowIndex, count(created_at) AS count FROM tbl_guesses WHERE guessId = wordId AND wordId = ? GROUP BY rowIndex', currentWord.id ); + const totalWon = wonGamesPerRowIndex.reduce((acc, curr) => { + return acc + curr.count; + }, 0); - const fullDistributionArray = Array.from({ length: 6 }, (_, i) => { + const startedGames = db.query( + 'SELECT created_at FROM tbl_guesses WHERE rowIndex = 0 AND wordId = ?', + currentWord.id + ); + + const distribution = Array.from({ length: 6 }, (_, i) => { return { rowIndex: i, count: 0 }; }); - distributionArray.forEach((row) => { - fullDistributionArray[row.rowIndex] = row; + wonGamesPerRowIndex.forEach((row) => { + distribution[row.rowIndex] = row; }); return { status: 200, body: { - distribution: fullDistributionArray + word: currentWord.word, + distribution: distribution, + total: { + won: totalWon, + played: startedGames.length + } } }; }