From 6c3eacf66f8406ae29729439bb1613f1e8f18b49 Mon Sep 17 00:00:00 2001 From: Berenice Medel Date: Thu, 27 Jan 2022 15:09:23 -0600 Subject: [PATCH] set active_users as temporary assigns --- lib/live_beats/user_tracker.ex | 8 ++++---- lib/live_beats_web/live/profile_live.ex | 2 +- lib/live_beats_web/live/settings_live.ex | 2 +- lib/live_beats_web/views/layout_view.ex | 9 ++++++++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/live_beats/user_tracker.ex b/lib/live_beats/user_tracker.ex index 6dcb781..2821ccf 100644 --- a/lib/live_beats/user_tracker.ex +++ b/lib/live_beats/user_tracker.ex @@ -1,12 +1,12 @@ defmodule LiveBeats.UserTracker do + @moduledoc """ + Send active users updates using a polling interval. + """ + use GenServer @pubsub LiveBeats.PubSub @poll_interval :timer.seconds(30) - @doc """ - TODO - """ - def subscribe() do Phoenix.PubSub.subscribe(@pubsub, topic()) end diff --git a/lib/live_beats_web/live/profile_live.ex b/lib/live_beats_web/live/profile_live.ex index f56a290..9f9f1bc 100644 --- a/lib/live_beats_web/live/profile_live.ex +++ b/lib/live_beats_web/live/profile_live.ex @@ -107,7 +107,7 @@ defmodule LiveBeatsWeb.ProfileLive do |> list_songs() |> assign_presences() - {:ok, socket, temporary_assigns: [songs: [], presences: []]} + {:ok, socket, temporary_assigns: [songs: [], presences: [], active_users: []]} end def handle_params(params, _url, socket) do diff --git a/lib/live_beats_web/live/settings_live.ex b/lib/live_beats_web/live/settings_live.ex index d18c529..0591bba 100644 --- a/lib/live_beats_web/live/settings_live.ex +++ b/lib/live_beats_web/live/settings_live.ex @@ -70,7 +70,7 @@ defmodule LiveBeatsWeb.SettingsLive do def mount(_parmas, _session, socket) do changeset = Accounts.change_settings(socket.assigns.current_user, %{}) - {:ok, assign(socket, changeset: changeset)} + {:ok, assign(socket, changeset: changeset), temporary_assigns: [active_users: []]} end def handle_event("validate", %{"user" => params}, socket) do diff --git a/lib/live_beats_web/views/layout_view.ex b/lib/live_beats_web/views/layout_view.ex index 69fc6f8..d0cf0f4 100644 --- a/lib/live_beats_web/views/layout_view.ex +++ b/lib/live_beats_web/views/layout_view.ex @@ -13,10 +13,17 @@ defmodule LiveBeatsWeb.LayoutView do

Active Users

-
+
<%= for user <- @users do %> <.link navigate={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" + id={"active-user#{user.id}"} >