Handle no scheduled alarm case

This commit is contained in:
nemunaire 2022-10-15 14:34:55 +02:00
parent 764ac78063
commit 192e751405
2 changed files with 25 additions and 17 deletions

View File

@ -65,7 +65,11 @@ export async function getAlarmSingle(aid) {
export async function getNextAlarm() {
const res = await fetch(`api/alarms/next`, {headers: {'Accept': 'application/json'}})
if (res.status == 200) {
return new Date(await res.json());
const data = await res.json();
if (data)
return new Date(data);
else
return data;
} else {
throw new Error((await res.json()).errmsg);
}

View File

@ -69,7 +69,10 @@
<span class="visually-hidden">Loading...</span>
</div>
{:then nextalarm}
Prochain réveil&nbsp;:
{#if nextalarm === null}
<Icon name="x-octagon" /> Pas de prochain réveil programmé
{:else}
<Icon name="alarm-fill" /> Prochain réveil&nbsp;:
{#if nextalarm.getDay() == new Date().getDay() && nextalarm.getMonth() == new Date().getMonth() && nextalarm.getFullYear() == new Date().getFullYear()}
aujourd'hui à
<DateFormat date={nextalarm} timeStyle="long" />
@ -87,6 +90,7 @@
{:else}
<DateFormat date={nextalarm} dateStyle="short" timeStyle="long" />
{/if}
{/if}
{/await}
</div>
{#await isActiveP then isActive}