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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from datetime import datetime, date
|
| 3 |
+
import utils
|
| 4 |
+
import json
|
| 5 |
+
|
| 6 |
+
# Set page config
|
| 7 |
+
st.set_page_config(
|
| 8 |
+
page_title="Todo App",
|
| 9 |
+
page_icon="β
",
|
| 10 |
+
layout="wide",
|
| 11 |
+
initial_sidebar_state="expanded"
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
# Initialize session state
|
| 15 |
+
if 'todos' not in st.session_state:
|
| 16 |
+
st.session_state.todos = []
|
| 17 |
+
if 'filter' not in st.session_state:
|
| 18 |
+
st.session_state.filter = 'all'
|
| 19 |
+
if 'editing_id' not in st.session_state:
|
| 20 |
+
st.session_state.editing_id = None
|
| 21 |
+
|
| 22 |
+
def main():
|
| 23 |
+
# Header with link
|
| 24 |
+
col1, col2, col3 = st.columns([1, 2, 1])
|
| 25 |
+
with col2:
|
| 26 |
+
st.markdown("""
|
| 27 |
+
<div style='text-align: center; padding: 20px;'>
|
| 28 |
+
<h1>π Todo App</h1>
|
| 29 |
+
<p style='font-size: 14px; color: #666;'>Built with <a href='https://huggingface.co/spaces/akhaliq/anycoder' target='_blank'>anycoder</a></p>
|
| 30 |
+
</div>
|
| 31 |
+
""", unsafe_allow_html=True)
|
| 32 |
+
|
| 33 |
+
# Sidebar for filters and stats
|
| 34 |
+
with st.sidebar:
|
| 35 |
+
st.header("π Statistics")
|
| 36 |
+
stats = utils.get_todo_stats(st.session_state.todos)
|
| 37 |
+
st.metric("Total Tasks", stats['total'])
|
| 38 |
+
st.metric("Completed", stats['completed'])
|
| 39 |
+
st.metric("Pending", stats['pending'])
|
| 40 |
+
completion_rate = (stats['completed'] / stats['total'] * 100) if stats['total'] > 0 else 0
|
| 41 |
+
st.metric("Completion Rate", f"{completion_rate:.1f}%")
|
| 42 |
+
|
| 43 |
+
st.divider()
|
| 44 |
+
|
| 45 |
+
st.header("π Filter Tasks")
|
| 46 |
+
filter_option = st.radio(
|
| 47 |
+
"Show:",
|
| 48 |
+
['All Tasks', 'Active Tasks', 'Completed Tasks'],
|
| 49 |
+
index=['all', 'active', 'completed'].index(st.session_state.filter)
|
| 50 |
+
)
|
| 51 |
+
st.session_state.filter = ['all', 'active', 'completed'][['All Tasks', 'Active Tasks', 'Completed Tasks'].index(filter_option)]
|
| 52 |
+
|
| 53 |
+
st.divider()
|
| 54 |
+
|
| 55 |
+
st.header("π― Priority")
|
| 56 |
+
priority_filter = st.multiselect(
|
| 57 |
+
"Filter by priority:",
|
| 58 |
+
['High', 'Medium', 'Low'],
|
| 59 |
+
default=['High', 'Medium', 'Low']
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
st.divider()
|
| 63 |
+
|
| 64 |
+
if st.button("ποΈ Clear Completed", type="secondary"):
|
| 65 |
+
st.session_state.todos = utils.clear_completed_todos(st.session_state.todos)
|
| 66 |
+
st.rerun()
|
| 67 |
+
|
| 68 |
+
# Main content area
|
| 69 |
+
col1, col2 = st.columns([2, 1])
|
| 70 |
+
|
| 71 |
+
with col1:
|
| 72 |
+
st.header("π Task List")
|
| 73 |
+
|
| 74 |
+
# Search bar
|
| 75 |
+
search_query = st.text_input("π Search tasks...", placeholder="Type to search...")
|
| 76 |
+
|
| 77 |
+
# Filter and search todos
|
| 78 |
+
filtered_todos = utils.filter_todos(st.session_state.todos, st.session_state.filter, search_query, priority_filter)
|
| 79 |
+
|
| 80 |
+
if not filtered_todos:
|
| 81 |
+
st.info("No tasks found. Add a new task to get started!")
|
| 82 |
+
else:
|
| 83 |
+
for todo in filtered_todos:
|
| 84 |
+
with st.container():
|
| 85 |
+
col_task, col_actions = st.columns([4, 1])
|
| 86 |
+
|
| 87 |
+
with col_task:
|
| 88 |
+
# Create a unique key for each todo
|
| 89 |
+
key = f"todo_{todo['id']}"
|
| 90 |
+
|
| 91 |
+
# Display todo based on whether it's being edited
|
| 92 |
+
if st.session_state.editing_id == todo['id']:
|
| 93 |
+
# Edit mode
|
| 94 |
+
edited_text = st.text_input(
|
| 95 |
+
"Edit task:",
|
| 96 |
+
value=todo['text'],
|
| 97 |
+
key=f"edit_{todo['id']}"
|
| 98 |
+
)
|
| 99 |
+
edited_priority = st.selectbox(
|
| 100 |
+
"Priority:",
|
| 101 |
+
['High', 'Medium', 'Low'],
|
| 102 |
+
index=['High', 'Medium', 'Low'].index(todo['priority']),
|
| 103 |
+
key=f"priority_{todo['id']}"
|
| 104 |
+
)
|
| 105 |
+
edited_date = st.date_input(
|
| 106 |
+
"Due date:",
|
| 107 |
+
value=datetime.strptime(todo['due_date'], '%Y-%m-%d').date(),
|
| 108 |
+
key=f"date_{todo['id']}"
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
col_save, col_cancel = st.columns(2)
|
| 112 |
+
with col_save:
|
| 113 |
+
if st.button("πΎ Save", key=f"save_{todo['id']}", type="primary"):
|
| 114 |
+
st.session_state.todos = utils.update_todo(
|
| 115 |
+
st.session_state.todos,
|
| 116 |
+
todo['id'],
|
| 117 |
+
edited_text,
|
| 118 |
+
edited_priority,
|
| 119 |
+
edited_date.strftime('%Y-%m-%d')
|
| 120 |
+
)
|
| 121 |
+
st.session_state.editing_id = None
|
| 122 |
+
st.rerun()
|
| 123 |
+
with col_cancel:
|
| 124 |
+
if st.button("β Cancel", key=f"cancel_{todo['id']}"):
|
| 125 |
+
st.session_state.editing_id = None
|
| 126 |
+
st.rerun()
|
| 127 |
+
else:
|
| 128 |
+
# Display mode
|
| 129 |
+
completed = st.checkbox(
|
| 130 |
+
todo['text'],
|
| 131 |
+
value=todo['completed'],
|
| 132 |
+
key=f"check_{todo['id']}",
|
| 133 |
+
help=f"Priority: {todo['priority']} | Due: {todo['due_date']}"
|
| 134 |
+
)
|
| 135 |
+
if completed != todo['completed']:
|
| 136 |
+
st.session_state.todos = utils.toggle_todo(st.session_state.todos, todo['id'])
|
| 137 |
+
st.rerun()
|
| 138 |
+
|
| 139 |
+
# Show priority and due date
|
| 140 |
+
priority_color = {'High': 'π΄', 'Medium': 'π‘', 'Low': 'π’'}
|
| 141 |
+
st.markdown(
|
| 142 |
+
f"<small style='color: #666;'>{priority_color[todo['priority']]} {todo['priority']} Priority | π
Due: {todo['due_date']}</small>",
|
| 143 |
+
unsafe_allow_html=True
|
| 144 |
+
)
|
| 145 |
+
|
| 146 |
+
with col_actions:
|
| 147 |
+
if not todo['completed'] and st.session_state.editing_id != todo['id']:
|
| 148 |
+
if st.button("βοΈ", key=f"edit_btn_{todo['id']}", help="Edit task"):
|
| 149 |
+
st.session_state.editing_id = todo['id']
|
| 150 |
+
st.rerun()
|
| 151 |
+
if st.button("ποΈ", key=f"delete_{todo['id']}", help="Delete task"):
|
| 152 |
+
st.session_state.todos = utils.delete_todo(st.session_state.todos, todo['id'])
|
| 153 |
+
st.rerun()
|
| 154 |
+
|
| 155 |
+
st.divider()
|
| 156 |
+
|
| 157 |
+
with col2:
|
| 158 |
+
st.header("β Add New Task")
|
| 159 |
+
|
| 160 |
+
with st.form("add_todo_form"):
|
| 161 |
+
task_text = st.text_area(
|
| 162 |
+
"Task description:",
|
| 163 |
+
placeholder="Enter your task here...",
|
| 164 |
+
height=100
|
| 165 |
+
)
|
| 166 |
+
|
| 167 |
+
priority = st.selectbox(
|
| 168 |
+
"Priority:",
|
| 169 |
+
['High', 'Medium', 'Low'],
|
| 170 |
+
index=1
|
| 171 |
+
)
|
| 172 |
+
|
| 173 |
+
due_date = st.date_input(
|
| 174 |
+
"Due date:",
|
| 175 |
+
value=date.today()
|
| 176 |
+
)
|
| 177 |
+
|
| 178 |
+
submit_button = st.form_submit_button("Add Task", type="primary")
|
| 179 |
+
|
| 180 |
+
if submit_button and task_text.strip():
|
| 181 |
+
new_todo = utils.create_todo(
|
| 182 |
+
task_text.strip(),
|
| 183 |
+
priority,
|
| 184 |
+
due_date.strftime('%Y-%m-%d')
|
| 185 |
+
)
|
| 186 |
+
st.session_state.todos.append(new_todo)
|
| 187 |
+
st.rerun()
|
| 188 |
+
st.success("Task added successfully!")
|
| 189 |
+
|
| 190 |
+
st.divider()
|
| 191 |
+
|
| 192 |
+
st.header("π Progress")
|
| 193 |
+
if stats['total'] > 0:
|
| 194 |
+
# Progress bar
|
| 195 |
+
progress_value = stats['completed'] / stats['total']
|
| 196 |
+
st.progress(progress_value)
|
| 197 |
+
st.caption(f"{stats['completed']} of {stats['total']} tasks completed")
|
| 198 |
+
|
| 199 |
+
# Priority breakdown
|
| 200 |
+
st.subheader("Priority Breakdown")
|
| 201 |
+
priority_stats = utils.get_priority_stats(st.session_state.todos)
|
| 202 |
+
for priority in ['High', 'Medium', 'Low']:
|
| 203 |
+
if priority_stats[priority] > 0:
|
| 204 |
+
st.write(f"π΄ {priority}: {priority_stats[priority]} tasks")
|
| 205 |
+
|
| 206 |
+
# Footer
|
| 207 |
+
st.markdown("---")
|
| 208 |
+
st.markdown(
|
| 209 |
+
"<div style='text-align: center; color: #666; font-size: 12px;'>"
|
| 210 |
+
"π‘ Tip: Click on a task to mark it complete, use the edit button to modify, or delete when done!"
|
| 211 |
+
"</div>",
|
| 212 |
+
unsafe_allow_html=True
|
| 213 |
+
)
|
| 214 |
+
|
| 215 |
+
if __name__ == "__main__":
|
| 216 |
+
main()
|