Skip to content

Commit

Permalink
fix: Fixing section 11.2 on readme. #54
Browse files Browse the repository at this point in the history
  • Loading branch information
LuchoTurtle committed Dec 8, 2022
1 parent d56ba62 commit 12e0c1c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 49 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2239,7 +2239,7 @@ that creates
in the user's mind.
Let's fix it!

Open your `lib/app_web/views/item_view.ex` file
Open your `lib/app_web/controllers/item_html.ex` file
and add the following function definition `unarchived_items/1`:

```elixir
Expand Down
4 changes: 4 additions & 0 deletions lib/app_web/controllers/item_html.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ defmodule AppWeb.ItemHTML do
false -> "item"
end
end

def got_items?(items) do
Enum.filter(items, fn i -> i.status < 2 end) |> Enum.count > 0
end
end
98 changes: 50 additions & 48 deletions lib/app_web/controllers/item_html/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -55,54 +55,56 @@
<% end %>
</ul>
</section>
<footer class="footer" style="display: block;">
<span class="todo-count">
<%= remaining_items(@items) %> <%= pluralise(@items) %> left
</span>
<ul class="filters">
<%= if got_items?(@items) do %>
<footer class="footer" style="display: block;">
<span class="todo-count">
<%= remaining_items(@items) %> <%= pluralise(@items) %> left
</span>
<ul class="filters">

<li>
<%= if @filter == "items" do %>
<a href="/items" class='selected'>
All
</a>
<% else %>
<a href="/items">
All
</a>
<% end %>
</li>
<li>
<%= if @filter == "active" do %>
<a href="/items/active" class='selected'>
Active
[<%= Enum.count(filter(@items, "active")) %>]
</a>
<% else %>
<a href="/items/active">
Active
[<%= Enum.count(filter(@items, "active")) %>]
</a>
<% end %>
</li>
<li>
<%= if @filter == "completed" do %>
<a href="/items/completed" class='selected'>
Completed
[<%= Enum.count(filter(@items, "completed")) %>]
</a>
<% else %>
<a href="/items/completed">
Completed
[<%= Enum.count(filter(@items, "completed")) %>]
</a>
<% end %>
</li>
<li>
<%= if @filter == "items" do %>
<a href="/items" class='selected'>
All
</a>
<% else %>
<a href="/items">
All
</a>
<% end %>
</li>
<li>
<%= if @filter == "active" do %>
<a href="/items/active" class='selected'>
Active
[<%= Enum.count(filter(@items, "active")) %>]
</a>
<% else %>
<a href="/items/active">
Active
[<%= Enum.count(filter(@items, "active")) %>]
</a>
<% end %>
</li>
<li>
<%= if @filter == "completed" do %>
<a href="/items/completed" class='selected'>
Completed
[<%= Enum.count(filter(@items, "completed")) %>]
</a>
<% else %>
<a href="/items/completed">
Completed
[<%= Enum.count(filter(@items, "completed")) %>]
</a>
<% end %>
</li>

</ul>
<a class="clear-completed" href="/items/clear">
Clear completed
[<%= Enum.count(filter(@items, "completed")) %>]
</a>
</footer>
</ul>
<a class="clear-completed" href="/items/clear">
Clear completed
[<%= Enum.count(filter(@items, "completed")) %>]
</a>
</footer>
<% end %>
</section>

0 comments on commit 12e0c1c

Please sign in to comment.