Skip to content

Commit

Permalink
fix a bug when choices have the same name
Browse files Browse the repository at this point in the history
  • Loading branch information
AiroPi committed Mar 23, 2024
1 parent 2022af3 commit 3535990
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
target: production
develop:
watch:
- action: sync+restart
- action: sync
path: ./src
target: /app
- action: rebuild
Expand Down
13 changes: 4 additions & 9 deletions src/cogs/poll/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,26 +360,21 @@ class RemoveChoices(SubMenu[EditChoices]):
async def __init__(self, parent: EditChoices) -> None:
await super().__init__(parent=parent)
self.old_value = self.parent.poll.choices.copy()
print(self.old_value)
self.linked_choice = {choice: i for i, choice in enumerate(self.old_value)}

self.choices_to_remove.placeholder = _("Select the choices you want to remove.", _l=100)
for choice, i in self.linked_choice.items():
for i, choice in enumerate(self.old_value):
label = choice.label[:99] + "…" if len(choice.label) > 100 else choice.label
self.choices_to_remove.add_option(label=label, value=str(i), emoji=LEGEND_EMOJIS[i])
self.choices_to_remove.max_values = len(self.old_value) - 2
self.choices_to_remove.min_values = 0

async def update(self):
for option in self.choices_to_remove.options:
option.default = option.value in self.choices_to_remove.values
for i, option in enumerate(self.choices_to_remove.options):
option.default = str(i) in self.choices_to_remove.values

@ui.select(cls=ui.Select[Self])
async def choices_to_remove(self, inter: Interaction, select: ui.Select[Self]):
# warning: corresponding answers are not removed from the database
self.parent.poll.choices = [
choice for choice in self.old_value if str(self.linked_choice[choice]) not in select.values
]
self.parent.poll.choices = [choice for i, choice in enumerate(self.old_value) if str(i) not in select.values]
await self.update()
await self.parent.update_poll_display(inter, view=self)

Expand Down
1 change: 1 addition & 0 deletions src/core/view_menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ async def __init__(
self.validate_btn.label = _("Validate")

async def set_back(self, inter: Interaction) -> None:
await self.parent.update()
await inter.response.edit_message(**(await self.parent.message_display()), view=self.parent)

async def cancel(self):
Expand Down

0 comments on commit 3535990

Please sign in to comment.