Add the sync button to Server Index LiveView.
continuous-integration/drone/push Build is passing Details

dev
KKlochko 2 months ago
parent 9115d6f596
commit f1f0b77954

@ -2,12 +2,21 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.Index do
use DecentralisedBookIndexWeb, :live_view
alias DecentralisedBookIndex.Metadata
alias DecentralisedBookIndex.SyncTasks.SyncServerTask
@impl true
def render(assigns) do
~H"""
<.header>
Listing Servers
<:actions>
<div class="flex flex-row gap-2">
<.primary_button phx-click="sync">
Sync now
</.primary_button>
</div>
</:actions>
</.header>
<div class="pt-2">
@ -177,4 +186,32 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.Index do
{:noreply, push_patch(socket, to: ~p"/servers?#{params}")}
end
@impl true
def handle_event("sync", _params, socket) do
Task.async(fn ->
SyncServerTask.sync_all()
send(self(), :sync_completed)
end)
socket =
socket
|> put_flash(:info, "The sync is started")
{:noreply, socket}
end
@impl true
def handle_info({_pid, :sync_completed}, socket) do
socket =
socket
|> put_flash(:info, "The sync is done")
{:noreply, socket}
end
@impl true
def handle_info(_params, socket) do
{:noreply, socket}
end
end

Loading…
Cancel
Save