Gisle Aune
4 years ago
2 changed files with 50 additions and 70 deletions
@ -1,93 +1,60 @@ |
|||||
<script lang="ts"> |
<script lang="ts"> |
||||
import type { IconName } from "../external/icons"; |
|
||||
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 DaysLeft from "./DaysLeft.svelte"; |
|
||||
import Icon from "./Icon.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 Progress from "./Progress.svelte"; |
import Progress from "./Progress.svelte"; |
||||
|
|
||||
export let goal: GoalResult = null; |
export let goal: GoalResult = null; |
||||
export let showAllOptions = false; |
export let showAllOptions = false; |
||||
|
export let linkGoal = false; |
||||
|
|
||||
let iconName: IconName = "question"; |
|
||||
let mdGoalEdit: ModalData; |
let mdGoalEdit: ModalData; |
||||
let mdGoalDelete: ModalData; |
let mdGoalDelete: ModalData; |
||||
|
let msLength: number; |
||||
|
let msElapsed: number; |
||||
|
|
||||
$: iconName = goal.group.icon as IconName; |
|
||||
$: mdGoalEdit = {name:"goal.edit", goal}; |
$: mdGoalEdit = {name:"goal.edit", goal}; |
||||
$: mdGoalDelete = {name:"goal.delete", goal}; |
$: mdGoalDelete = {name:"goal.delete", goal}; |
||||
</script> |
|
||||
|
|
||||
<div class="goal" class:full={showAllOptions}> |
|
||||
<div class="icon"><Icon block name={iconName} /></div> |
|
||||
<div class="body"> |
|
||||
<div class="header"> |
|
||||
<div class="name">{goal.name}</div> |
|
||||
<div class="times"> |
|
||||
<DaysLeft startTime={goal.startTime} endTime={goal.endTime} /> |
|
||||
</div> |
|
||||
</div> |
|
||||
{#if showAllOptions} |
|
||||
<div class="description"> |
|
||||
<p>{goal.description}</p> |
|
||||
</div> |
|
||||
<OptionRow> |
|
||||
<Option open={mdGoalEdit}>Edit</Option> |
|
||||
<Option open={mdGoalDelete}>Delete</Option> |
|
||||
</OptionRow> |
|
||||
{/if} |
|
||||
<div class="progress"> |
|
||||
<Progress count={goal.completedAmount} target={goal.amount} /> |
|
||||
</div> |
|
||||
</div> |
|
||||
</div> |
|
||||
|
$: { |
||||
|
const now = Date.now() |
||||
|
const start = Date.parse(goal.startTime) |
||||
|
const length = Date.parse(goal.endTime) - start; |
||||
|
|
||||
<style> |
|
||||
div.goal { |
|
||||
display: flex; |
|
||||
flex-direction: row; |
|
||||
padding-bottom: 0.5em; |
|
||||
} |
|
||||
div.goal.full { |
|
||||
padding-bottom: 1em; |
|
||||
} |
|
||||
div.icon { |
|
||||
font-size: 2em; |
|
||||
padding: 0 0.5ch; |
|
||||
width: 2ch; |
|
||||
padding-top: 0.125em; |
|
||||
color: #333; |
|
||||
} |
|
||||
div.body { |
|
||||
display: flex; |
|
||||
flex-direction: column; |
|
||||
width: 100%; |
|
||||
} |
|
||||
div.header { |
|
||||
display: flex; |
|
||||
flex-direction: row; |
|
||||
} |
|
||||
|
msLength = length; |
||||
|
msElapsed = 0; |
||||
|
|
||||
div.name { |
|
||||
font-size: 1em; |
|
||||
margin: auto 0; |
|
||||
vertical-align: middle; |
|
||||
font-weight: 100; |
|
||||
} |
|
||||
div.times { |
|
||||
margin-left: auto; |
|
||||
margin-right: 0.25ch; |
|
||||
|
if (now > start) { |
||||
|
if (now > start + length) { |
||||
|
msElapsed = length; |
||||
|
} else { |
||||
|
msElapsed = Math.round(now - start); |
||||
|
} |
||||
|
} |
||||
} |
} |
||||
|
</script> |
||||
|
|
||||
|
<ParentEntry |
||||
|
full={showAllOptions} |
||||
|
entry={goal} |
||||
|
headerLink={linkGoal ? "/goals#"+goal.id : ""} |
||||
|
> |
||||
|
{#if showAllOptions} |
||||
|
<OptionRow> |
||||
|
<Option open={mdGoalEdit}>Edit</Option> |
||||
|
<Option open={mdGoalDelete}>Delete</Option> |
||||
|
</OptionRow> |
||||
|
{/if} |
||||
|
<div class="progress"> |
||||
|
<Progress count={goal.completedAmount} target={goal.amount} /> |
||||
|
<Progress thinner gray count={msElapsed} target={msLength} /> |
||||
|
</div> |
||||
|
</ParentEntry> |
||||
|
<style> |
||||
div.progress { |
div.progress { |
||||
padding-top: 0.125em; |
padding-top: 0.125em; |
||||
font-size: 1.25em; |
font-size: 1.25em; |
||||
} |
} |
||||
|
|
||||
div.description > p { |
|
||||
padding: 0; |
|
||||
margin: 0.25em 0; |
|
||||
} |
|
||||
</style> |
</style> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue