lightswitch done
This commit is contained in:
		
							parent
							
								
									9755373c8f
								
							
						
					
					
						commit
						85a31d3d02
					
				| @ -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,7 +15,19 @@ 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} |     {:noreply, socket} | ||||||
|   end |   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 | ||||||
| end | end | ||||||
|  | |||||||
| @ -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> | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user