theenglishway (time) 4 роки тому
батько
коміт
ee572891d0

+ 7 - 0
lib/vaccins/location_store.ex

@@ -91,6 +91,10 @@ defmodule Vaccins.LocationStore do
     {:ok, load_state()}
   end
 
+  def reload() do
+    GenServer.call(@name, :reload)
+  end
+
   def get_locations() do
     GenServer.call(@name, :get_locations)
   end
@@ -103,6 +107,9 @@ defmodule Vaccins.LocationStore do
     GenServer.call(@name, {:delete_location, id})
   end
 
+  @impl true
+  def handle_call(:reload, _, _), do: {:reply, :ok, load_state()}
+
   @impl true
   def handle_call(:get_locations, _, state = %{locations: locations}),
     do: {:reply, locations |> Map.values() |> Enum.map(&Location.build_query/1), state}

+ 5 - 0
lib/vaccins_web/live/index.ex

@@ -33,6 +33,11 @@ defmodule VaccinsWeb.IndexLive do
     end
   end
 
+  def handle_event("reload_file", _, socket) do
+    :ok = LocationStore.reload()
+    {:noreply, socket |> assign(locations: LocationStore.get_locations())}
+  end
+
   def handle_event("trigger_all", _, socket) do
     {:noreply, socket |> trigger_global_refresh}
   end

+ 1 - 0
lib/vaccins_web/live/index_live.html.leex

@@ -1,4 +1,5 @@
 <button phx-click="trigger_all">Trigger all</button>
+<button phx-click="reload_file">Reload file</button>
 <button phx-click="toggle_form">Display/hide form</button>
 
 <%= if @display_cs do %>