Adding the final touches
Our to-do app is complete. However, we can make it even better by adding a few more features.
Adding pagination to the to-do list
If we go back to the to-do list, we can see that now we have a lot of data. It’s getting hard to navigate through the list. Let’s add pagination to make the data more manageable.
First, let’s compute the pagination data, calculating the total number of pages and the logic for the previous and next buttons. In the TodosController.jl
file, add the following:
const TODOS_PER_PAGE = 20 const PAGINATION_DISPLAY_INTERVAL = 5 const MAX_PAGINATION_WIDTH = 30 page() = parse(Int, params(:page, "1")) function count_pages() total_pages = count(Todo, user_id = current_user_id()) / TODOS_PER_PAGE |> ceil |> Int current_page = page() ...