Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
Fix checked & reorder
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-codechimp committed Jun 28, 2024
1 parent f5fe6b5 commit 940adda
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
3 changes: 2 additions & 1 deletion custom_components/mealie/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def async_get_shopping_list_items(

params = {"orderBy": "position", "orderDirection": "asc", "perPage": "1000"}
params["group_id"] = group_id
params["queryFilter"] = f"shopping_list_id={shopping_list_id}"
params["queryFilter"] = f"shoppingListId={shopping_list_id}"

return await self.api_wrapper("get", "/api/groups/shopping/items", data=params)

Expand Down Expand Up @@ -79,6 +79,7 @@ async def async_reorder_shopping_list_item(
data["quantity"] = item["quantity"]
data["labelId"] = item["labelId"]
data["note"] = item["note"]
data["checked"] = item["checked"]

if item["isFood"]:
data["foodId"] = item["foodId"]
Expand Down
26 changes: 20 additions & 6 deletions custom_components/mealie/todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,24 @@ async def async_update_todo_item(self, item: TodoItem) -> None:
"""Update an item on the list."""

list_items = self.coordinator.shopping_list_items[self._shopping_list_id]

for list_item in list_items:
if list_item["id"] == item.uid:
list_item["note"] = item.summary
list_item["isFood"] = "False"
list_item["foodId"] = None
list_item["quantity"] = "0.0"
list_item["checked"] = item.status == TodoItemStatus.COMPLETED
position = list_item["position"]
break

list_items = self.coordinator.shopping_list_items[self._shopping_list_id]
for list_item in list_items:
if list_item["id"] == item.uid:
if list_item["display"] == item.summary:
list_item["checked"] = item.status == TodoItemStatus.COMPLETED
else:
list_item["note"] = item.summary
list_item["position"] = position
list_item["isFood"] = "False"
list_item["foodId"] = None
list_item["quantity"] = "0.0"
list_item["checked"] = item.status == TodoItemStatus.COMPLETED

await self.coordinator.api.async_update_shopping_list_item(
self._shopping_list_id, item.uid, list_item
Expand Down Expand Up @@ -189,8 +200,11 @@ async def async_move_todo_item(
if previous_uid is None:
previous_uid_index = -1

if previous_uid_index < old_uid_index:
previous_uid_index += 1

list_items.pop(old_uid_index)
list_items.insert(previous_uid_index + 1, item_to_move)
list_items.insert(previous_uid_index, item_to_move)

position = 0
for item in list_items:
Expand Down

0 comments on commit 940adda

Please sign in to comment.