View Source Bonfire.UI.Common (Bonfire v0.9.10-classic-beta.156)

A library of common utils and helpers used across Bonfire extensions

  • Many common functions for web UIs
  • Common and generic re-usable components
  • Etc

Handy commands

Copyright (c) 2022 Bonfire Contributors

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Summary

Functions

Warning: this will set assigns for any/all users who subscribe to them. You want to cast_self/2 instead if dealing with user-specific actions or private data.

copies the go param into a query string, if any

Generate a query string adding a go redirection path to the URI (for redirecting somewhere after auth flows). It is recommended to use set_go_after/2 where possible instead.

Special LiveView helper function which allows loading LiveComponents in regular Phoenix views: live_render_component(@conn, MyLiveComponent)

Inserts one or many items in an existing stream. See Phoenix.LiveView.stream_insert/4 for opts.

Subscribe to assigns targeted at the current account/user

Save a go redirection path in the session (for redirecting somewhere after auth flows)

Checks if the socket is connected.

Run a function and expects tuple. If anything else is returned, like an error, a flash message is shown to the user.

Functions

Link to this function

assign_error(socket, msg, pid \\ self())

View Source
Link to this function

assign_flash(socket_or_conn, type, message, assigns \\ %{}, pid \\ self())

View Source
Link to this function

assign_generic(socket_or_conn, assigns)

View Source
Link to this function

assign_generic(socket, key, value)

View Source
Link to this function

assign_generic_global(socket, assigns)

View Source
Link to this function

assign_global(socket, assigns)

View Source
Link to this function

assign_global(socket, key, value)

View Source
Link to this function

assigns_merge(assigns, new)

View Source
Link to this function

assigns_merge(socket, assigns, new)

View Source
Link to this function

assigns_minimal(assigns)

View Source
Link to this function

assigns_subscribe(socket, assign_names)

View Source
Link to this function

batch_update_many_async(assigns_sockets, many_opts, opts)

View Source
Link to this function

batch_update_many_async(current_user, assigns_sockets, many_opts, opts)

View Source
Link to this function

can?(subject, verbs, object, opts \\ [])

View Source
Link to this function

cast_public(socket, assigns_to_broadcast)

View Source

Warning: this will set assigns for any/all users who subscribe to them. You want to cast_self/2 instead if dealing with user-specific actions or private data.

Link to this function

cast_self(socket, assigns_to_broadcast)

View Source

copies the go param into a query string, if any

Link to this function

current_url(socket_or_assigns, default \\ nil, recursing \\ false)

View Source
Link to this function

current_user_or_remote_interaction(socket, verb, object)

View Source

Callback implementation for Bonfire.Common.ExtensionModule.declared_extension/0.

Generate a query string adding a go redirection path to the URI (for redirecting somewhere after auth flows). It is recommended to use set_go_after/2 where possible instead.

Link to this macro

live_aliases(aliases, path, live_view, action \\ nil, opts \\ [])

View Source (macro)
Link to this function

live_render_component(conn, load_live_component)

View Source

Special LiveView helper function which allows loading LiveComponents in regular Phoenix views: live_render_component(@conn, MyLiveComponent)

Link to this function

live_render_with_conn(conn, live_view)

View Source
Link to this function

live_upload_files(module \\ nil, upload_field \\ :files, current_user, metadata, socket)

View Source
Link to this function

maybe_apply_or_ret(assigns, mod, fun)

View Source
Link to this function

maybe_assign(socket, key, value)

View Source
Link to this function

maybe_assign_context(socket, ret)

View Source
Link to this function

maybe_component(module, context \\ [])

View Source
Link to this function

maybe_consume_uploaded_entries(socket, key, fun)

View Source
Link to this function

maybe_consume_uploaded_entry(socket, key, fun)

View Source
Link to this function

maybe_last_sentry_event_id()

View Source
Link to this function

maybe_push_event(socket, name, data)

View Source
Link to this function

maybe_send_update(component, id, assigns, opts \\ [])

View Source
Link to this function

maybe_stream_insert(socket, name, items, opts)

View Source

Inserts one or many items in an existing stream. See Phoenix.LiveView.stream_insert/4 for opts.

Link to this function

opts_for_update_many_async(arg, opts)

View Source
Link to this function

patch_to(socket_or_conn, to \\ nil, opts \\ [])

View Source
Link to this function

path_fallback(socket_or_conn, opts)

View Source
Link to this function

redirect_to(socket_or_conn, to \\ nil, opts \\ [])

View Source
Link to this function

redirect_to_previous_go(conn, params, default, current_path)

View Source
Link to this macro

render_sface_or_native(opts \\ [])

View Source (macro)
Link to this function

rich(content, opts \\ [])

View Source
Link to this function

self_subscribe(socket, assign_names)

View Source

Subscribe to assigns targeted at the current account/user

Link to this function

send_self(socket \\ nil, assigns)

View Source
Link to this function

send_self_global(socket \\ nil, assigns)

View Source
Link to this function

set_go_after(conn, path \\ nil)

View Source

Save a go redirection path in the session (for redirecting somewhere after auth flows)

Link to this function

socket_connected?(socket)

View Source

Checks if the socket is connected.

Examples

iex> socket_connected?(%{socket_connected?: true})
true

iex> socket_connected?(%{socket_connected?: false})
false

iex> socket_connected?(%{__context__: %{socket_connected?: true}})
true

iex> socket_connected?(%Phoenix.LiveView.Socket{transport_pid: 1})
true

iex> socket_connected?(%Phoenix.LiveView.Socket{transport_pid: nil})
false
Link to this function

templated(content, data \\ %{})

View Source
Link to this function

templated_or_remote_markdown(content, data \\ nil)

View Source
Link to this function

undead_mount(socket, fun)

View Source

Run a function and expects tuple. If anything else is returned, like an error, a flash message is shown to the user.

Link to this function

undead_on_mount(socket, fun)

View Source
Link to this function

undead_render(assigns, fun)

View Source
Link to this function

undead_update(socket, fun)

View Source
Link to this function

update_many_async(assigns_sockets, opts)

View Source
Link to this function

update_many_async(current_user, assigns_sockets, opts)

View Source