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,52 +24,52 @@ 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_heading>
|
||||||
|
<%= @name %>
|
||||||
|
</.panel_heading>
|
||||||
|
|
||||||
<.panel class={@class} {@rest} is-info>
|
<%= if @details == nil do %>
|
||||||
<.panel_heading>
|
<.panel_tabs is-hidden-mobile>
|
||||||
<%= @name %>
|
<%= for filter <- @filters do %>
|
||||||
</.panel_heading>
|
<a
|
||||||
|
class={if filter.active, do: "is-active"}
|
||||||
|
phx-click="filter"
|
||||||
|
phx-value-key={filter.key}
|
||||||
|
>
|
||||||
|
<%= filter.title %>
|
||||||
|
</a>
|
||||||
|
<% end %>
|
||||||
|
</.panel_tabs>
|
||||||
|
|
||||||
<.panel_tabs is-hidden-mobile>
|
<.panel_tabs is-hidden-tablet>
|
||||||
<%= for filter <- @filters do %>
|
<%= for filter <- @filters do %>
|
||||||
<a
|
<a
|
||||||
class={if filter.active, do: "is-active"}
|
title={filter.title}
|
||||||
phx-click="filter"
|
class={if filter.active, do: "is-active"}
|
||||||
phx-value-key={filter.key}
|
phx-click="filter"
|
||||||
>
|
phx-value-key={filter.key}
|
||||||
<%= filter.title %>
|
>
|
||||||
</a>
|
<.icon for={filter.icon} color="auto" />
|
||||||
|
</a>
|
||||||
|
<% end %>
|
||||||
|
</.panel_tabs>
|
||||||
<% end %>
|
<% end %>
|
||||||
</.panel_tabs>
|
<.panel_block>
|
||||||
|
<.control has-icons-left>
|
||||||
<.panel_tabs is-hidden-tablet>
|
<input
|
||||||
<%= for filter <- @filters do %>
|
class="input is-info"
|
||||||
<a
|
type="text"
|
||||||
title={filter.title}
|
placeholder="Search"
|
||||||
class={if filter.active, do: "is-active"}
|
name="search"
|
||||||
phx-click="filter"
|
value={@query}
|
||||||
phx-value-key={filter.key}
|
phx-keyup="search"
|
||||||
>
|
/>
|
||||||
<.icon for={filter.icon} color="auto" />
|
<.icon for="search" size="1.5rem" aria-hidden="true" is-left />
|
||||||
</a>
|
</.control>
|
||||||
<% end %>
|
</.panel_block>
|
||||||
</.panel_tabs>
|
<%= render_slot(@inner_block) %>
|
||||||
|
</.panel>
|
||||||
<.panel_block>
|
|
||||||
<.control has-icons-left>
|
|
||||||
<input
|
|
||||||
class="input is-info"
|
|
||||||
type="text"
|
|
||||||
placeholder="Search"
|
|
||||||
name="search"
|
|
||||||
value={@query}
|
|
||||||
phx-keyup="search"
|
|
||||||
/>
|
|
||||||
<.icon for="search" size="1.5rem" aria-hidden="true" is-left />
|
|
||||||
</.control>
|
|
||||||
</.panel_block>
|
|
||||||
<%= render_slot(@inner_block) %>
|
|
||||||
</.panel>
|
|
||||||
</.block>
|
</.block>
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue