From 9b54f05d75e9a63b03018294c992b2d42ad10709 Mon Sep 17 00:00:00 2001
From: Remy Moll <me@moll.re>
Date: Tue, 10 Oct 2023 17:08:58 +0200
Subject: [PATCH] toggle option shows current status

---
 bot/commands/list/list.py | 50 ++++++++++++++++++++++++++-------------
 1 file changed, 33 insertions(+), 17 deletions(-)

diff --git a/bot/commands/list/list.py b/bot/commands/list/list.py
index 484206d..c0b0c78 100644
--- a/bot/commands/list/list.py
+++ b/bot/commands/list/list.py
@@ -123,10 +123,17 @@ class ListHandler(BaseHandler):
         await query.answer()
 
         list_object = context.user_data["current_list"]
-        keyboard = [[InlineKeyboardButton(v, callback_data=k)] for k,v in list_object.content.items()]
-        reply_markup = InlineKeyboardMarkup(keyboard)
+        readable_it = printable_list(list_object)
+       
+        if readable_it:
+            msg_content = "Which item would you like to toggle?"
+            keyboard = [[InlineKeyboardButton(v, callback_data=k)] for k,v in zip(list_object.content.keys(), readable_it)]
+            reply_markup = InlineKeyboardMarkup(keyboard)
+        else:
+            msg_content = "List empty"
+            reply_markup = None
 
-        await query.edit_message_text("Which item would you like to toggle?", reply_markup = reply_markup)
+        await query.edit_message_text(msg_content, reply_markup = reply_markup)
         return ITEMTOGGLE
 
 
@@ -168,20 +175,10 @@ class ListHandler(BaseHandler):
         await query.answer()
         list_object = context.user_data["current_list"]
 
-        content_it = list_object.content.values()
-        # distinguish the enumeration:
-        # either all done_dict values are None -> the list is not toggleable
-        # or at least one value is of type bool -> the list is toggleable and None === False
-        if any([type(e) == bool for e in list_object.done_dict.values()]):
-            done_it = [
-            "✅ " if e else "❌ " \
-            for e in list_object.done_dict.values()
-            ]
-        else:
-            done_it = [". " for e in list_object.done_dict]
-
-        if content_it:
-            msg_content = "\n".join([f"{d} {c}" for d, c in zip(done_it, content_it)])
+        readable_it = printable_list(list_object)
+       
+        if readable_it:
+            msg_content = "\n".join(readable_it)
         else:
             msg_content = "List empty"
         
@@ -238,3 +235,22 @@ class ListHandler(BaseHandler):
 
         await query.edit_message_text(f"Removed {name}", reply_markup=reply_markup)
         return ACTION
+
+
+
+def printable_list(list_object: ListModel):
+    content_it = list_object.content.values()
+    done_bool_it = list_object.done_dict.values()
+    # distinguish the enumeration:
+    # either all done_dict values are None -> the list is not toggleable
+    # or at least one value is of type bool -> the list is toggleable and None === False
+    if any([type(e) == bool for e in done_bool_it]):
+        done_it = [
+        "✅" if e else "❌" \
+        for e in list_object.done_dict.values()
+        ]
+    else:
+        done_it = ["-" for e in done_bool_it]
+    
+    readable_it = [f"{d} {c}" for d, c in zip(done_it, content_it)]
+    return readable_it