Skip to content

Commit

Permalink
Fix checking todo item that dont support due date (#19262)
Browse files Browse the repository at this point in the history
* Fix checking todo item that dont support due date

* make cleaner

* Revert "make cleaner"

This reverts commit fa33b33.

* Update dialog-todo-item-editor.ts

* do check in 1 place
  • Loading branch information
bramkragten authored Jan 3, 2024
1 parent acbb7e0 commit 8368fb4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
12 changes: 9 additions & 3 deletions src/data/todo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,12 @@ export const updateItem = (
item: item.uid,
rename: item.summary,
status: item.status,
description: item.description || null,
description: item.description,
due_datetime: item.due?.includes("T") ? item.due : undefined,
due_date: item.due?.includes("T") ? undefined : item.due || null,
due_date:
item.due === undefined || item.due?.includes("T")
? undefined
: item.due,
},
{ entity_id }
);
Expand All @@ -102,7 +105,10 @@ export const createItem = (
item: item.summary,
description: item.description || undefined,
due_datetime: item.due?.includes("T") ? item.due : undefined,
due_date: item.due?.includes("T") ? undefined : item.due,
due_date:
item.due === undefined || item.due?.includes("T")
? undefined
: item.due,
},
{ entity_id }
);
Expand Down
3 changes: 2 additions & 1 deletion src/panels/lovelace/cards/hui-todo-list-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,8 @@ export class HuiTodoListCard extends LitElement implements LovelaceCard {
return;
}
await updateItem(this.hass!, this._entityId!, {
...item,
uid: item.uid,
summary: item.summary,
status:
item.status === TodoItemStatus.NeedsAction
? TodoItemStatus.Completed
Expand Down
12 changes: 9 additions & 3 deletions src/panels/todo/dialog-todo-item-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,20 @@ class DialogTodoItemEditor extends LitElement {
(this._todoListSupportsFeature(
TodoListEntityFeature.SET_DESCRIPTION_ON_ITEM
)
? // backend should accept null to clear the field, but it doesn't now
null
? null
: undefined),
due: this._due
? this._hasTime
? this._due.toISOString()
: this._formatDate(this._due)
: null,
: this._todoListSupportsFeature(
TodoListEntityFeature.SET_DUE_DATETIME_ON_ITEM
) ||
this._todoListSupportsFeature(
TodoListEntityFeature.SET_DUE_DATE_ON_ITEM
)
? null
: undefined,
status: this._checked
? TodoItemStatus.Completed
: TodoItemStatus.NeedsAction,
Expand Down

0 comments on commit 8368fb4

Please sign in to comment.