Ver código fonte

Hide form by default

theenglishway (time) 4 anos atrás
pai
commit
575ad9798c

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

@@ -12,7 +12,8 @@ defmodule VaccinsWeb.IndexLive do
        locations: locations,
        pending: %{},
        availabilities: locations |> Map.new(&{&1.id, []}),
-       location_cs: LocationStore.LocationRaw.changeset(%{})
+       location_cs: LocationStore.LocationRaw.changeset(%{}),
+       display_cs: false
      )
      |> trigger_global_refresh}
   end
@@ -25,11 +26,13 @@ defmodule VaccinsWeb.IndexLive do
     end
   end
 
-  @impl true
   def handle_event("trigger_all", _, socket) do
     {:noreply, socket |> trigger_global_refresh}
   end
 
+  def handle_event("toggle_form", _, socket = %{assigns: %{display_cs: display}}),
+    do: {:noreply, socket |> assign(display_cs: not display)}
+
   @impl true
   def handle_info({:query_sent, id, ref}, socket = %{assigns: %{pending: pending}}) do
     {:noreply, socket |> assign(pending: pending |> Map.put(ref, id))}

+ 16 - 13
lib/vaccins_web/live/index_live.html.leex

@@ -1,20 +1,23 @@
-<%= f = form_for @location_cs, "#", [phx_submit: :add_location] %>
-  <%= label f, :name %>
-  <%= text_input f, :name %>
-  <%= error_tag f, :name %>
+<button phx-click="trigger_all">Trigger all</button>
+<button phx-click="toggle_form">Display/hide form</button>
 
-  <%= label f, :booking_page %>
-  <%= text_input f, :booking_page %>
-  <%= error_tag f, :booking_page %>
+<%= if @display_cs do %>
+  <%= f = form_for @location_cs, "#", [phx_submit: :add_location] %>
+    <%= label f, :name %>
+    <%= text_input f, :name %>
+    <%= error_tag f, :name %>
 
-  <%= label f, :raw_query %>
-  <%= text_input f, :raw_query %>
-  <%= error_tag f, :raw_query %>
+    <%= label f, :booking_page %>
+    <%= text_input f, :booking_page %>
+    <%= error_tag f, :booking_page %>
 
-  <%= submit "send" %>
-</form>
+    <%= label f, :raw_query %>
+    <%= text_input f, :raw_query %>
+    <%= error_tag f, :raw_query %>
 
-<button phx-click="trigger_all">Trigger all</button>
+    <%= submit "send" %>
+  </form>
+<% end %>
 
 <ul class="locations-list">
   <%= for l <- @locations do %>