Build a Todo App
Welcome to the "Build a Todo App" tutorial! In this section, we're going to create a dynamic Todo App together. Imagine our wind turbine technicians being able to manage their tasks efficiently with this application. We'll collaborate to develop an app with features like:
Adding, removing, and clearing tasks
Marking tasks as completed
Tracking the number of completed tasks
Dynamically disabling or hiding buttons
Previously, we built a basic todo app using a function-based approach. This time, we'll employ a more sophisticated Parameterized
class-based approach. This method will enhance the extensibility and maintainability of our todo app in the long run.
:::{dropdown} Requirements
:::
:::{dropdown} Code
:::
Explanation
Let's break down the todo app.
Import Necessary Libraries
Here, we import the required libraries for our task management app. We use List
from the typing
module to define a list of tasks, param
for declaring parameters, and panel
for creating the user interface. We configure the "material"
design to give the todo app a modern look and feel.
Define Constants
We set a constant BUTTON_WIDTH
to control the width of buttons in our app.
Define Task Model
This class defines the model of a task. It has two attributes: value
(description of the task) and completed
(whether the task is completed or not). The __panel__
method renders the task as a row containing a checkbox for completion status and the task description.
Define TaskList Class
This class represents a list of tasks. It provides methods to add and remove tasks, as well as calculate summary statistics such as the total number of tasks, the number of completed tasks, and a status message.
:::{note}
The TaskList
and the rest of the todo app follows the DataStore design pattern introduced in Structure with a DataStore.
:::
Define TaskInput Class
This class represents a widget for users to input tasks.
The __panel__
method defines the appearance and behavior of the task input widget. It consists of a text input field for entering task descriptions and a button to submit the task.
Define TaskRow Class
This method defines the appearance of the task row, which consists of the task description and a button to remove the task.
Define TaskListEditor Class
This class represents a component that allows users to manage a list of tasks.
This __panel__
method defines the appearance and behavior of the task list editor component. It consists of an input field for adding tasks, a list of tasks, and a button to remove all tasks.
Recap
We've built a todo app using a Parameterized
class-based approach and the DataStore design pattern. Now, our wind turbine technicians can manage their tasks efficiently and collaboratively.