added solid.js as front end
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
defmodule RiverConnectWeb.SolidDemoLive do
|
||||
use RiverConnectWeb, :live_view
|
||||
|
||||
def mount(_params, _session, socket) do
|
||||
if connected?(socket) do
|
||||
# Optional: Send initial state on mount if needed,
|
||||
# but SolidBridge will handle the initial render and push events.
|
||||
:ok
|
||||
end
|
||||
|
||||
{:ok, assign(socket, count: 0)}
|
||||
end
|
||||
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
<div class="p-8">
|
||||
<h1 class="text-2xl font-bold mb-4">Solid.js + LiveView Bridge</h1>
|
||||
|
||||
<div
|
||||
id="solid-app"
|
||||
phx-update="ignore"
|
||||
phx-hook="SolidBridge"
|
||||
data-initial-count={@count}
|
||||
></div>
|
||||
|
||||
<div class="mt-8 p-4 bg-gray-100 rounded">
|
||||
<h2 class="font-semibold text-gray-700 mb-2">Server State (LiveView Assigns):</h2>
|
||||
<p class="text-lg">Count: <%= @count %></p>
|
||||
</div>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
def handle_event("increment", _params, socket) do
|
||||
new_count = socket.assigns.count + 1
|
||||
{:noreply,
|
||||
socket
|
||||
|> assign(count: new_count)
|
||||
|> push_event("sync_state", %{count: new_count})}
|
||||
end
|
||||
|
||||
def handle_event("decrement", _params, socket) do
|
||||
new_count = socket.assigns.count - 1
|
||||
{:noreply,
|
||||
socket
|
||||
|> assign(count: new_count)
|
||||
|> push_event("sync_state", %{count: new_count})}
|
||||
end
|
||||
end
|
||||
@@ -19,6 +19,7 @@ defmodule RiverConnectWeb.Router do
|
||||
|
||||
get "/", PageController, :home
|
||||
live "/audio", AudioLive
|
||||
live "/solid-demo", SolidDemoLive
|
||||
end
|
||||
|
||||
# Other scopes may use custom stacks.
|
||||
|
||||
Reference in New Issue
Block a user