Add toggling stuff
This commit is contained in:
@@ -19,7 +19,7 @@ defmodule WishWeb.HomeLive.Index do
|
|||||||
Wishlist.list_available_items()
|
Wishlist.list_available_items()
|
||||||
end
|
end
|
||||||
|
|
||||||
{:ok, assign(socket, :items, items) |> assign(:grid, grid?)}
|
{:ok, assign(socket, :items, items) |> assign(:grid, grid?) |> assign(:hidden, false)}
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
@@ -27,6 +27,20 @@ defmodule WishWeb.HomeLive.Index do
|
|||||||
{:noreply, assign(socket, :grid, !socket.assigns.grid)}
|
{:noreply, assign(socket, :grid, !socket.assigns.grid)}
|
||||||
end
|
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
|
@impl true
|
||||||
def handle_event("toggle_received", %{"id" => id}, socket) do
|
def handle_event("toggle_received", %{"id" => id}, socket) do
|
||||||
item = Wishlist.get_item!(id)
|
item = Wishlist.get_item!(id)
|
||||||
|
|||||||
@@ -5,7 +5,21 @@
|
|||||||
JS.push("toggle_view_state")
|
JS.push("toggle_view_state")
|
||||||
|> JS.dispatch("toggle_view_state", detail: %{"grid" => !@grid})
|
|> 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>
|
</.button>
|
||||||
</:actions>
|
</:actions>
|
||||||
</.header>
|
</.header>
|
||||||
|
|||||||
Reference in New Issue
Block a user