mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-02-21 21:36:17 +08:00
* Update phoenix deps
* Update reference to LiveDashboard encode_pid
* Fix form input id references
* Move to HEEx
* Update back to filesystem LV npm package
* Further HEEx rewrites
* Refactor icons into function components
* .html.leex -> .html.heex
* Further refactoring
* Move render helpers into function components
* Add doctype back
* Further refactoring
* Refactor cell component
* Further refactoring
* Compose sidebar using function components
* Rewrite notebook card component as function component
* Fruther refactoring
* Fix race condition in runtime tests
* Rewrite tooltips into function component
* Update Tailwind purge rules
* Revert "Rewrite tooltips into function component"
This reverts commit bd6ca8f0b5
.
* Refactor conditional tooltip
60 lines
1.5 KiB
Elixir
60 lines
1.5 KiB
Elixir
defmodule LivebookWeb.UserHelpers do
|
|
use Phoenix.Component
|
|
|
|
alias Livebook.Users.User
|
|
|
|
@doc """
|
|
Renders user avatar.
|
|
|
|
## Examples
|
|
|
|
<.user_avatar user={@user} class="h-20 w-20" text_class="text-3xl" />
|
|
"""
|
|
def user_avatar(assigns) do
|
|
assigns =
|
|
assigns
|
|
|> assign_new(:class, fn -> "w-full h-full" end)
|
|
|> assign_new(:text_class, fn -> "" end)
|
|
|
|
~H"""
|
|
<div class={"#{@class} rounded-full flex items-center justify-center"} style={"background-color: #{@user.hex_color}"}>
|
|
<div class={"#{@text_class} text-gray-100 font-semibold"}>
|
|
<%= avatar_text(@user.name) %>
|
|
</div>
|
|
</div>
|
|
"""
|
|
end
|
|
|
|
defp avatar_text(nil), do: "?"
|
|
|
|
defp avatar_text(name) do
|
|
name
|
|
|> String.split()
|
|
|> Enum.map(&String.at(&1, 0))
|
|
|> Enum.map(&String.upcase/1)
|
|
|> case do
|
|
[initial] -> initial
|
|
initials -> List.first(initials) <> List.last(initials)
|
|
end
|
|
end
|
|
|
|
@doc """
|
|
Builds `Livebook.Users.User` using information from
|
|
session and socket.
|
|
|
|
Uses `user_data` from socket `connect_params` as initial
|
|
attributes if the socket is connected. Otherwise uses
|
|
`user_data` from session.
|
|
"""
|
|
def build_current_user(session, socket) do
|
|
%{"current_user_id" => current_user_id} = session
|
|
|
|
connect_params = get_connect_params(socket) || %{}
|
|
user_data = connect_params["user_data"] || session["user_data"] || %{}
|
|
|
|
case User.change(%{User.new() | id: current_user_id}, user_data) do
|
|
{:ok, user} -> user
|
|
{:error, _errors, user} -> user
|
|
end
|
|
end
|
|
end
|