diff --git a/lib/live_beats/media_library.ex b/lib/live_beats/media_library.ex
index ab11e58..37e098a 100644
--- a/lib/live_beats/media_library.ex
+++ b/lib/live_beats/media_library.ex
@@ -192,6 +192,19 @@ defmodule LiveBeats.MediaLibrary do
|> Repo.all()
end
+ def list_active_profiles(opts) do
+ from(s in Song,
+ inner_join: u in LiveBeats.Accounts.User,
+ on: s.user_id == u.id,
+ where: s.status in [:playing],
+ limit: ^Keyword.fetch!(opts, :limit),
+ order_by: [desc: s.updated_at],
+ select: struct(u, [:id, :username, :profile_tagline])
+ )
+ |> Repo.all()
+ |> Enum.map(&get_profile!/1)
+ end
+
def get_current_active_song(%Profile{user_id: user_id}) do
Repo.one(from s in Song, where: s.user_id == ^user_id and s.status in [:playing, :paused])
end
diff --git a/lib/live_beats_web/controllers/user_auth.ex b/lib/live_beats_web/controllers/user_auth.ex
index a4ccbd3..02b881d 100644
--- a/lib/live_beats_web/controllers/user_auth.ex
+++ b/lib/live_beats_web/controllers/user_auth.ex
@@ -135,5 +135,7 @@ defmodule LiveBeatsWeb.UserAuth do
defp maybe_store_return_to(conn), do: conn
- def signed_in_path(conn), do: Routes.song_index_path(conn, :index, conn.assigns.current_user.username)
+ def signed_in_path(conn) do
+ LiveBeatsWeb.LiveHelpers.profile_path(conn.assigns.current_user)
+ end
end
diff --git a/lib/live_beats_web/live/live_helpers.ex b/lib/live_beats_web/live/live_helpers.ex
index dd77d96..a7e98f8 100644
--- a/lib/live_beats_web/live/live_helpers.ex
+++ b/lib/live_beats_web/live/live_helpers.ex
@@ -5,8 +5,15 @@ defmodule LiveBeatsWeb.LiveHelpers do
alias LiveBeatsWeb.Router.Helpers, as: Routes
alias Phoenix.LiveView.JS
- def home_path(socket) do
- Routes.song_index_path(socket, :index, socket.assigns.current_user.username)
+ alias LiveBeats.Accounts
+ alias LiveBeats.MediaLibrary
+
+ def profile_path(%Accounts.User{} = current_user) do
+ Routes.song_index_path(LiveBeatsWeb.Endpoint, :index, current_user.username)
+ end
+
+ def profile_path(%MediaLibrary.Profile{} = profile) do
+ Routes.song_index_path(LiveBeatsWeb.Endpoint, :index, profile.username)
end
def flash(%{kind: :error} = assigns) do
diff --git a/lib/live_beats_web/live/nav.ex b/lib/live_beats_web/live/nav.ex
index be6dec0..fb7a777 100644
--- a/lib/live_beats_web/live/nav.ex
+++ b/lib/live_beats_web/live/nav.ex
@@ -1,7 +1,9 @@
defmodule LiveBeatsWeb.Nav do
import Phoenix.LiveView
+ alias LiveBeats.MediaLibrary
+
def on_mount(:default, _params, _session, socket) do
- {:cont, assign(socket, genres: LiveBeats.MediaLibrary.list_genres())}
+ {:cont, assign(socket, :active_users, MediaLibrary.list_active_profiles(limit: 20))}
end
end
diff --git a/lib/live_beats_web/live/player_live.ex b/lib/live_beats_web/live/player_live.ex
index e63e972..a5d5291 100644
--- a/lib/live_beats_web/live/player_live.ex
+++ b/lib/live_beats_web/live/player_live.ex
@@ -38,7 +38,7 @@ defmodule LiveBeatsWeb.PlayerLive do
<%= if @profile do %>
<.link
- redirect_to={Routes.song_index_path(@socket, :index, @profile.username)}
+ redirect_to={profile_path(@profile)}
class="mx-auto flex outline border-2 border-white border-opacity-20 rounded-md p-1 pr-2"
>
<.icon name={:user_circle}/>
diff --git a/lib/live_beats_web/live/song_live/index.ex b/lib/live_beats_web/live/song_live/index.ex
index 14c64d7..27d8d0c 100644
--- a/lib/live_beats_web/live/song_live/index.ex
+++ b/lib/live_beats_web/live/song_live/index.ex
@@ -178,7 +178,7 @@ defmodule LiveBeatsWeb.SongLive.Index do
LayoutComponent.show_modal(UploadFormComponent, %{
id: :new,
confirm: {"Save", type: "submit", form: "song-form"},
- patch_to: home_path(socket),
+ patch_to: profile_path(socket.assigns.current_user),
song: socket.assigns.song,
title: socket.assigns.page_title,
current_user: socket.assigns.current_user
diff --git a/lib/live_beats_web/live/song_live/upload_form_component.ex b/lib/live_beats_web/live/song_live/upload_form_component.ex
index 4c93609..b14bfe9 100644
--- a/lib/live_beats_web/live/song_live/upload_form_component.ex
+++ b/lib/live_beats_web/live/song_live/upload_form_component.ex
@@ -54,7 +54,7 @@ defmodule LiveBeatsWeb.SongLive.UploadFormComponent do
{:noreply,
socket
|> put_flash(:info, "#{map_size(songs)} song(s) uploaded")
- |> push_redirect(to: home_path(socket))}
+ |> push_redirect(to: profile_path(current_user))}
{:error, _reason} ->
{:noreply, socket}
diff --git a/lib/live_beats_web/templates/layout/live.html.heex b/lib/live_beats_web/templates/layout/live.html.heex
index 8521b3e..d602b08 100644
--- a/lib/live_beats_web/templates/layout/live.html.heex
+++ b/lib/live_beats_web/templates/layout/live.html.heex
@@ -22,83 +22,11 @@
alt="Workflow">
+ <.sidebar_account_dropdown id="mobile-account-dropdown" current_user={@current_user}/>
+
-
-
- <%= if @current_user do %>
-
-
-
-
-
-
-
-
- <%= @current_user.name %>
- @<%= @current_user.username %>
-
-
-
-
-
-
-
-
-
-
-
- <% else %>
- <%= live_redirect to: Routes.sign_in_path(@socket, :index),
- class: "text-gray-600 hover:text-gray-900 hover:bg-gray-50 group flex items-center px-2 py-2 text-base leading-5 font-medium rounded-md" do %>
-
-
-
-
- Sign in
- <% end %>
- <% end %>
-
-
-
+ <.sidebar_nav_links current_user={@current_user}/>
+ <.sidebar_active_users id="desktop-active-users" users={@active_users}/>
@@ -118,49 +46,7 @@
- <%= if @current_user do %>
-
-
-
-
-
-
-
-
- <%= @current_user.name %>
- @<%= @current_user.username %>
-
-
-
-
-
-
-
-
-
-
-
-
- <%= link "Logout", to: Routes.o_auth_callback_path(@socket, :sign_out), method: :delete, role: "menuitem", id: "options-menu-item-5", class: "block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" %>
-
-
-
- <% end %>
+ <.sidebar_account_dropdown id="account-dropdown" current_user={@current_user}/>
Search
@@ -180,57 +66,9 @@
-
-
- <%= if @current_user do %>
- <.link
- redirect_to={Routes.song_index_path(@socket, :index, @current_user.username)}
- class="text-gray-700 hover:text-gray-900 hover:bg-gray-50 group flex items-center px-2 py-2 text-sm font-medium rounded-md"
- >
- <.icon name={:music_note} outlined class="text-gray-400 group-hover:text-gray-500 mr-3 flex-shrink-0 h-6 w-6"/>
- My Songs
-
-
- <.link
- redirect_to={Routes.settings_path(@socket, :edit)}
- class="text-gray-700 hover:text-gray-900 hover:bg-gray-50 group flex items-center px-2 py-2 text-sm font-medium rounded-md"
- >
- <.icon name={:adjustments} outlined class="text-gray-400 group-hover:text-gray-500 mr-3 flex-shrink-0 h-6 w-6"/>
- Settings
-
- <% end %>
-
- <%= unless @current_user do %>
- <%= live_redirect to: Routes.sign_in_path(@socket, :index),
- class: "text-gray-700 hover:text-gray-900 hover:bg-gray-50 group flex items-center px-2 py-2 text-sm font-medium rounded-md" do %>
-
-
-
- Sign in
- <% end %>
- <% end %>
-
-
-
+ <.sidebar_nav_links current_user={@current_user}/>
+
+ <.sidebar_active_users id="mobile-active-users" users={@active_users}/>
diff --git a/lib/live_beats_web/views/layout_view.ex b/lib/live_beats_web/views/layout_view.ex
index 512e481..66c8160 100644
--- a/lib/live_beats_web/views/layout_view.ex
+++ b/lib/live_beats_web/views/layout_view.ex
@@ -4,4 +4,116 @@ defmodule LiveBeatsWeb.LayoutView do
# Phoenix LiveDashboard is available only in development by default,
# so we instruct Elixir to not warn if the dashboard route is missing.
@compile {:no_warn_undefined, {Routes, :live_dashboard_path, 2}}
+
+ def sidebar_active_users(assigns) do
+ ~H"""
+
+
+ Active Users
+
+
+ <%= for user <- @users do %>
+ <.link redirect_to={profile_path(user)}
+ class="group flex items-center px-3 py-2 text-base leading-5 font-medium text-gray-600 rounded-md hover:text-gray-900 hover:bg-gray-50"
+ >
+
+
+ <%= user.username %>
+
+
+ <% end %>
+
+
+ """
+ end
+
+ def sidebar_nav_links(assigns) do
+ ~H"""
+
+ <%= if @current_user do %>
+ <.link
+ redirect_to={profile_path(@current_user)}
+ class="text-gray-700 hover:text-gray-900 hover:bg-gray-50 group flex items-center px-2 py-2 text-sm font-medium rounded-md"
+ >
+ <.icon name={:music_note} outlined class="text-gray-400 group-hover:text-gray-500 mr-3 flex-shrink-0 h-6 w-6"/>
+ My Songs
+
+
+ <.link
+ redirect_to={Routes.settings_path(LiveBeatsWeb.Endpoint, :edit)}
+ class="text-gray-700 hover:text-gray-900 hover:bg-gray-50 group flex items-center px-2 py-2 text-sm font-medium rounded-md"
+ >
+ <.icon name={:adjustments} outlined class="text-gray-400 group-hover:text-gray-500 mr-3 flex-shrink-0 h-6 w-6"/>
+ Settings
+
+ <% else %>
+ <.link redirect_to={Routes.sign_in_path(LiveBeatsWeb.Endpoint, :index)}
+ class="text-gray-700 hover:text-gray-900 hover:bg-gray-50 group flex items-center px-2 py-2 text-sm font-medium rounded-md"
+ >
+
+
+
+ Sign in
+
+ <% end %>
+
+ """
+ end
+
+ def sidebar_account_dropdown(assigns) do
+ ~H"""
+
+
+
+
+
+
+
+
+ <%= @current_user.name %>
+ @<%= @current_user.username %>
+
+
+
+
+
+
+
+
+
+
+ <.link
+ redirect_to={profile_path(@current_user)}
+ class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100"
+ >View Profile
+
Settings
+
Notifications
+
+
+
+ <.link
+ href={Routes.o_auth_callback_path(LiveBeatsWeb.Endpoint, :sign_out)}
+ method={:delete}
+ role="menuitem"
+ class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100"
+ >Sign out
+
+
+
+ """
+ end
end