Handle no scheduled alarm case
This commit is contained in:
parent
764ac78063
commit
192e751405
@ -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);
|
||||
}
|
||||
|
@ -69,23 +69,27 @@
|
||||
<span class="visually-hidden">Loading...</span>
|
||||
</div>
|
||||
{:then nextalarm}
|
||||
Prochain réveil :
|
||||
{#if nextalarm.getDay() == new Date().getDay() && nextalarm.getMonth() == new Date().getMonth() && nextalarm.getFullYear() == new Date().getFullYear()}
|
||||
aujourd'hui à
|
||||
<DateFormat date={nextalarm} timeStyle="long" />
|
||||
<br class="d-block d-md-none" />
|
||||
<CycleCounter ends={nextalarm} on:reload={reloadNextAlarm} />
|
||||
{:else if nextalarm.getDay() == new Date(Date.now() + 86400000).getDay() && nextalarm.getMonth() == new Date(Date.now() + 86400000).getMonth() && nextalarm.getFullYear() == new Date(Date.now() + 86400000).getFullYear()}
|
||||
demain à
|
||||
<DateFormat date={nextalarm} timeStyle="long" />
|
||||
<br class="d-block d-md-none" />
|
||||
<CycleCounter ends={nextalarm} on:reload={reloadNextAlarm} />
|
||||
{:else if nextalarm.getTime() < Date.now() + 604800000}
|
||||
<span title={nextalarm}>{nextalarm.toLocaleString('default', {weekday: 'long'})}</span>
|
||||
à
|
||||
<DateFormat date={nextalarm} timeStyle="long" />
|
||||
{#if nextalarm === null}
|
||||
<Icon name="x-octagon" /> Pas de prochain réveil programmé
|
||||
{:else}
|
||||
<DateFormat date={nextalarm} dateStyle="short" timeStyle="long" />
|
||||
<Icon name="alarm-fill" /> Prochain réveil :
|
||||
{#if nextalarm.getDay() == new Date().getDay() && nextalarm.getMonth() == new Date().getMonth() && nextalarm.getFullYear() == new Date().getFullYear()}
|
||||
aujourd'hui à
|
||||
<DateFormat date={nextalarm} timeStyle="long" />
|
||||
<br class="d-block d-md-none" />
|
||||
<CycleCounter ends={nextalarm} on:reload={reloadNextAlarm} />
|
||||
{:else if nextalarm.getDay() == new Date(Date.now() + 86400000).getDay() && nextalarm.getMonth() == new Date(Date.now() + 86400000).getMonth() && nextalarm.getFullYear() == new Date(Date.now() + 86400000).getFullYear()}
|
||||
demain à
|
||||
<DateFormat date={nextalarm} timeStyle="long" />
|
||||
<br class="d-block d-md-none" />
|
||||
<CycleCounter ends={nextalarm} on:reload={reloadNextAlarm} />
|
||||
{:else if nextalarm.getTime() < Date.now() + 604800000}
|
||||
<span title={nextalarm}>{nextalarm.toLocaleString('default', {weekday: 'long'})}</span>
|
||||
à
|
||||
<DateFormat date={nextalarm} timeStyle="long" />
|
||||
{:else}
|
||||
<DateFormat date={nextalarm} dateStyle="short" timeStyle="long" />
|
||||
{/if}
|
||||
{/if}
|
||||
{/await}
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user