summaryrefslogtreecommitdiffstats
path: root/apps/web-shared/src/components
diff options
context:
space:
mode:
authorivarlovlie <git@ivarlovlie.no>2022-06-02 23:02:47 +0200
committerivarlovlie <git@ivarlovlie.no>2022-06-02 23:02:47 +0200
commitccf06386c6b153fe3c420e9200f481dc085e064a (patch)
tree656b182fa83dfedde0d36f341f15d282e751aa4e /apps/web-shared/src/components
parent83b11393da8f733c0ffc5abed5d1e0e827d04b61 (diff)
downloadgreatoffice-ccf06386c6b153fe3c420e9200f481dc085e064a.tar.xz
greatoffice-ccf06386c6b153fe3c420e9200f481dc085e064a.zip
refactor: Rename accounts to portal
Diffstat (limited to 'apps/web-shared/src/components')
-rw-r--r--apps/web-shared/src/components/stopwatch.svelte30
1 files changed, 26 insertions, 4 deletions
diff --git a/apps/web-shared/src/components/stopwatch.svelte b/apps/web-shared/src/components/stopwatch.svelte
index 8287e31..3ed0d0e 100644
--- a/apps/web-shared/src/components/stopwatch.svelte
+++ b/apps/web-shared/src/components/stopwatch.svelte
@@ -1,8 +1,8 @@
<script lang="ts">
- import {writable_persistent} from "$shared/lib/persistent-store";
import Button from "$shared/components/button.svelte";
import {Textarea} from "$shared/components/form";
import {StorageKeys} from "$shared/lib/configuration";
+ import {StoreType, writable_persistent} from "$shared/lib/persistent-store";
import {Temporal} from "@js-temporal/polyfill";
import {createEventDispatcher, onMount} from "svelte";
@@ -11,11 +11,15 @@
hours: 0,
minutes: 0,
seconds: 0,
- startTime: null as Temporal.PlainTime,
+ startTime: null as Temporal.PlainDateTime,
+ lastStep: null as Temporal.PlainDateTime,
isRunning: false,
intervalId: 0,
note: "",
},
+ options: {
+ store: StoreType.LOCAL
+ },
name: StorageKeys.stopwatch,
});
@@ -30,10 +34,27 @@
}
onMount(() => {
+ start_if_running();
+ });
+
+ function start_if_running() {
if ($state.isRunning) {
+ if (Temporal.PlainDateTime.compare($state.lastStep, Temporal.Now.plainDateTimeISO()) == -1) {
+ const duration = Temporal.Now.plainDateTimeISO().since($state.lastStep, {smallestUnit: "second"});
+ console.log("lastStep",$state.lastStep.toString());
+ console.log("duration", duration.toString());
+ console.log(duration.seconds);
+ // for (let i = 0; i < steps; i++) {
+ // step();
+ // }
+ }
clearInterval($state.intervalId);
$state.intervalId = setInterval(step, 1000);
}
+ }
+
+ window.addEventListener("focus", () => {
+ start_if_running();
});
const dispatch = createEventDispatcher();
@@ -52,7 +73,8 @@
$state.seconds = 0;
}
- if (!$state.startTime) $state.startTime = Temporal.Now.plainTimeISO();
+ if (!$state.startTime) $state.startTime = Temporal.Now.plainDateTimeISO();
+ $state.lastStep = Temporal.Now.plainDateTimeISO();
}
function reset() {
@@ -108,7 +130,7 @@
function on_create_entry() {
if (!$state.startTime) return;
- const plainStartTime = Temporal.PlainTime.from($state.startTime);
+ const plainStartTime = Temporal.PlainDateTime.from($state.startTime);
dispatch("create", {
from: plainStartTime,
to: plainStartTime.add({hours: $state.hours, minutes: $state.minutes, seconds: $state.seconds}),