defmodule BeetRoundServerWeb.BiddingLive.Index do use BeetRoundServerWeb, :live_view alias BeetRoundServer.Biddings @impl true def render(assigns) do ~H""" <.header> Listing Biddings <:actions> <.button variant="primary" navigate={~p"/biddings/new"}> <.icon name="hero-plus" /> New Bidding <.table id="biddings" rows={@streams.biddings} row_click={fn {_id, bidding} -> JS.navigate(~p"/biddings/#{bidding}") end} > <:col :let={{_id, bidding}} label="Bidding round">{bidding.bidding_round} <:col :let={{_id, bidding}} label="Amount">{bidding.amount} <:col :let={{_id, bidding}} label="Depot wish one">{bidding.depot_wish_one} <:col :let={{_id, bidding}} label="Depot wish two">{bidding.depot_wish_two} <:action :let={{_id, bidding}}>
<.link navigate={~p"/biddings/#{bidding}"}>Show
<.link navigate={~p"/biddings/#{bidding}/edit"}>Edit <:action :let={{id, bidding}}> <.link phx-click={JS.push("delete", value: %{id: bidding.id}) |> hide("##{id}")} data-confirm="Are you sure?" > Delete
""" end @impl true def mount(_params, _session, socket) do if connected?(socket) do Biddings.subscribe_biddings(socket.assigns.current_scope) end {:ok, socket |> assign(:page_title, "Listing Biddings") |> stream(:biddings, list_biddings(socket.assigns.current_scope))} end @impl true def handle_event("delete", %{"id" => id}, socket) do bidding = Biddings.get_bidding!(socket.assigns.current_scope, id) {:ok, _} = Biddings.delete_bidding(socket.assigns.current_scope, bidding) {:noreply, stream_delete(socket, :biddings, bidding)} end @impl true def handle_info({type, %BeetRoundServer.Biddings.Bidding{}}, socket) when type in [:created, :updated, :deleted] do {:noreply, stream(socket, :biddings, list_biddings(socket.assigns.current_scope), reset: true)} end defp list_biddings(current_scope) do Biddings.list_biddings(current_scope) end end