From e1769f5c6ae8ae19fa144937dde76a1d51e96a2f Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 24 Jan 2023 21:12:19 +0000 Subject: [PATCH] sunrise-sunset: create the sunrise-sunset photo guessing page --- src/routes/sunrise-sunset/+page.svelte | 145 ++++++++++++++----------- src/routes/sunrise-sunset/+page.ts | 17 +++ 2 files changed, 98 insertions(+), 64 deletions(-) create mode 100644 src/routes/sunrise-sunset/+page.ts diff --git a/src/routes/sunrise-sunset/+page.svelte b/src/routes/sunrise-sunset/+page.svelte index 51f691d..7a76213 100644 --- a/src/routes/sunrise-sunset/+page.svelte +++ b/src/routes/sunrise-sunset/+page.svelte @@ -1,86 +1,103 @@ -

Sunrise, Sunset?

+ + +
+

Sunrise, Sunset?

+
- Sunrise or Sunset? + Sunrise or Sunset?
-
- - -
+
+ + +
- {#if $guessHistory.total > 0} -

- You've guessed correctly {Number($guessHistory.correct / $guessHistory.total)}% of the time -

- {:else} -

You've not guessed yet.

- {/if} + {#if $guessHistory.total > 0} +

+ You've guessed correctly {Number( + $guessHistory.correct / $guessHistory.total + )}% of the time +

+ {:else} +

You've not guessed yet.

+ {/if}
diff --git a/src/routes/sunrise-sunset/+page.ts b/src/routes/sunrise-sunset/+page.ts new file mode 100644 index 0000000..ea644c4 --- /dev/null +++ b/src/routes/sunrise-sunset/+page.ts @@ -0,0 +1,17 @@ +import { error } from '@sveltejs/kit'; +import type { PageLoad } from './$types.js'; +import { type DailyPhoto } from '../api/sunrise-sunset-photo.json/SunriseSunsetController.js'; + +export const load: PageLoad = async ({ fetch }) => { + const response = await fetch('/api/sunrise-sunset-photo.json'); + + if (response.ok) { + const json: DailyPhoto = await response.json(); + return { + status: 200, + body: json as DailyPhoto, + }; + } + + throw error(500, 'Failed to fetch sunrise-sunset photo'); +};