Skip to content

Commit 95d21c4

Browse files
committed
views: Add PollResultsView class.
Takes poll_question and options as an input and displays voters for each option.
1 parent f5d32aa commit 95d21c4

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

zulipterminal/ui_tools/views.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from zulipterminal.config.symbols import (
2424
CHECK_MARK,
2525
COLUMN_TITLE_BAR_LINE,
26+
INVALID_MARKER,
2627
PINNED_STREAMS_DIVIDER,
2728
SECTION_DIVIDER_LINE,
2829
)
@@ -2172,3 +2173,37 @@ def keypress(self, size: urwid_Size, key: str) -> str:
21722173
self.controller.exit_popup()
21732174
return key
21742175
return super().keypress(size, key)
2176+
2177+
2178+
class PollResultsView(PopUpView):
2179+
def __init__(
2180+
self,
2181+
controller: Any,
2182+
poll_question: str,
2183+
poll_options: Dict[str, Dict[str, Any]],
2184+
) -> None:
2185+
poll_results_content: List[Tuple[str, List[Tuple[str, str]]]] = [("", [])]
2186+
2187+
for option_key, option_data in poll_options.items():
2188+
option_text = option_data["option"]
2189+
if len(option_text) >= 13:
2190+
option_text = option_text[:10] + "…"
2191+
voter_names = option_data["votes"]
2192+
2193+
voters_display = (
2194+
"\n".join(map(str, voter_names))
2195+
if voter_names
2196+
else f"{INVALID_MARKER} No votes yet"
2197+
)
2198+
2199+
poll_results_content[0][1].append((option_text, voters_display))
2200+
2201+
popup_width, column_widths = self.calculate_table_widths(
2202+
poll_results_content, len(poll_question)
2203+
)
2204+
2205+
widgets = self.make_table_with_categories(poll_results_content, column_widths)
2206+
2207+
super().__init__(
2208+
controller, widgets, "SHOW_POLL_VOTES", popup_width, poll_question
2209+
)

0 commit comments

Comments
 (0)