Toggling view modes
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user