|
499 | 499 | if (!this.state.newTodo.trim()) return |
500 | 500 |
|
501 | 501 | const now = Date.now() |
| 502 | + const nowIso = new Date().toISOString() |
502 | 503 | const newTodos = [ |
503 | 504 | ...this.state.todos, |
504 | 505 | { |
505 | 506 | '@id': `#${Math.floor(now / 1000)}.${now % 1000}`, |
506 | 507 | '@type': 'Task', |
507 | 508 | title: this.state.newTodo, |
508 | 509 | completed: false, |
509 | | - created: new Date().toISOString() |
| 510 | + created: nowIso, |
| 511 | + updated: nowIso |
510 | 512 | } |
511 | 513 | ] |
512 | 514 |
|
|
522 | 524 | // Only toggle items with @type 'Task' |
523 | 525 | const newTodos = this.state.todos.map(todo => { |
524 | 526 | 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 | + } |
526 | 532 | } |
527 | 533 | return todo |
528 | 534 | }) |
|
645 | 651 | this.state.availableUris[this.state.currentUriIndex] || null |
646 | 652 | const isUsingCustomUrl = !!customTodosUrl |
647 | 653 |
|
| 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 | + |
648 | 661 | return html` |
649 | 662 | <div class="min-h-screen flex flex-col"> |
650 | 663 | <${Navbar} onLogout=${this.handleLogout} /> |
|
835 | 848 | ? html`<p class="text-center text-gray-500"> |
836 | 849 | No tasks yet. Add one above! |
837 | 850 | </p>` |
838 | | - : [...taskItems].reverse().map( |
| 851 | + : sortedTasks.map( |
839 | 852 | todo => html` |
840 | 853 | <div |
841 | 854 | key=${todo['@id']} |
|
943 | 956 | /> |
944 | 957 | </svg> |
945 | 958 | </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 |
947 | 973 | ? html` |
948 | 974 | <span |
949 | 975 | class="ml-2 text-xs text-gray-400" |
|
0 commit comments