This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user