Toggling view modes

This commit is contained in:
2023-11-24 00:38:13 +00:00
parent 77dda92301
commit e3e68b89ee
2 changed files with 47 additions and 20 deletions

View File

@@ -5,6 +5,17 @@ defmodule WishWeb.HomeLive.Index do
@impl true
def mount(_params, _session, socket) do
{:ok, stream(socket, :items, Wishlist.list_items())}
{:ok, assign(socket, :items, Wishlist.list_items()) |> assign(:display, :grid)}
end
@impl true
def handle_event("toggle", _, socket) do
new_state =
case socket.assigns.display do
:row -> :grid
:grid -> :row
end
{:noreply, assign(socket, :display, new_state)}
end
end