Skip to content

Commit

Permalink
Add description and due support to todo lists (#19107)
Browse files Browse the repository at this point in the history
  • Loading branch information
bramkragten authored Dec 21, 2023
1 parent 8f07e6f commit 09dcc29
Show file tree
Hide file tree
Showing 7 changed files with 850 additions and 198 deletions.
12 changes: 12 additions & 0 deletions src/components/ha-check-list-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ import { CheckListItemBase } from "@material/mwc-list/mwc-check-list-item-base";
import { styles as controlStyles } from "@material/mwc-list/mwc-control-list-item.css";
import { styles } from "@material/mwc-list/mwc-list-item.css";
import { customElement } from "lit/decorators";
import { fireEvent } from "../common/dom/fire_event";

@customElement("ha-check-list-item")
export class HaCheckListItem extends CheckListItemBase {
async onChange(event) {
super.onChange(event);
fireEvent(this, event.type);
}

static override styles = [
styles,
controlStyles,
Expand All @@ -22,6 +28,12 @@ export class HaCheckListItem extends CheckListItemBase {
margin-inline-start: 0px;
direction: var(--direction);
}
.mdc-deprecated-list-item__meta {
flex-shrink: 0;
}
.mdc-deprecated-list-item__graphic {
margin-top: var(--check-list-item-graphic-margin-top);
}
`,
];
}
Expand Down
21 changes: 18 additions & 3 deletions src/data/todo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ export interface TodoItem {
uid: string;
summary: string;
status: TodoItemStatus;
description?: string;
due?: string;
}

export const enum TodoListEntityFeature {
CREATE_TODO_ITEM = 1,
DELETE_TODO_ITEM = 2,
UPDATE_TODO_ITEM = 4,
MOVE_TODO_ITEM = 8,
SET_DUE_DATE_ON_ITEM = 16,
SET_DUE_DATETIME_ON_ITEM = 32,
SET_DESCRIPTION_ON_ITEM = 64,
}

export const getTodoLists = (hass: HomeAssistant): TodoList[] =>
Expand Down Expand Up @@ -74,20 +79,30 @@ export const updateItem = (
hass.callService(
"todo",
"update_item",
{ item: item.uid, rename: item.summary, status: item.status },
{
item: item.uid,
rename: item.summary,
status: item.status,
description: item.description || undefined,
due_datetime: item.due?.includes("T") ? item.due : undefined,
due_date: item.due?.includes("T") ? undefined : item.due || undefined,
},
{ entity_id }
);

export const createItem = (
hass: HomeAssistant,
entity_id: string,
summary: string
item: Omit<TodoItem, "uid" | "status">
): Promise<ServiceCallResponse> =>
hass.callService(
"todo",
"add_item",
{
item: summary,
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,
},
{ entity_id }
);
Expand Down
Loading

0 comments on commit 09dcc29

Please sign in to comment.