-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hosting and Tenant: Add site selector #100
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's working well but I realized we can implement it with less code and make it work for all pages without duplicating the code.
Every page in admin use PageBuilder
(https://github.com/BeaconCMS/beacon_live_admin/blob/main/lib/beacon/live_admin/page_builder.ex) which works as a base module to define shared behavior on all pages.
In that module, inside defmacro __using__
, you can add a global handle_event:
@impl true
def handle_event("change-site", %{"site" => site}, socket) do
site = String.to_existing_atom(site)
path =
case String.split(socket.assigns.beacon_page.path, "/") do
["", path | _] -> beacon_live_admin_path(socket, site, path)
_ -> beacon_live_admin_path(socket)
end
{:noreply, push_navigate(socket, to: path)}
end
Now for the frontend part, we also have a module/template that's shared across all pages and that is https://github.com/BeaconCMS/beacon_live_admin/blob/main/lib/beacon/live_admin/page_live.ex and https://github.com/BeaconCMS/beacon_live_admin/blob/main/lib/beacon/live_admin/page_live.html.heex
So in that module you can define that @running_sites
assign and then call the <.site_selector>
component in page_live.html.heex
By doing so you can remove the duplicated code in each live view (see the suggestions on the file component_editor_live/index.ex
Thanks!
attr :selected_site, :string, default: "" | ||
attr :options, :list, default: [] | ||
|
||
def site_selector(assigns) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻
4cccb62
to
e00b986
Compare
❤️ |
#8
layouts example:
error_pages example: