Skip to content

Commit

Permalink
Add clear button
Browse files Browse the repository at this point in the history
  • Loading branch information
s-hosoai committed Mar 15, 2024
1 parent f0c6389 commit c40b178
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/zenohex_phoenix_demo/zenohex_manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ defmodule ZenohexPhoenixDemo.ZenohexManager do
{:reply, state.msgs, state}
end

def handle_call(:clear_msgs, _form, state) do
{:reply, [], %{state | msgs: [] }}
end

def handle_info(:loop, state) do
recv_timeout(state)
{:noreply, state}
Expand Down
8 changes: 7 additions & 1 deletion lib/zenohex_phoenix_demo_web/live/zenohex_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ defmodule ZenohexPhoenixDemoWeb.ZenohexLive do

def render(assigns) do
~L"""
<h1 class="mb-4 text-4xl font-extrabold leading-none tracking-tight text-gray-900 md:text-5xl lg:text-6xl dark:text-white">Zenohex demo</h1>
<h1 class="mb-4 text-4xl font-extrabold leading-none tracking-tight text-gray-900 md:text-5xl lg:text-6xl">Zenohex demo</h1>
<button phx-click="pub" class="focus:outline-none text-white bg-purple-700 hover:bg-purple-800 focus:ring-4 focus:ring-purple-300 font-medium rounded-lg text-sm px-5 py-2.5 mb-2 dark:bg-purple-600 dark:hover:bg-purple-700 dark:focus:ring-purple-900"> Pubish Message</button>
<div>
<label>subscribe</label>
<textarea rows=20 class="block p-2.5 w-full text-sm text-gray-900 bg-gray-50 rounded-lg border border-gray-300 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"><%= @msgs %></textarea>
</div>
<button phx-click="clear" class="focus:outline-none text-white bg-purple-700 hover:bg-purple-800 focus:ring-4 focus:ring-purple-300 font-medium rounded-lg text-sm px-5 py-2.5 mb-2 dark:bg-purple-600 dark:hover:bg-purple-700 dark:focus:ring-purple-900"> Clear</button>
"""
end

Expand All @@ -25,6 +26,11 @@ defmodule ZenohexPhoenixDemoWeb.ZenohexLive do
{:noreply, socket}
end

def handle_event("clear", _value, socket) do
GenServer.call(ZenohexPhoenixDemo.ZenohexManager, :clear_msgs)
{:noreply, socket}
end

def handle_cast({:callback, msg}, _from, socket) do
socket = update(socket, :zenoh_sub_status, fn msgs -> msgs <> msg end)
{:noreply, socket}
Expand Down

0 comments on commit c40b178

Please sign in to comment.