This commit is contained in:
@@ -2,12 +2,21 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.Index do
|
|||||||
use DecentralisedBookIndexWeb, :live_view
|
use DecentralisedBookIndexWeb, :live_view
|
||||||
|
|
||||||
alias DecentralisedBookIndex.Metadata
|
alias DecentralisedBookIndex.Metadata
|
||||||
|
alias DecentralisedBookIndex.SyncTasks.SyncServerTask
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def render(assigns) do
|
def render(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
<.header>
|
<.header>
|
||||||
Listing Servers
|
Listing Servers
|
||||||
|
|
||||||
|
<:actions>
|
||||||
|
<div class="flex flex-row gap-2">
|
||||||
|
<.primary_button phx-click="sync">
|
||||||
|
Sync now
|
||||||
|
</.primary_button>
|
||||||
|
</div>
|
||||||
|
</:actions>
|
||||||
</.header>
|
</.header>
|
||||||
|
|
||||||
<div class="pt-2">
|
<div class="pt-2">
|
||||||
@@ -177,4 +186,32 @@ defmodule DecentralisedBookIndexWeb.DbiServerLive.Index do
|
|||||||
|
|
||||||
{:noreply, push_patch(socket, to: ~p"/servers?#{params}")}
|
{:noreply, push_patch(socket, to: ~p"/servers?#{params}")}
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user