Skip to content

Commit

Permalink
Simplify liters count
Browse files Browse the repository at this point in the history
  • Loading branch information
edalholt committed Dec 7, 2024
1 parent 5e36aba commit 8ff341f
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions frontend/src/lib/LastCoffee.svelte
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
<script lang="ts">
import axios from "axios";
import { onMount } from "svelte";
let hours = 0;
let minutes = 0;
const calculateTimeSinceBrew = async (lastCoffee: string) => {
const timeSince = Math.abs(
new Date(Date.parse(lastCoffee)).getTime() - Date.now()
);
hours = Math.floor(timeSince / 1000 / 60 / 60);
minutes = Math.floor((timeSince / 1000 / 60) % 60);
};
let timeSince = null;
onMount(async () => {
const res = await axios.get("/coffee/latest");
calculateTimeSinceBrew(await res.data.brewTime);
timeSince = await res.data.timeSince;
});
</script>

{hours} hours and {minutes} minutes
{#if timeSince}
<p>{timeSince}</p>
{:else}
<p>Loading...</p>
{/if}

0 comments on commit 8ff341f

Please sign in to comment.