One-line embedder for PhoenixKitWeb.Components.MediaBrowser.
LiveView uploads must live on the parent socket (not the LiveComponent),
so embedding the MediaBrowser requires three small pieces of plumbing on
the parent: an allow_upload, a "validate" event stub for the upload
channel, and a handle_info delegator for component→parent messages.
This module bundles all three into a single use call.
Usage
defmodule MyAppWeb.MediaPage do
use MyAppWeb, :live_view
use PhoenixKitWeb.Components.MediaBrowser.Embed
def mount(_params, _session, socket) do
{:ok, socket}
end
endThen in the template:
<.live_component
module={PhoenixKitWeb.Components.MediaBrowser}
id="media-browser"
parent_uploads={@uploads}
/>What gets injected
on_mount— callsMediaBrowser.setup_uploads/1so@uploads.media_filesis available on every mount of this LiveView.- Fallback
handle_event("validate", _, socket)— absorbs the upload channel'sphx-changeevents. User-defined clauses with other event names still win because they are defined first. - Fallback
handle_info({MediaBrowser, _, _}, socket)— forwards toMediaBrowser.handle_parent_info/2for component registration and upload piping.
Both fallbacks are injected via @before_compile, so user clauses
declared earlier in the module match before them.