toggle by setting date instead of bool

This commit is contained in:
Jonathan Jenne 2022-06-20 21:41:34 +02:00
parent 7844996672
commit ee369a32d6
2 changed files with 13 additions and 2 deletions

View File

@ -14,6 +14,15 @@
const tag = e.srcElement.dataset.tag
dispatch('filter', tag)
}
function noteTime(note) {
console.log(note)
if (note.done) {
return time(note.done)
} else if(note.created) {
return time(note.created)
}
}
</script>
<article class="note flex" class:done={note.done} class:todo={!note.done}>
@ -21,12 +30,12 @@
{note.title}
</div>
<div>{noteTime(note)}</div>
<aside class="tags">
{#each note.tags as tag}
<a href={`/tag/${tag}`} data-tag={tag} on:click={filterByTag}>#{tag}</a>
{/each}
</aside>
</article>
<style>

View File

@ -43,10 +43,12 @@ export function applyFilterSort(notes, filter) {
export function toggleDoneState(notes, id) {
return notes.map(note => {
if (note.created === id) {
const done = note.done ? null : Date.now()
// return a new object
return {
...note,
done: !note.done
done
};
}