Skip to content

Commit

Permalink
changed reset, added check optional
Browse files Browse the repository at this point in the history
  • Loading branch information
KurosawaAngel committed May 24, 2024
1 parent 5734a6f commit 4c822ef
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/aiogram_dialog/widgets/kbd/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def __call__(
event: ChatEvent,
select: ManagedT, # noqa: F841
dialog_manager: DialogManager,
data: T,
data: Optional[T],
/,
):
raise NotImplementedError
Expand Down Expand Up @@ -252,11 +252,14 @@ def _get_checked(self, manager: DialogManager) -> Optional[str]:
return self.get_widget_data(manager, None)

async def set_checked(
self, event: ChatEvent, item_id: T,
self, event: ChatEvent, item_id: Optional[T],
manager: DialogManager,
) -> None:
checked = self._get_checked(manager)
item_id_str = str(item_id)
if item_id is None:
item_id_str = None
else:
item_id_str = str(item_id)
self.set_widget_data(manager, item_id_str)
if checked != item_id_str:
await self._process_on_state_changed(event, item_id_str, manager)
Expand Down Expand Up @@ -297,11 +300,7 @@ def get_checked(self) -> Optional[T]:
"""Get an id of selected item."""
return self.widget.get_checked(self.manager)

def reset_checked(self) -> None:
"""Reset which item is selected."""
return self.widget.set_widget_data(self.manager, None)

async def set_checked(self, item_id: T):
async def set_checked(self, item_id: Optional[T]) -> None:
"""Get set which item is selected."""
return await self.widget.set_checked(
self.manager.event, item_id, self.manager,
Expand Down

0 comments on commit 4c822ef

Please sign in to comment.