From ac98297cff9f4a8fcde9952a368212487e8c7e09 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 28 Jan 2023 14:21:38 +0000 Subject: [PATCH] sunrise-sunset: Update notification styles --- src/routes/sunrise-sunset/+page.svelte | 53 ++++--------- .../sunrise-sunset/NotificationSection.svelte | 77 +++++++++++++++++++ 2 files changed, 93 insertions(+), 37 deletions(-) create mode 100644 src/routes/sunrise-sunset/NotificationSection.svelte diff --git a/src/routes/sunrise-sunset/+page.svelte b/src/routes/sunrise-sunset/+page.svelte index 08d6b68..66c4ccf 100644 --- a/src/routes/sunrise-sunset/+page.svelte +++ b/src/routes/sunrise-sunset/+page.svelte @@ -2,19 +2,19 @@ import type { PageData } from "./$types.js"; import { format as formatDate } from "date-fns"; import { onMount } from "svelte"; - import { spring } from "svelte/motion"; - import { fade } from "svelte/transition"; - import { writable } from "svelte/store"; + import { writable, type Writable } from "svelte/store"; import Navbar from "$lib/components/Navbar.svelte"; import MetaTags from "./MetaTags.svelte"; import OptionsSection from "./OptionsSection.svelte"; import ScoreCardSection from "./ScoreCardSection.svelte"; + import NotificationSection from "./NotificationSection.svelte"; import type { ISunriseSunsetGuessingHistory } from "./ISunriseSunsetGuessingHistory.js"; let hasGuessingHistoryBeenLoaded = false; - let debug = true; - let visibleNotification: "none" | "success" | "failure" = "none"; + let debug = false; + let visibleNotification: Writable<"none" | "success" | "failure"> = + writable("none"); const guessingHistory = writable({ mostRecentGuessDate: undefined, @@ -24,12 +24,6 @@ incorrectDays: [] }); - const notificationSpring = spring(20, { - stiffness: 0.1, - damping: 0.15, - precision: 0.01 - }); - export let data: PageData; const now = new Date(); const todaysDateString = formatDate(now, "yyyy-MM-dd"); @@ -38,9 +32,8 @@ $: picture = data.body.photo; function debugRemoveLocalStorage() { - notificationSpring.set(20); localStorage.removeItem(localStorageKey); - visibleNotification = "none"; + visibleNotification.set("none"); guessingHistory.set({ mostRecentGuessDate: undefined, totalNumberOfGuesses: 0, @@ -51,11 +44,10 @@ } function revealNotification(wasCorrect: boolean) { - notificationSpring.set(0); if (wasCorrect) { - visibleNotification = "success"; + visibleNotification.set("success"); } else { - visibleNotification = "failure"; + visibleNotification.set("failure"); } } @@ -92,6 +84,13 @@ const storedGuessHistory = localStorage.getItem(localStorageKey); if (storedGuessHistory) { guessingHistory.set(JSON.parse(storedGuessHistory)); + const wasTodayGuessed = + $guessingHistory.mostRecentGuessDate === todaysDateString; + if (wasTodayGuessed) { + revealNotification( + $guessingHistory.correctDays.includes(todaysDateString) + ); + } } hasGuessingHistoryBeenLoaded = true; }); @@ -120,17 +119,7 @@ {#if hasGuessingHistoryBeenLoaded} -
- {#if visibleNotification !== "none"} -
- {visibleNotification === "success" ? "Correct 🎉" : "Incorrect 💔"} -
- {/if} -
+ diff --git a/src/routes/sunrise-sunset/NotificationSection.svelte b/src/routes/sunrise-sunset/NotificationSection.svelte new file mode 100644 index 0000000..b60999a --- /dev/null +++ b/src/routes/sunrise-sunset/NotificationSection.svelte @@ -0,0 +1,77 @@ + + +
+ {#if $visibleNotification !== "none"} +
+

+ Today's Guess: +

+

+ {$visibleNotification === "success" ? "Correct 🎉" : "Incorrect 💔"} +

+
+ {/if} +
+ +