Browse Source

make time left indicators update every minute, and fix segmented progress bars.

main
Gisle Aune 4 years ago
parent
commit
468d12879c
  1. 10
      svelte-ui/src/components/DaysLeft.svelte
  2. 31
      svelte-ui/src/components/EveryMinute.svelte
  3. 9
      svelte-ui/src/components/GoalEntry.svelte
  4. 4
      svelte-ui/src/components/Progress.svelte
  5. 4
      svelte-ui/src/pages/FrontPage.svelte

10
svelte-ui/src/components/DaysLeft.svelte

@ -1,4 +1,6 @@
<script lang="ts"> <script lang="ts">
import EveryMinute from "./EveryMinute.svelte";
export let startTime: Date | string = new Date(); export let startTime: Date | string = new Date();
export let endTime: Date | string = new Date(); export let endTime: Date | string = new Date();
@ -9,6 +11,7 @@
let amountStr = "0"; let amountStr = "0";
let unit = "days"; let unit = "days";
let titleTimeStr = ""; let titleTimeStr = "";
let now = new Date();
function formatTime(time: Date): string { function formatTime(time: Date): string {
const pad = (n:number) => n < 9 ? '0'+n : n.toString(); const pad = (n:number) => n < 9 ? '0'+n : n.toString();
@ -16,9 +19,11 @@
return `${time.getFullYear()}-${pad(time.getMonth()+1)}-${pad(time.getDate())}` return `${time.getFullYear()}-${pad(time.getMonth()+1)}-${pad(time.getDate())}`
} }
$: {
const now = new Date();
function onMinute(e: {detail: Date}) {
now = e.detail;
}
$: {
overdue = false; overdue = false;
unit = "days"; unit = "days";
@ -64,6 +69,7 @@
} }
</script> </script>
<EveryMinute on:minute={onMinute} />
<span title={titleTimeStr}> <span title={titleTimeStr}>
{#if (overdue)} {#if (overdue)}
<span class="overdue">{amountStr} {unit} ago</span> <span class="overdue">{amountStr} {unit} ago</span>

31
svelte-ui/src/components/EveryMinute.svelte

@ -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>

9
svelte-ui/src/components/GoalEntry.svelte

@ -1,6 +1,7 @@
<script lang="ts"> <script lang="ts">
import type { GoalResult } from "../models/goal"; import type { GoalResult } from "../models/goal";
import type { ModalData } from "../stores/modal"; import type { ModalData } from "../stores/modal";
import EveryMinute from "./EveryMinute.svelte";
import Option from "./Option.svelte"; import Option from "./Option.svelte";
import OptionRow from "./OptionRow.svelte"; import OptionRow from "./OptionRow.svelte";
import ParentEntry from "./ParentEntry.svelte"; import ParentEntry from "./ParentEntry.svelte";
@ -14,12 +15,16 @@
let mdGoalDelete: ModalData; let mdGoalDelete: ModalData;
let msLength: number; let msLength: number;
let msElapsed: number; let msElapsed: number;
let now = Date.now();
function onMinute(e: {detail: Date}) {
now = e.detail.getTime();
}
$: mdGoalEdit = {name:"goal.edit", goal}; $: mdGoalEdit = {name:"goal.edit", goal};
$: mdGoalDelete = {name:"goal.delete", goal}; $: mdGoalDelete = {name:"goal.delete", goal};
$: { $: {
const now = Date.now()
const start = Date.parse(goal.startTime) const start = Date.parse(goal.startTime)
const length = Date.parse(goal.endTime) - start; const length = Date.parse(goal.endTime) - start;
@ -35,7 +40,7 @@
} }
} }
</script> </script>
<EveryMinute on:minute={onMinute} />
<ParentEntry <ParentEntry
full={showAllOptions} full={showAllOptions}
entry={goal} entry={goal}

4
svelte-ui/src/components/Progress.svelte

@ -51,9 +51,7 @@
// Mark it non-segmented if the target is too high. This prevents a clunky progress bar, // 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. // or a browser freeze if you set the target very high.
if (target > 50) {
nonSegmented = true;
}
nonSegmented = (target >= 50);
} }
</script> </script>

4
svelte-ui/src/pages/FrontPage.svelte

@ -41,7 +41,7 @@
fakeProject = { fakeProject = {
id: "P_fakeProject", id: "P_fakeProject",
active: true, active: true,
createdTime: new Date().toISOString(),
createdTime: "1970-01-01T00:00:00Z",
description: "", description: "",
icon: "list", icon: "list",
name: "Individual Tasks", name: "Individual Tasks",
@ -53,8 +53,6 @@
if (fakeProject.tasks.length > 0) { if (fakeProject.tasks.length > 0) {
fakeProject.endTime = fakeProject.tasks[0].endTime; fakeProject.endTime = fakeProject.tasks[0].endTime;
} }
console.log(fakeProject, $fpTaskStore);
} }
$: { $: {

Loading…
Cancel
Save