diff --git a/src/routes/sunrise-sunset/+page.svelte b/src/routes/sunrise-sunset/+page.svelte index 56e2d86..08d6b68 100644 --- a/src/routes/sunrise-sunset/+page.svelte +++ b/src/routes/sunrise-sunset/+page.svelte @@ -8,10 +8,12 @@ import Navbar from "$lib/components/Navbar.svelte"; import MetaTags from "./MetaTags.svelte"; + import OptionsSection from "./OptionsSection.svelte"; + import ScoreCardSection from "./ScoreCardSection.svelte"; import type { ISunriseSunsetGuessingHistory } from "./ISunriseSunsetGuessingHistory.js"; let hasGuessingHistoryBeenLoaded = false; - let debug = false; + let debug = true; let visibleNotification: "none" | "success" | "failure" = "none"; const guessingHistory = writable({ @@ -57,7 +59,8 @@ } } - function onOptionSelected(option: "sunrise" | "sunset") { + function onOptionSelected(event: { option: "sunrise" | "sunset" }) { + const { option } = event; $guessingHistory.mostRecentGuessDate = todaysDateString; $guessingHistory.totalNumberOfGuesses += 1; $guessingHistory.guesses = [...$guessingHistory.guesses, option]; @@ -128,47 +131,22 @@ {/if} -
-
- - -
- {#if $guessingHistory.mostRecentGuessDate === todaysDateString} -

- You've already guessed today. Come back tomorrow. -

- {/if} -
-
-
-

Your Score

- {#if $guessingHistory.mostRecentGuessDate !== undefined} -

- You've made {$guessingHistory.totalNumberOfGuesses} - {$guessingHistory.totalNumberOfGuesses === 1 ? "guess" : "guesses"} so - far. -

-

- You've guessed correctly {Number( - $guessingHistory.correctDays.length / - $guessingHistory.totalNumberOfGuesses - ) * 100}% of the time. -

- {:else} -

You've not guessed yet.

- {/if} -
-
+ { + onOptionSelected(event.detail); + }} + /> + + {/if} @@ -218,59 +196,6 @@ max-height: 100%; } - .options { - padding: 12px; - display: grid; - place-items: center; - grid-template-columns: 100%; - } - - .options__buttons-container { - display: grid; - gap: 12px; - grid-template-columns: 50% 50%; - place-content: center; - max-width: 500px; - } - - .options__button { - border: 1px solid #000; - text-align: center; - border-radius: 4px; - padding: 12px; - font-size: 1.2rem; - cursor: pointer; - transition: all 0.2s ease-in-out; - } - - .options__button:disabled { - opacity: 0.5; - cursor: not-allowed; - } - - .option--sunrise { - border-color: var(--colour-orage); - background-color: var(--colour-orage); - color: white; - } - - .option--sunrise:hover:not(:disabled) { - color: white; - background-color: var(--colour-orange-lightened); - } - - .option--sunset { - border-color: var(--colour-grey-lightened); - background-color: var(--colour-grey-lightened); - color: white; - } - - .option--sunset:hover:not(:disabled) { - color: white; - background-color: var(--colour-grey); - border-color: var(--colour-dark-grey); - } - .notification { } @@ -280,27 +205,4 @@ text-align: center; font-size: 1.2rem; } - - .score { - display: grid; - place-content: center; - text-align: center; - padding: 12px 0px; - } - - .score__card { - display: grid; - place-content: center; - background: white; - text-align: center; - padding: 12px; - border-radius: 4px; - // gentle grey border, with soft shadow - border: 1px solid rgba(0, 0, 0, 0.1); - box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.1); - } - - .score__title { - font-size: 1.2rem; - } diff --git a/src/routes/sunrise-sunset/OptionsSection.svelte b/src/routes/sunrise-sunset/OptionsSection.svelte new file mode 100644 index 0000000..ce874e0 --- /dev/null +++ b/src/routes/sunrise-sunset/OptionsSection.svelte @@ -0,0 +1,90 @@ + + +
+
+ + +
+ {#if hasAlreadyGuessedToday} +

+ You've already guessed today. Come back tomorrow. +

+ {/if} +
+ + diff --git a/src/routes/sunrise-sunset/ScoreCardSection.svelte b/src/routes/sunrise-sunset/ScoreCardSection.svelte new file mode 100644 index 0000000..e59336d --- /dev/null +++ b/src/routes/sunrise-sunset/ScoreCardSection.svelte @@ -0,0 +1,52 @@ + + +
+
+

Your Score Card

+ {#if doesUserHaveGuessingHistory} +

+ You've made {totalGuessCount} + {totalGuessCount === 1 ? "guess" : "guesses"} so far. +

+

+ You've guessed correctly {Number(correctGuessCount / totalGuessCount) * + 100}% of the time. +

+ {:else} +

You've not guessed yet.

+ {/if} +
+
+ +