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 = {
mounted(){
let pingEvery
this.handleEvent("pong", () => {
let rtt = Date.now() - this.nowMs
pingEvery = pingEvery ? 5000 : 1000
this.el.innerText = `ping: ${rtt}ms`
this.timer = setTimeout(() => this.ping(rtt), 5000)
this.timer = setTimeout(() => this.ping(rtt), pingEvery)
})
this.ping(null)
},

View file

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

View file

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

View file

@ -1,3 +1,8 @@
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

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 py-1 text-sm truncate">
<%= @presence.username %>
<%= if @ping do %>
<p class="text-gray-400 text-xs">ping: <%= @ping %>ms</p>
<%= if @region do %>
<p class="text-gray-400 text-xs">ping: <%= if @ping, do: "#{@ping}ms", else: "..." %></p>
<img
:if={@region}
class="inline w-7 h-7 absolute right-3 top-3"
src={"https://fly.io/phx/ui/images/#{@region}.svg"}
title={region_name(@region)}
/>
<% end %>
<% end %>
</div>
</div>
</.link>

View file

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

View file

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

View file

@ -43,6 +43,7 @@ defmodule LiveBeatsWeb.ProfileLive do
<:actions>
<%= if @active_profile_id == @profile.user_id do %>
<.button
:if={@songs_count > 0}
primary
phx-click={
JS.push("switch_profile", value: %{user_id: nil}, target: "#player", loading: "#player")
@ -52,6 +53,7 @@ defmodule LiveBeatsWeb.ProfileLive do
</.button>
<% else %>
<.button
:if={@songs_count > 0}
primary
phx-click={
JS.push("switch_profile",
@ -113,6 +115,7 @@ defmodule LiveBeatsWeb.ProfileLive do
rows={@streams.songs}
row_id={fn {id, _song} -> id end}
row_click={
@owns_profile? &&
fn {id, song} ->
JS.push("play_or_pause",
loading: "#songs tbody, ##{id}",
@ -121,12 +124,15 @@ defmodule LiveBeatsWeb.ProfileLive do
end
}
streamable
sortable_drop="row_dropped"
sortable_drop={@owns_profile? && "row_dropped"}
>
<:col
:let={{_id, song}}
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 class="w-3 h-3 animate-ping bg-purple-400 rounded-full absolute"></span>
@ -428,9 +434,10 @@ defmodule LiveBeatsWeb.ProfileLive do
end
defp assign_presences(socket) do
%{profile: profile} = socket.assigns
socket = assign(socket, presences_count: 0, presences: %{}, presence_ids: %{})
if profile = socket.assigns.profile do
if profile do
profile
|> LiveBeatsWeb.Presence.list_profile_users()
|> Enum.reduce(socket, fn {_, presence}, acc -> assign_presence(acc, presence) end)