36 lines
1 KiB
Elixir
36 lines
1 KiB
Elixir
defmodule FreediveWeb.LiliformLive do
|
|
defmacro __using__(opts) do
|
|
quote location: :keep, bind_quoted: [opts: opts] do
|
|
use FreediveWeb, :live_view
|
|
@behaviour FreediveWeb.LiliformLive
|
|
@filters_all [
|
|
%{
|
|
title: "All",
|
|
icon: "all",
|
|
active: false
|
|
}
|
|
]
|
|
|
|
def(mount(_params, _session, socket)) do
|
|
items = items()
|
|
socket = assign(socket, :opts, Keyword.get(unquote(opts), :opts, []))
|
|
socket = assign(socket, :items_all, items)
|
|
socket = assign(socket, :items, items)
|
|
socket = assign(socket, :filters, @filters_all ++ filters())
|
|
socket = assign(socket, :query, "")
|
|
IO.inspect(socket, label: "socket")
|
|
{:ok, socket}
|
|
end
|
|
|
|
def(handle_event("search", %{"value" => query}, socket)) do
|
|
items = search(query)
|
|
socket = assign(socket, :items, items)
|
|
{:noreply, socket}
|
|
end
|
|
end
|
|
end
|
|
|
|
@callback items() :: [map]
|
|
@callback filters() :: [map]
|
|
@callback search(query :: String.t()) :: [map]
|
|
end
|