Skip to content

Commit

Permalink
fix: Fixing order of todos on completion. #54
Browse files Browse the repository at this point in the history
  • Loading branch information
LuchoTurtle committed Dec 7, 2022
1 parent bbaa6ca commit 7f6cb12
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,33 @@ But `onclick` is `JavaScript` and we don't _need_ to resort to `JS`. <br />
The `<a>` (link) is a perfectly semantic non-js approach to toggling
`item.status`.

### 7.6 Maintaining correct order of `todo` items

If you "complete" or revert the operation,
the order of the todos might differ between
these operations.
To keep this consistent,
let's fetch all the `todo` items in the same order.

Inside `lib/app/todo.ex`,
change `list_items/0` to the following.

```elixir
def list_items do
query =
from(
i in Item,
select: i,
order_by: [asc: i.id]
)

Repo.all(query)
end
```

By fetching the `todo` items and ordering them,
we guarantee the UX stays consistent!


<br />

Expand Down

0 comments on commit 7f6cb12

Please sign in to comment.