Files
BeetRoundServer/lib/beet_round_server_web/live/bidding_live/show.ex

68 lines
2.0 KiB
Elixir

defmodule BeetRoundServerWeb.BiddingLive.Show do
use BeetRoundServerWeb, :live_view
alias BeetRoundServer.Biddings
@impl true
def render(assigns) do
~H"""
<Layouts.app flash={@flash} current_scope={@current_scope}>
<.header>
Bidding {@bidding.id}
<:subtitle>This is a bidding record from your database.</:subtitle>
<:actions>
<.button navigate={~p"/biddings"}>
<.icon name="hero-arrow-left" />
</.button>
<.button variant="primary" navigate={~p"/biddings/#{@bidding}/edit?return_to=show"}>
<.icon name="hero-pencil-square" /> Edit bidding
</.button>
</:actions>
</.header>
<.list>
<:item title="Bidding round">{@bidding.bidding_round}</:item>
<:item title="Amount">{@bidding.amount}</:item>
<:item title="Depot wish one">{@bidding.depot_wish_one}</:item>
<:item title="Depot wish two">{@bidding.depot_wish_two}</:item>
</.list>
</Layouts.app>
"""
end
@impl true
def mount(%{"id" => id}, _session, socket) do
if connected?(socket) do
Biddings.subscribe_biddings(socket.assigns.current_scope)
end
{:ok,
socket
|> assign(:page_title, "Show Bidding")
|> assign(:bidding, Biddings.get_bidding!(socket.assigns.current_scope, id))}
end
@impl true
def handle_info(
{:updated, %BeetRoundServer.Biddings.Bidding{id: id} = bidding},
%{assigns: %{bidding: %{id: id}}} = socket
) do
{:noreply, assign(socket, :bidding, bidding)}
end
def handle_info(
{:deleted, %BeetRoundServer.Biddings.Bidding{id: id}},
%{assigns: %{bidding: %{id: id}}} = socket
) do
{:noreply,
socket
|> put_flash(:error, "The current bidding was deleted.")
|> push_navigate(to: ~p"/biddings")}
end
def handle_info({type, %BeetRoundServer.Biddings.Bidding{}}, socket)
when type in [:created, :updated, :deleted] do
{:noreply, socket}
end
end