lightswitch done
This commit is contained in:
parent
9755373c8f
commit
85a31d3d02
|
@ -2,7 +2,12 @@ defmodule PokemonCoutureWeb.ClothesTrackerLive do
|
|||
use PokemonCoutureWeb, :live_view
|
||||
|
||||
def mount(_params, _session, socket) do
|
||||
socket = assign(socket, :light_bulb_status, "off")
|
||||
socket =
|
||||
socket
|
||||
|> assign(:light_bulb_status, "off")
|
||||
|> assign(:on_button_status, "")
|
||||
|> assign(:off_button_status, "disabled")
|
||||
|
||||
{:ok, socket}
|
||||
end
|
||||
|
||||
|
@ -10,6 +15,18 @@ defmodule PokemonCoutureWeb.ClothesTrackerLive do
|
|||
socket =
|
||||
socket
|
||||
|> assign(:light_bulb_status, "on")
|
||||
|> assign(:on_button_status, "disabled")
|
||||
|> assign(:off_button_status, "enabled")
|
||||
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
def handle_event("off", _value, socket) do
|
||||
socket =
|
||||
socket
|
||||
|> assign(:light_bulb_status, "off")
|
||||
|> assign(:on_button_status, "")
|
||||
|> assign(:off_button_status, "disabled")
|
||||
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
<h1>The light is <%= @light_bulb_status %>.</h1>
|
||||
<button phx-click="on">On</button>
|
||||
<button phx-click="on" <%= @on_button_status %>>On</button>
|
||||
<button phx-click="off" <%= @off_button_status %>>Off</button>
|
||||
|
|
Loading…
Reference in New Issue