make time left indicators update every minute, and fix segmented progress bars.
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-01-13 23:08:17 +01:00
parent ab35df9fe2
commit 468d12879c
5 changed files with 48 additions and 10 deletions
+8 -2
View File
@@ -1,4 +1,6 @@
<script lang="ts">
import EveryMinute from "./EveryMinute.svelte";
export let startTime: Date | string = new Date();
export let endTime: Date | string = new Date();
@@ -9,6 +11,7 @@
let amountStr = "0";
let unit = "days";
let titleTimeStr = "";
let now = new Date();
function formatTime(time: Date): string {
const pad = (n:number) => n < 9 ? '0'+n : n.toString();
@@ -16,9 +19,11 @@
return `${time.getFullYear()}-${pad(time.getMonth()+1)}-${pad(time.getDate())}`
}
$: {
const now = new Date();
function onMinute(e: {detail: Date}) {
now = e.detail;
}
$: {
overdue = false;
unit = "days";
@@ -64,6 +69,7 @@
}
</script>
<EveryMinute on:minute={onMinute} />
<span title={titleTimeStr}>
{#if (overdue)}
<span class="overdue">{amountStr} {unit} ago</span>
@@ -0,0 +1,31 @@
<script lang="ts" context="module">
const listeners: ((now: Date)=>void)[] = [];
setInterval(() => {
for (const listener of listeners) {
listener(new Date);
}
}, 60000);
</script>
<script lang="ts">
import { createEventDispatcher, onMount } from "svelte";
const dispatch = createEventDispatcher();
function onMinute(date: Date) {
dispatch("minute", date);
}
onMount(() => {
listeners.push(onMinute);
return () => {
const index = listeners.indexOf(onMinute);
if (index !== -1) {
listeners.splice(index, 1);
}
}
})
</script>
+7 -2
View File
@@ -1,6 +1,7 @@
<script lang="ts">
import type { GoalResult } from "../models/goal";
import type { ModalData } from "../stores/modal";
import EveryMinute from "./EveryMinute.svelte";
import Option from "./Option.svelte";
import OptionRow from "./OptionRow.svelte";
import ParentEntry from "./ParentEntry.svelte";
@@ -14,12 +15,16 @@
let mdGoalDelete: ModalData;
let msLength: number;
let msElapsed: number;
let now = Date.now();
function onMinute(e: {detail: Date}) {
now = e.detail.getTime();
}
$: mdGoalEdit = {name:"goal.edit", goal};
$: mdGoalDelete = {name:"goal.delete", goal};
$: {
const now = Date.now()
const start = Date.parse(goal.startTime)
const length = Date.parse(goal.endTime) - start;
@@ -35,7 +40,7 @@
}
}
</script>
<EveryMinute on:minute={onMinute} />
<ParentEntry
full={showAllOptions}
entry={goal}
+1 -3
View File
@@ -51,9 +51,7 @@
// Mark it non-segmented if the target is too high. This prevents a clunky progress bar,
// or a browser freeze if you set the target very high.
if (target > 50) {
nonSegmented = true;
}
nonSegmented = (target >= 50);
}
</script>
+1 -3
View File
@@ -41,7 +41,7 @@
fakeProject = {
id: "P_fakeProject",
active: true,
createdTime: new Date().toISOString(),
createdTime: "1970-01-01T00:00:00Z",
description: "",
icon: "list",
name: "Individual Tasks",
@@ -53,8 +53,6 @@
if (fakeProject.tasks.length > 0) {
fakeProject.endTime = fakeProject.tasks[0].endTime;
}
console.log(fakeProject, $fpTaskStore);
}
$: {