MapComplete/src/UI/OpeningHours/NextChangeViz.svelte

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

61 lines
2 KiB
Svelte
Raw Normal View History

2023-12-19 22:08:00 +01:00
<script lang="ts">
/**
* Simple visualisation which shows when the POI opens/closes next.
*/
import type { SpecialVisualizationState } from "../SpecialVisualization"
import { Store, Stores } from "../../Logic/UIEventSource"
import { OH } from "./OpeningHours"
import opening_hours from "opening_hours"
import Clock from "../../assets/svg/Clock.svelte"
import { Utils } from "../../Utils"
import Circle from "../../assets/svg/Circle.svelte"
import Ring from "../../assets/svg/Ring.svelte"
export let state: SpecialVisualizationState
export let tags: Store<Record<string, string>>
export let keyToUse: string = "opening_hours"
export let prefix: string = undefined
export let postfix: string = undefined
let oh: Store<opening_hours | "error" | undefined> = OH.CreateOhObjectStore(
tags,
keyToUse,
prefix,
2024-02-20 13:33:38 +01:00
postfix
2023-12-19 22:08:00 +01:00
)
let currentState = oh.mapD((oh) => (typeof oh === "string" ? undefined : oh.getState()))
let tomorrow = new Date()
tomorrow.setTime(tomorrow.getTime() + 24 * 60 * 60 * 1000)
let nextChange = oh
.mapD(
(oh) => (typeof oh === "string" ? undefined : oh.getNextChange(new Date(), tomorrow)),
2024-02-20 13:33:38 +01:00
[Stores.Chronic(5 * 60 * 1000)]
2023-12-19 22:08:00 +01:00
)
.mapD((date) => Utils.TwoDigits(date.getHours()) + ":" + Utils.TwoDigits(date.getMinutes()))
let size = nextChange.map((change) =>
2024-02-20 13:33:38 +01:00
change === undefined ? "absolute h-7 w-7" : "absolute h-5 w-5 top-0 left-1/4"
2023-12-19 22:08:00 +01:00
)
2023-12-04 03:32:25 +01:00
</script>
{#if $currentState !== undefined}
<div class="relative h-8 w-8">
{#if $currentState === true}
<Ring class={$size} color="#0f0" style="z-index: 0" />
<Clock class={$size} color="#0f0" style="z-index: 0" />
{:else if $currentState === false}
<Circle class={$size} color="#f00" style="z-index: 0" />
<Clock class={$size} color="#fff" style="z-index: 0" />
{/if}
{#if $nextChange !== undefined}
2023-12-19 22:08:00 +01:00
<span
class="absolute bottom-0 text-sm font-bold"
style="z-index: 1; background-color: #ffffff88; margin-top: 3px"
>
2023-12-04 03:32:25 +01:00
{$nextChange}
</span>
{/if}
</div>
{/if}