lightswitch done

This commit is contained in:
Lili (Tlapka) 2021-09-08 16:49:52 +02:00
parent 9755373c8f
commit 85a31d3d02
2 changed files with 20 additions and 2 deletions

View File

@ -2,7 +2,12 @@ defmodule PokemonCoutureWeb.ClothesTrackerLive do
use PokemonCoutureWeb, :live_view use PokemonCoutureWeb, :live_view
def mount(_params, _session, socket) do 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} {:ok, socket}
end end
@ -10,6 +15,18 @@ defmodule PokemonCoutureWeb.ClothesTrackerLive do
socket = socket =
socket socket
|> assign(:light_bulb_status, "on") |> 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} {:noreply, socket}
end end

View File

@ -1,2 +1,3 @@
<h1>The light is <%= @light_bulb_status %>.</h1> <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>