more frontend stuff
This commit is contained in:
parent
cb6f86207a
commit
bb6c61b08e
@ -4,7 +4,7 @@
|
|||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite --host",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"check": "svelte-check --tsconfig ./tsconfig.json"
|
"check": "svelte-check --tsconfig ./tsconfig.json"
|
||||||
|
@ -8,8 +8,8 @@
|
|||||||
let info: Info;
|
let info: Info;
|
||||||
let alarms: Alarm[];
|
let alarms: Alarm[];
|
||||||
|
|
||||||
onMount(async () => {
|
function fetchdata() {
|
||||||
Promise.all([
|
return Promise.all([
|
||||||
fetch("/api/info")
|
fetch("/api/info")
|
||||||
.then((r) => r.json())
|
.then((r) => r.json())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
@ -21,6 +21,10 @@
|
|||||||
alarms = data;
|
alarms = data;
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
await fetchdata();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -33,7 +37,9 @@
|
|||||||
{#if alarms}
|
{#if alarms}
|
||||||
{#each alarms as alarm}
|
{#each alarms as alarm}
|
||||||
<div class="mb-2 pb-2 px-2 w-full border-b-2">
|
<div class="mb-2 pb-2 px-2 w-full border-b-2">
|
||||||
<AlarmComp {alarm} />
|
<AlarmComp {alarm} on:update={()=>{
|
||||||
|
fetchdata();
|
||||||
|
}} />
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
{/if}
|
{/if}
|
||||||
|
@ -11,7 +11,8 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<div class="fixed bottom-8 right-5" >
|
<!-- TODO: handle position of button on mobile -->
|
||||||
|
<div class="pt-10" >
|
||||||
{#if closed}
|
{#if closed}
|
||||||
<button class="h-16 p-2 bg-orange-500 rounded-xl cursor-pointer" on:click={()=>{
|
<button class="h-16 p-2 bg-orange-500 rounded-xl cursor-pointer" on:click={()=>{
|
||||||
closed = false;
|
closed = false;
|
||||||
@ -19,7 +20,7 @@
|
|||||||
<MdAddAlarm />
|
<MdAddAlarm />
|
||||||
</button>
|
</button>
|
||||||
{:else}
|
{:else}
|
||||||
<div class="w-40 h-10 bg-orange-500 rounded-xl flex">
|
<div class="w-40 h-10 bg-orange-500 rounded-xl flex justify-center">
|
||||||
<form
|
<form
|
||||||
on:submit|preventDefault={()=>{
|
on:submit|preventDefault={()=>{
|
||||||
closed = true;
|
closed = true;
|
||||||
@ -28,7 +29,8 @@
|
|||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
class="bg-transparent border-b-2 border-white outline-none w-32 m-auto"
|
inputmode="text"
|
||||||
|
class="bg-transparent border-b-2 border-white outline-none w-32 m-auto pt-1"
|
||||||
use:focus on:focusout={()=>{
|
use:focus on:focusout={()=>{
|
||||||
closed = true;
|
closed = true;
|
||||||
}}
|
}}
|
||||||
|
@ -3,21 +3,45 @@
|
|||||||
import MdRemoveCircle from 'svelte-icons/md/MdRemoveCircle.svelte'
|
import MdRemoveCircle from 'svelte-icons/md/MdRemoveCircle.svelte'
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
import MdAlarmOff from 'svelte-icons/md/MdAlarmOff.svelte'
|
import MdAlarmOff from 'svelte-icons/md/MdAlarmOff.svelte'
|
||||||
|
|
||||||
import type { Alarm } from "../types";
|
import type { Alarm } from "../types";
|
||||||
|
import { createEventDispatcher } from 'svelte';
|
||||||
|
|
||||||
export let alarm: Alarm;
|
export let alarm: Alarm;
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex justify-between items-center w-full">
|
<div class="flex justify-between items-center w-full">
|
||||||
<!-- <div class="text-xl" >{alarm.name}</div> -->
|
<!-- <div class="text-xl" >{alarm.name}</div> -->
|
||||||
<div class="text-xl">{alarm.time}</div>
|
<div class="text-xl">{alarm.time}</div>
|
||||||
<dir class="h-7 cursor-pointer flex gap-6 text-orange-500" >
|
<dir class="flex gap-5">
|
||||||
|
<button class="h-7 cursor-pointer" on:click={()=>{
|
||||||
|
fetch(`/api/alarm/${alarm.name}`, {
|
||||||
|
method: "PATCH",
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
disabled: !alarm.disabled
|
||||||
|
})
|
||||||
|
}).then(res => {
|
||||||
|
|
||||||
|
if (res.status === 200) {
|
||||||
|
dispatch('update', alarm);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}}>
|
||||||
<MdAlarmOff />
|
<MdAlarmOff />
|
||||||
|
</button>
|
||||||
|
{#if alarm.disabled}
|
||||||
|
<div class="text-xl">Disabled</div>
|
||||||
|
{/if}
|
||||||
|
<button class="h-7 cursor-pointer" on:click={()=>{
|
||||||
|
// TODO: remove alarm
|
||||||
|
dispatch('remove', alarm);
|
||||||
|
}}>
|
||||||
<MdRemoveCircle />
|
<MdRemoveCircle />
|
||||||
|
</button>
|
||||||
</dir>
|
</dir>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
|
||||||
|
|
||||||
</style>
|
|
@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
export let info: Info;
|
export let info: Info;
|
||||||
|
|
||||||
let duration = Duration.parse(info.nextAlarmIn);
|
|
||||||
let localUTOffset = new Date().getTimezoneOffset() * -1 / 60;
|
let localUTOffset = new Date().getTimezoneOffset() * -1 / 60;
|
||||||
let serverTime = new ServerClock(info.serverTime)
|
let serverTime = new ServerClock(info.serverTime)
|
||||||
|
|
||||||
@ -28,7 +27,9 @@
|
|||||||
<p class="text-orange-500" >Local time not in sync with server </p>
|
<p class="text-orange-500" >Local time not in sync with server </p>
|
||||||
{/if }
|
{/if }
|
||||||
</div>
|
</div>
|
||||||
|
{#if info.nextAlarmIn}
|
||||||
<div class="text-lg text-center mt-2">
|
<div class="text-lg text-center mt-2">
|
||||||
<div class="h-4 inline-block" ><MdAccessAlarm /></div> <span> in {duration.sprintf("%hh %mm")}</span>
|
<div class="h-4 inline-block" ><MdAccessAlarm /></div> <span> in {Duration.parse(info.nextAlarmIn).sprintf("%hh %mm")}</span>
|
||||||
</div>
|
</div>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
export interface Info {
|
export interface Info {
|
||||||
alarms: number
|
alarms: number
|
||||||
deviceId: string
|
deviceId: string
|
||||||
nextAlarmAt: string
|
nextAlarmAt?: string
|
||||||
nextAlarmIn: string
|
nextAlarmIn?: string
|
||||||
serverTime: string
|
serverTime: string
|
||||||
spotifyUser: string
|
spotifyUser: string
|
||||||
timezone: string
|
timezone: string
|
||||||
@ -13,4 +13,5 @@ export interface Info {
|
|||||||
export interface Alarm {
|
export interface Alarm {
|
||||||
name: string
|
name: string
|
||||||
time: string
|
time: string
|
||||||
|
disabled: boolean
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user