freedive/lib/freedive_web/live/service_live.ex

115 lines
2.8 KiB
Elixir
Raw Normal View History

2024-05-15 22:18:55 +02:00
defmodule FreediveWeb.ServiceLive do
2024-05-16 01:37:36 +02:00
use FreediveWeb.LiliformLive
2024-05-16 17:11:00 +02:00
alias Freedive.Api.Service
2024-05-15 22:18:55 +02:00
def render(assigns) do
~H"""
<.page name="Services" filters={@filters} details={@details}>
<FreediveWeb.ServiceLive.Components.items_block
items={@items}
selected_item={@selected_item}
details={@details}
/>
2024-05-16 02:27:59 +02:00
</.page>
2024-05-15 22:18:55 +02:00
"""
end
def items() do
2024-05-16 17:11:00 +02:00
Service.list()
2024-05-15 22:18:55 +02:00
end
2024-05-16 01:37:36 +02:00
def filters() do
[
%{
title: "Running",
2024-05-16 02:22:56 +02:00
key: :running,
2024-05-16 01:37:36 +02:00
icon: "circle-play",
active: true
},
%{
title: "Enabled",
2024-05-16 02:22:56 +02:00
key: :enabled,
2024-05-16 01:37:36 +02:00
icon: "circle-check",
active: false
}
]
end
2024-05-16 05:01:40 +02:00
def search(items, query) do
items
|> Enum.filter(fn {name, _item} ->
String.contains?(String.downcase(name), String.downcase(query))
2024-05-16 01:37:36 +02:00
end)
2024-05-16 05:01:40 +02:00
|> Enum.into(%{}, fn {name, item} -> {name, item} end)
2024-05-16 01:37:36 +02:00
end
end
defmodule FreediveWeb.ServiceLive.Components do
2024-05-16 01:37:36 +02:00
use Liliform.Component
import Liliform.Icon
import Liliform.Panel
import Liliform.Title
2024-05-16 01:37:36 +02:00
@doc """
2024-05-16 02:27:59 +02:00
Returns items as panel-blocks.
2024-05-16 01:37:36 +02:00
"""
attr :items, :list, default: [], doc: "items"
attr :selected_item, :string, default: nil, doc: "selected item"
attr :details, :string, default: nil, doc: "details"
def items_block(%{details: true} = assigns) do
~H"""
<.link
class="panel-block pt-1 has-background-light"
phx-click="tap"
phx-value-name={@selected_item.name}
>
<span class="panel-icon">
<.icon for="arrow-left" aria-hidden="true" has-text-dark />
</span>
<div class="mt-2 ml-2">Back</div>
</.link>
<.panel_media>
<:icon>
<.icon_raw for={@selected_item.icon} color="auto" size="3rem" aria-hidden="true" />
<%!-- <Lucideicons.accessibility height="2rem" width="2rem" /> --%>
</:icon>
<.title is-4>
<%= @selected_item.name %>
</.title>
<.subtitle>
<%= @selected_item.description %>
</.subtitle>
<:actions>
<div class="columns">
<div class="column is-narrow">
<.icon for="running" color="auto" aria-hidden="true" />
<.icon for="enabled" color="auto" aria-hidden="true" />
</div>
2024-05-16 05:01:40 +02:00
</div>
</:actions>
</.panel_media>
"""
end
2024-05-16 01:37:36 +02:00
2024-05-16 01:47:37 +02:00
def items_block(assigns) do
2024-05-16 01:37:36 +02:00
~H"""
<%= for {_name, item} <- @items do %>
<.link
class={"panel-block pt-1 #{if @selected_item != nil and @selected_item.name == item.name, do: "has-background-info-light"}"}
phx-click="tap"
phx-value-name={item.name}
>
2024-05-16 01:37:36 +02:00
<span class="panel-icon">
<.icon for={item.icon} color="auto" aria-hidden="true" />
</span>
<div class="mt-2 ml-2"><%= item.name %></div>
</.link>
<% end %>
"""
end
2024-05-15 22:18:55 +02:00
end