mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-09-06 04:54:29 +08:00
Add a fallback to user's profile picture (#2940)
This commit is contained in:
parent
a4fd19e400
commit
64e2a07a12
1 changed files with 22 additions and 13 deletions
|
@ -14,6 +14,25 @@ defmodule LivebookWeb.UserComponents do
|
|||
attr :text_class, :string, default: nil
|
||||
|
||||
def user_avatar(%{user: %{avatar_url: nil}} = assigns) do
|
||||
~H"""
|
||||
<.avatar_text class={@class} user={@user} text_class={@text_class} />
|
||||
"""
|
||||
end
|
||||
|
||||
def user_avatar(assigns) do
|
||||
~H"""
|
||||
<object
|
||||
data={@user.avatar_url}
|
||||
type="image/png"
|
||||
class={["rounded-full flex items-center justify-center", @class]}
|
||||
aria-hidden="true"
|
||||
>
|
||||
<.avatar_text class={@class} user={@user} text_class={@text_class} />
|
||||
</object>
|
||||
"""
|
||||
end
|
||||
|
||||
defp avatar_text(assigns) do
|
||||
~H"""
|
||||
<div
|
||||
class={["rounded-full flex items-center justify-center", @class]}
|
||||
|
@ -21,25 +40,15 @@ defmodule LivebookWeb.UserComponents do
|
|||
aria-hidden="true"
|
||||
>
|
||||
<div class={["text-gray-100 font-semibold", @text_class]}>
|
||||
{avatar_text(@user.name)}
|
||||
{initials(@user.name)}
|
||||
</div>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
def user_avatar(assigns) do
|
||||
~H"""
|
||||
<img
|
||||
src={@user.avatar_url}
|
||||
class={["rounded-full flex items-center justify-center", @class]}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
"""
|
||||
end
|
||||
defp initials(nil), do: "?"
|
||||
|
||||
defp avatar_text(nil), do: "?"
|
||||
|
||||
defp avatar_text(name) do
|
||||
defp initials(name) do
|
||||
name
|
||||
|> String.split()
|
||||
|> Enum.map(&String.at(&1, 0))
|
||||
|
|
Loading…
Add table
Reference in a new issue