Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 23 additions & 28 deletions lib/beacon/live_admin/live/home_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ defmodule Beacon.LiveAdmin.HomeLive do
alias Beacon.LiveAdmin.Router

@impl true
def mount(_params, _session, socket) do
def mount(_params, %{"pages" => pages}, socket) do
if connected?(socket) do
PubSub.subscribe()
end

socket = assign(socket, :pages, pages)

{:ok, assign(socket, :running_sites, Cluster.running_sites())}
end

Expand All @@ -33,33 +35,11 @@ defmodule Beacon.LiveAdmin.HomeLive do
<div class="p-6 rounded-[20px] bg-white border border-gray-200 hover:border-white hover:ring-2 hover:ring-gray-200 hover:ring-offset-8 hover:ring-offset-white transition">
<h3 class="mb-2 text-sm font-semibold leading-8 tracking-wider text-gray-600 uppercase"><%= site %></h3>
<div class="flex flex-col flex-wrap gap-2 mt-10 md:flex-row">
<.link href={Router.beacon_live_admin_path(@socket, site, "/media_library")} class={nav_class()}>
Media Library
</.link>
<.link href={Router.beacon_live_admin_path(@socket, site, "/components")} class={nav_class()}>
Components
</.link>
<.link href={Router.beacon_live_admin_path(@socket, site, "/layouts")} class={nav_class()}>
Layouts
</.link>
<.link href={Router.beacon_live_admin_path(@socket, site, "/pages")} class={nav_class()}>
Pages
</.link>
<.link href={Router.beacon_live_admin_path(@socket, site, "/live_data")} class={nav_class()}>
Live Data
</.link>
<.link href={Router.beacon_live_admin_path(@socket, site, "/events")} class={nav_class()}>
Event Handlers
</.link>
<.link href={Router.beacon_live_admin_path(@socket, site, "/info_handlers")} class={nav_class()}>
Info Handlers
</.link>
<.link href={Router.beacon_live_admin_path(@socket, site, "/error_pages")} class={nav_class()}>
Error Pages
</.link>
<.link href={Router.beacon_live_admin_path(@socket, site, "/hooks")} class={nav_class()}>
JS Hooks
</.link>
<%= for {path, _, _, _} <- all_pages(@pages) do %>
<.link href={Router.beacon_live_admin_path(@socket, site, path)} class={nav_class()}>
<%= path_to_title(path) %>
</.link>
<% end %>
</div>
</div>
<% end %>
Expand All @@ -78,4 +58,19 @@ defmodule Beacon.LiveAdmin.HomeLive do
def handle_info({Cluster, :sites_changed}, socket) do
{:noreply, assign(socket, :running_sites, Beacon.LiveAdmin.Cluster.running_sites())}
end

defp all_pages(pages) do
Enum.filter(pages, fn {path, _, _, _} ->
path =~ ~r{^/[^/]+$}
end)
end

defp path_to_title(path) do
path
|> String.replace(~w[/ _ -], " ")
|> String.trim()
|> String.capitalize()
end


end
3 changes: 2 additions & 1 deletion lib/beacon/live_admin/live/media_library_live/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ defmodule Beacon.LiveAdmin.MediaLibraryLive.Index do
asset = MediaLibrary.get_asset_by(site, id: id)
{:ok, _} = MediaLibrary.soft_delete(site, asset)

path = beacon_live_admin_path(socket, site, "/media_library", query: socket.assigns.query)
query = Map.get(socket.assigns, :query)
path = beacon_live_admin_path(socket, site, "/media_library", query: query)
socket = push_patch(socket, to: path)

{:noreply, socket}
Expand Down