Add toggling stuff

This commit is contained in:
2023-12-04 01:05:02 +00:00
parent 09433c76fc
commit 6ca30eb5bb
2 changed files with 30 additions and 2 deletions

View File

@@ -19,7 +19,7 @@ defmodule WishWeb.HomeLive.Index do
Wishlist.list_available_items()
end
{:ok, assign(socket, :items, items) |> assign(:grid, grid?)}
{:ok, assign(socket, :items, items) |> assign(:grid, grid?) |> assign(:hidden, false)}
end
@impl true
@@ -27,6 +27,20 @@ defmodule WishWeb.HomeLive.Index do
{:noreply, assign(socket, :grid, !socket.assigns.grid)}
end
@impl true
def handle_event("toggle_hidden_items", _, socket) do
new_state = !socket.assigns.hidden
items =
if new_state do
Wishlist.list_items()
else
Wishlist.list_available_items()
end
{:noreply, assign(socket, :items, items) |> assign(:hidden, new_state)}
end
@impl true
def handle_event("toggle_received", %{"id" => id}, socket) do
item = Wishlist.get_item!(id)

View File

@@ -5,7 +5,21 @@
JS.push("toggle_view_state")
|> JS.dispatch("toggle_view_state", detail: %{"grid" => !@grid})
}>
Toggle List/Grid
<%= if @grid do %>
List View
<% else %>
Grid View
<% end %>
</.button>
</:actions>
<:actions :if={!@current_user}>
<.button phx-click={JS.push("toggle_hidden_items")}>
<%= if @hidden do %>
Hide
<% else %>
Show
<% end %>
Received
</.button>
</:actions>
</.header>