forked from hiway/freedive
Auto open details when searched items have single result
This commit is contained in:
parent
48b34fd6fc
commit
c1c428d524
3 changed files with 61 additions and 46 deletions
|
@ -42,8 +42,22 @@ defmodule FreediveWeb.LiliformLive do
|
||||||
FreediveWeb.LiliformLive.get_active_filter(socket.assigns.filters)
|
FreediveWeb.LiliformLive.get_active_filter(socket.assigns.filters)
|
||||||
)
|
)
|
||||||
|
|
||||||
items = search(filtered_items, query)
|
searched_items = search(filtered_items, query)
|
||||||
socket = assign(socket, :items, items)
|
socket = assign(socket, :items, searched_items)
|
||||||
|
|
||||||
|
socket =
|
||||||
|
case Kernel.length(Map.keys(searched_items)) == 1 do
|
||||||
|
true ->
|
||||||
|
IO.inspect(Map.keys(searched_items) |> List.first())
|
||||||
|
assign(socket, %{
|
||||||
|
selected_item: Map.get(searched_items, Map.keys(searched_items) |> List.first()),
|
||||||
|
details: true
|
||||||
|
})
|
||||||
|
|
||||||
|
false ->
|
||||||
|
assign(socket, %{selected_item: nil, details: nil})
|
||||||
|
end
|
||||||
|
|
||||||
{:noreply, socket}
|
{:noreply, socket}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ defmodule FreediveWeb.ServiceLive do
|
||||||
|
|
||||||
def render(assigns) do
|
def render(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
<.page name="Services" filters={@filters}>
|
<.page name="Services" filters={@filters} details={@details}>
|
||||||
<FreediveWeb.ServiceLive.Components.items_block
|
<FreediveWeb.ServiceLive.Components.items_block
|
||||||
items={@items}
|
items={@items}
|
||||||
selected_item={@selected_item}
|
selected_item={@selected_item}
|
||||||
|
|
|
@ -11,6 +11,7 @@ defmodule Liliform.Page do
|
||||||
attr :name, :string, required: true, doc: "page name"
|
attr :name, :string, required: true, doc: "page name"
|
||||||
attr :class, :string, default: "", doc: "additional classes"
|
attr :class, :string, default: "", doc: "additional classes"
|
||||||
attr :filters, :list, default: [], doc: "filters"
|
attr :filters, :list, default: [], doc: "filters"
|
||||||
|
attr :details, :string, default: nil, doc: "details"
|
||||||
attr :query, :string, default: "", doc: "search query"
|
attr :query, :string, default: "", doc: "search query"
|
||||||
attr :rest, :global
|
attr :rest, :global
|
||||||
|
|
||||||
|
@ -23,12 +24,12 @@ defmodule Liliform.Page do
|
||||||
|
|
||||||
~H"""
|
~H"""
|
||||||
<.block class="px-2 py-4">
|
<.block class="px-2 py-4">
|
||||||
|
|
||||||
<.panel class={@class} {@rest} is-info>
|
<.panel class={@class} {@rest} is-info>
|
||||||
<.panel_heading>
|
<.panel_heading>
|
||||||
<%= @name %>
|
<%= @name %>
|
||||||
</.panel_heading>
|
</.panel_heading>
|
||||||
|
|
||||||
|
<%= if @details == nil do %>
|
||||||
<.panel_tabs is-hidden-mobile>
|
<.panel_tabs is-hidden-mobile>
|
||||||
<%= for filter <- @filters do %>
|
<%= for filter <- @filters do %>
|
||||||
<a
|
<a
|
||||||
|
@ -53,7 +54,7 @@ defmodule Liliform.Page do
|
||||||
</a>
|
</a>
|
||||||
<% end %>
|
<% end %>
|
||||||
</.panel_tabs>
|
</.panel_tabs>
|
||||||
|
<% end %>
|
||||||
<.panel_block>
|
<.panel_block>
|
||||||
<.control has-icons-left>
|
<.control has-icons-left>
|
||||||
<input
|
<input
|
||||||
|
|
Loading…
Reference in a new issue