Fix a couple bugs

This commit is contained in:
Chris McCord 2024-06-04 17:27:51 -04:00
parent d517cc0f55
commit 44f86837f1
8 changed files with 40 additions and 29 deletions

View file

@ -197,10 +197,12 @@ Hooks.AudioPlayer = {
Hooks.Ping = { Hooks.Ping = {
mounted(){ mounted(){
let pingEvery
this.handleEvent("pong", () => { this.handleEvent("pong", () => {
let rtt = Date.now() - this.nowMs let rtt = Date.now() - this.nowMs
pingEvery = pingEvery ? 5000 : 1000
this.el.innerText = `ping: ${rtt}ms` this.el.innerText = `ping: ${rtt}ms`
this.timer = setTimeout(() => this.ping(rtt), 5000) this.timer = setTimeout(() => this.ping(rtt), pingEvery)
}) })
this.ping(null) this.ping(null)
}, },

View file

@ -13,10 +13,9 @@ config :live_beats, :github,
# Configure your database # Configure your database
config :live_beats, LiveBeats.Repo, config :live_beats, LiveBeats.Repo,
username: "root", username: "postgres",
password: nil, password: "postgres",
hostname: "localhost", hostname: "localhost",
port: 26257,
database: "live_beats_dev", database: "live_beats_dev",
migration_lock: false, migration_lock: false,
stacktrace: true, stacktrace: true,

View file

@ -304,6 +304,7 @@ defmodule LiveBeats.MediaLibrary do
def get_profile!(%Accounts.User{} = user) do def get_profile!(%Accounts.User{} = user) do
%Profile{ %Profile{
user_id: user.id, user_id: user.id,
songs_count: user.songs_count,
username: user.username, username: user.username,
tagline: user.profile_tagline, tagline: user.profile_tagline,
avatar_url: user.avatar_url, avatar_url: user.avatar_url,

View file

@ -1,3 +1,8 @@
defmodule LiveBeats.MediaLibrary.Profile do defmodule LiveBeats.MediaLibrary.Profile do
defstruct user_id: nil, username: nil, tagline: nil, avatar_url: nil, external_homepage_url: nil defstruct user_id: nil,
username: nil,
tagline: nil,
avatar_url: nil,
external_homepage_url: nil,
songs_count: 0
end end

View file

@ -161,16 +161,13 @@ defmodule LiveBeatsWeb.Presence.BadgeComponent do
<div class="flex-1 flex items-center justify-between text-gray-900 text-sm font-medium hover:text-gray-600 pl-3"> <div class="flex-1 flex items-center justify-between text-gray-900 text-sm font-medium hover:text-gray-600 pl-3">
<div class="flex-1 py-1 text-sm truncate"> <div class="flex-1 py-1 text-sm truncate">
<%= @presence.username %> <%= @presence.username %>
<%= if @ping do %> <p class="text-gray-400 text-xs">ping: <%= if @ping, do: "#{@ping}ms", else: "..." %></p>
<p class="text-gray-400 text-xs">ping: <%= @ping %>ms</p>
<%= if @region do %>
<img <img
:if={@region}
class="inline w-7 h-7 absolute right-3 top-3" class="inline w-7 h-7 absolute right-3 top-3"
src={"https://fly.io/phx/ui/images/#{@region}.svg"} src={"https://fly.io/phx/ui/images/#{@region}.svg"}
title={region_name(@region)} title={region_name(@region)}
/> />
<% end %>
<% end %>
</div> </div>
</div> </div>
</.link> </.link>

View file

@ -524,7 +524,7 @@ defmodule LiveBeatsWeb.CoreComponents do
attr :patch, :string attr :patch, :string
attr :primary, :boolean, default: false attr :primary, :boolean, default: false
attr :rest, :global attr :rest, :global, include: ["disabled"]
slot :inner_block slot :inner_block

View file

@ -52,7 +52,7 @@ defmodule LiveBeatsWeb.PlayerLive do
<div class="mx-auto flex"></div> <div class="mx-auto flex"></div>
<% end %> <% end %>
<%= if is_nil(@profile) or @own_profile? do %> <%= if @own_profile? do %>
<!-- prev --> <!-- prev -->
<button <button
type="button" type="button"
@ -137,7 +137,8 @@ defmodule LiveBeatsWeb.PlayerLive do
</svg> </svg>
</button> </button>
<!-- next --> <!-- next -->
<% else %> <% end %>
<%= if !@own_profile? && @profile && @profile.songs_count > 0 do %>
<button type="button" class="mx-auto scale-75"></button> <button type="button" class="mx-auto scale-75"></button>
<!-- stop button --> <!-- stop button -->
<button <button
@ -185,14 +186,13 @@ defmodule LiveBeatsWeb.PlayerLive do
socket = socket =
socket socket
|> assign( |> assign(
foo: true,
song: nil, song: nil,
playing: false, playing: false,
profile: nil, profile: nil,
current_user_id: current_user.id, current_user_id: current_user.id,
own_profile?: false own_profile?: false
) )
|> switch_profile(current_user.active_profile_user_id || current_user.id) |> switch_profile(current_user.active_profile_user_id)
{:ok, socket, layout: false, temporary_assigns: []} {:ok, socket, layout: false, temporary_assigns: []}
end end

View file

@ -43,6 +43,7 @@ defmodule LiveBeatsWeb.ProfileLive do
<:actions> <:actions>
<%= if @active_profile_id == @profile.user_id do %> <%= if @active_profile_id == @profile.user_id do %>
<.button <.button
:if={@songs_count > 0}
primary primary
phx-click={ phx-click={
JS.push("switch_profile", value: %{user_id: nil}, target: "#player", loading: "#player") JS.push("switch_profile", value: %{user_id: nil}, target: "#player", loading: "#player")
@ -52,6 +53,7 @@ defmodule LiveBeatsWeb.ProfileLive do
</.button> </.button>
<% else %> <% else %>
<.button <.button
:if={@songs_count > 0}
primary primary
phx-click={ phx-click={
JS.push("switch_profile", JS.push("switch_profile",
@ -113,6 +115,7 @@ defmodule LiveBeatsWeb.ProfileLive do
rows={@streams.songs} rows={@streams.songs}
row_id={fn {id, _song} -> id end} row_id={fn {id, _song} -> id end}
row_click={ row_click={
@owns_profile? &&
fn {id, song} -> fn {id, song} ->
JS.push("play_or_pause", JS.push("play_or_pause",
loading: "#songs tbody, ##{id}", loading: "#songs tbody, ##{id}",
@ -121,12 +124,15 @@ defmodule LiveBeatsWeb.ProfileLive do
end end
} }
streamable streamable
sortable_drop="row_dropped" sortable_drop={@owns_profile? && "row_dropped"}
> >
<:col <:col
:let={{_id, song}} :let={{_id, song}}
label="Title" label="Title"
class!="px-6 py-3 text-sm font-medium text-gray-900 min-w-[200px] md:min-w-[20rem] cursor-pointer" class!={[
"px-6 py-3 text-sm font-medium text-gray-900 min-w-[200px] md:min-w-[20rem]",
@owns_profile? && "cursor-pointer"
]}
> >
<span :if={song.status == :playing} class="flex pt-1 relative mr-2 w-4"> <span :if={song.status == :playing} class="flex pt-1 relative mr-2 w-4">
<span class="w-3 h-3 animate-ping bg-purple-400 rounded-full absolute"></span> <span class="w-3 h-3 animate-ping bg-purple-400 rounded-full absolute"></span>
@ -428,9 +434,10 @@ defmodule LiveBeatsWeb.ProfileLive do
end end
defp assign_presences(socket) do defp assign_presences(socket) do
%{profile: profile} = socket.assigns
socket = assign(socket, presences_count: 0, presences: %{}, presence_ids: %{}) socket = assign(socket, presences_count: 0, presences: %{}, presence_ids: %{})
if profile = socket.assigns.profile do if profile do
profile profile
|> LiveBeatsWeb.Presence.list_profile_users() |> LiveBeatsWeb.Presence.list_profile_users()
|> Enum.reduce(socket, fn {_, presence}, acc -> assign_presence(acc, presence) end) |> Enum.reduce(socket, fn {_, presence}, acc -> assign_presence(acc, presence) end)