Skip to content

Commit c3a6099

Browse files
add updated
1 parent f05c14a commit c3a6099

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

todo.html

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,14 +499,16 @@
499499
if (!this.state.newTodo.trim()) return
500500

501501
const now = Date.now()
502+
const nowIso = new Date().toISOString()
502503
const newTodos = [
503504
...this.state.todos,
504505
{
505506
'@id': `#${Math.floor(now / 1000)}.${now % 1000}`,
506507
'@type': 'Task',
507508
title: this.state.newTodo,
508509
completed: false,
509-
created: new Date().toISOString()
510+
created: nowIso,
511+
updated: nowIso
510512
}
511513
]
512514

@@ -522,7 +524,11 @@
522524
// Only toggle items with @type 'Task'
523525
const newTodos = this.state.todos.map(todo => {
524526
if (todo['@id'] === id && todo['@type'] === 'Task') {
525-
return { ...todo, completed: !todo.completed }
527+
return {
528+
...todo,
529+
completed: !todo.completed,
530+
updated: new Date().toISOString()
531+
}
526532
}
527533
return todo
528534
})
@@ -645,6 +651,13 @@
645651
this.state.availableUris[this.state.currentUriIndex] || null
646652
const isUsingCustomUrl = !!customTodosUrl
647653

654+
// Sort tasks by updated date (falling back to created date)
655+
const sortedTasks = [...taskItems].sort((a, b) => {
656+
const aDate = a.updated || a.created || ''
657+
const bDate = b.updated || b.created || ''
658+
return new Date(bDate) - new Date(aDate)
659+
})
660+
648661
return html`
649662
<div class="min-h-screen flex flex-col">
650663
<${Navbar} onLogout=${this.handleLogout} />
@@ -835,7 +848,7 @@
835848
? html`<p class="text-center text-gray-500">
836849
No tasks yet. Add one above!
837850
</p>`
838-
: [...taskItems].reverse().map(
851+
: sortedTasks.map(
839852
todo => html`
840853
<div
841854
key=${todo['@id']}
@@ -943,7 +956,20 @@
943956
/>
944957
</svg>
945958
</a>
946-
${todo.created
959+
${todo.updated &&
960+
todo.updated !== todo.created
961+
? html`
962+
<span
963+
class="ml-2 text-xs text-gray-400"
964+
title="Last updated"
965+
>
966+
(updated:
967+
${new Date(
968+
todo.updated
969+
).toLocaleDateString()})
970+
</span>
971+
`
972+
: todo.created
947973
? html`
948974
<span
949975
class="ml-2 text-xs text-gray-400"

0 commit comments

Comments
 (0)