22 lines
549 B
Elixir
22 lines
549 B
Elixir
defmodule Bright.ThermostatLive do
|
|
use BrightWeb, :live_view
|
|
|
|
def render(assigns) do
|
|
~H"""
|
|
Current temperature: {@temperature}°F
|
|
<button class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" phx-click="inc_temperature">
|
|
Button
|
|
</button>
|
|
"""
|
|
end
|
|
|
|
def mount(_params, _session, socket) do
|
|
temperature = 70
|
|
{:ok, assign(socket, :temperature, temperature)}
|
|
end
|
|
|
|
def handle_event("inc_temperature", _params, socket) do
|
|
{:noreply, update(socket, :temperature, &(&1 + 1))}
|
|
end
|
|
end
|