You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.5 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <script lang="ts">
  2. import type { GoalResult } from "../models/goal";
  3. import type { ModalData } from "../stores/modal";
  4. import EveryMinute from "./EveryMinute.svelte";
  5. import Option from "./Option.svelte";
  6. import OptionRow from "./OptionRow.svelte";
  7. import ParentEntry from "./ParentEntry.svelte";
  8. import Progress from "./Progress.svelte";
  9. export let goal: GoalResult = null;
  10. export let showAllOptions = false;
  11. export let linkGoal = false;
  12. let mdGoalEdit: ModalData;
  13. let mdGoalDelete: ModalData;
  14. let msLength: number;
  15. let msElapsed: number;
  16. let now = Date.now();
  17. $: mdGoalEdit = {name:"goal.edit", goal};
  18. $: mdGoalDelete = {name:"goal.delete", goal};
  19. $: {
  20. const start = Date.parse(goal.startTime)
  21. const length = Date.parse(goal.endTime) - start;
  22. msLength = length;
  23. msElapsed = 0;
  24. if (now > start) {
  25. if (now > start + length) {
  26. msElapsed = length;
  27. } else {
  28. msElapsed = Math.round(now - start);
  29. }
  30. }
  31. }
  32. </script>
  33. <EveryMinute bind:now={now} />
  34. <ParentEntry
  35. full={showAllOptions}
  36. entry={goal}
  37. headerLink={linkGoal ? "/goals#"+goal.id : ""}
  38. >
  39. {#if showAllOptions}
  40. <OptionRow>
  41. <Option open={mdGoalEdit}>Edit</Option>
  42. <Option open={mdGoalDelete}>Delete</Option>
  43. </OptionRow>
  44. {/if}
  45. <div class="progress">
  46. <Progress count={goal.completedAmount} target={goal.amount} />
  47. <Progress thinner gray count={msElapsed} target={msLength} titleTime />
  48. </div>
  49. </ParentEntry>
  50. <style>
  51. div.progress {
  52. padding-top: 0.125em;
  53. font-size: 1.25em;
  54. }
  55. </style>