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'); +};