fp/services/bright/lib/bright_web/live/thermostat_live.ex

20 lines
516 B
Elixir
Raw Normal View History

2025-01-11 03:10:04 +00:00
defmodule BrightWeb.ThermostatLive do
2025-01-03 14:45:35 +00:00
use BrightWeb, :live_view
def render(assigns) do
~H"""
Current temperature: {@temperature}°F
2025-01-11 03:10:04 +00:00
<button class="button" phx-click="inc_temperature">+</button>
2025-01-03 14:45:35 +00:00
"""
end
def mount(_params, _session, socket) do
2025-01-11 03:10:04 +00:00
temperature = 70 # Let's assume a fixed temperature for now
2025-01-03 14:45:35 +00:00
{:ok, assign(socket, :temperature, temperature)}
end
def handle_event("inc_temperature", _params, socket) do
{:noreply, update(socket, :temperature, &(&1 + 1))}
end
end