Optimize resource usage of the manager when attendees join the event

This commit is contained in:
Alex
2024-09-01 12:46:09 +02:00
parent bcaafa0492
commit 107be10b5c
10 changed files with 30 additions and 21 deletions

View File

@@ -5,7 +5,7 @@
- Fix OIDC to allow only client_secret_basic and client_secret_post auth methods - Fix OIDC to allow only client_secret_basic and client_secret_post auth methods
- Fix minimum length for 2 characters messages - Fix minimum length for 2 characters messages
- Fix poll option order - Fix poll option order
- Fix translations - Fix translations for current interactions
- Improve poll results UI - Improve poll results UI
- Optimize resource usage of the manager when attendees join the event - Optimize resource usage of the manager when attendees join the event

View File

@@ -316,6 +316,13 @@ Hooks.Pickr = {
this.pickr.destroy(); this.pickr.destroy();
}, },
}; };
Hooks.UpdateAttendees = {
mounted() {
this.handleEvent("update-attendees", ({ count }) => {
this.el.textContent = count;
});
},
};
Hooks.Presenter = { Hooks.Presenter = {
mounted() { mounted() {
this.presenter = new Presenter(this); this.presenter = new Presenter(this);

View File

@@ -17,21 +17,17 @@ defmodule ClaperWeb.EventLive.EmbedComponent do
<div class="text-white flex space-x-2 items-center"> <div class="text-white flex space-x-2 items-center">
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
class="h-6 w-6" fill="none"
viewBox="0 0 24 24" viewBox="0 0 24 24"
stroke-width="1.5" stroke-width="1.5"
stroke="currentColor" stroke="currentColor"
fill="none" class="h-6 w-6"
stroke-linecap="round"
stroke-linejoin="round"
> >
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path> <path
<path d="M12 3a3 3 0 0 0 -3 3v12a3 3 0 0 0 3 3"></path> stroke-linecap="round"
<path d="M6 3a3 3 0 0 1 3 3v12a3 3 0 0 1 -3 3"></path> stroke-linejoin="round"
<path d="M13 7h7a1 1 0 0 1 1 1v8a1 1 0 0 1 -1 1h-7"></path> d="M14.25 9.75L16.5 12l-2.25 2.25m-4.5 0L7.5 12l2.25-2.25M6 20.25h12A2.25 2.25 0 0020.25 18V6A2.25 2.25 0 0018 3.75H6A2.25 2.25 0 003.75 6v12A2.25 2.25 0 006 20.25z"
<path d="M5 7h-1a1 1 0 0 0 -1 1v8a1 1 0 0 0 1 1h1"></path> />
<path d="M17 12h.01"></path>
<path d="M13 12h.01"></path>
</svg> </svg>
<span class="font-bold"><%= gettext("See current web content") %></span> <span class="font-bold"><%= gettext("See current web content") %></span>
</div> </div>

View File

@@ -86,7 +86,7 @@ defmodule ClaperWeb.EventLive.Manage do
@impl true @impl true
def handle_info(%{event: "presence_diff"}, %{assigns: %{event: event}} = socket) do def handle_info(%{event: "presence_diff"}, %{assigns: %{event: event}} = socket) do
attendees = Presence.list("event:#{event.uuid}") attendees = Presence.list("event:#{event.uuid}")
{:noreply, assign(socket, :attendees_nb, Enum.count(attendees))} {:noreply, push_event(socket, "update-attendees", %{count: Enum.count(attendees)})}
end end
@impl true @impl true

View File

@@ -402,7 +402,9 @@
clip-rule="evenodd" clip-rule="evenodd"
/> />
</svg> </svg>
<span><%= @attendees_nb %></span> <span id="attendees-count" phx-update="ignore" phx-hook="UpdateAttendees">
<%= @attendees_nb %>
</span>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -53,7 +53,7 @@ defmodule ClaperWeb.EventLive.PollComponent do
<% end %> <% end %>
</div> </div>
<div> <div>
<div class="flex flex-col space-y-3"> <div class="flex flex-col space-y-3 overflow-y-auto max-h-[500px]">
<%= if (length @poll.poll_opts) > 0 do %> <%= if (length @poll.poll_opts) > 0 do %>
<%= for {opt, idx} <- Enum.with_index(@poll.poll_opts) do %> <%= for {opt, idx} <- Enum.with_index(@poll.poll_opts) do %>
<%= if (length @current_poll_vote) > 0 do %> <%= if (length @current_poll_vote) > 0 do %>
@@ -123,14 +123,14 @@ defmodule ClaperWeb.EventLive.PollComponent do
</div> </div>
<%= if (length @selected_poll_opt) == 0 || (length @current_poll_vote) > 0 do %> <%= if (length @selected_poll_opt) == 0 || (length @current_poll_vote) > 0 do %>
<button class="px-3 py-2 text-white font-semibold bg-gray-500 rounded-md mt-3 mb-12 cursor-default"> <button class="px-3 py-2 text-white font-semibold bg-gray-500 rounded-md mt-3 mb-4 cursor-default">
<%= gettext("Vote") %> <%= gettext("Vote") %>
</button> </button>
<% else %> <% else %>
<button <button
phx-click="vote" phx-click="vote"
phx-disable-with="..." phx-disable-with="..."
class="px-3 py-2 text-white font-semibold bg-primary-500 hover:bg-primary-600 rounded-md mt-3 mb-12" class="px-3 py-2 text-white font-semibold bg-primary-500 hover:bg-primary-600 rounded-md mt-3 mb-4"
> >
<%= gettext("Vote") %> <%= gettext("Vote") %>
</button> </button>

View File

@@ -84,7 +84,7 @@ defmodule ClaperWeb.EventLive.Presenter do
@impl true @impl true
def handle_info(%{event: "presence_diff"}, %{assigns: %{event: event}} = socket) do def handle_info(%{event: "presence_diff"}, %{assigns: %{event: event}} = socket) do
attendees = Presence.list("event:#{event.uuid}") attendees = Presence.list("event:#{event.uuid}")
{:noreply, assign(socket, :attendees_nb, Enum.count(attendees))} {:noreply, push_event(socket, "update-attendees", %{count: Enum.count(attendees)})}
end end
@impl true @impl true

View File

@@ -234,7 +234,9 @@
<div class="inline-flex justify-between items-center text-white text-2xl"> <div class="inline-flex justify-between items-center text-white text-2xl">
<img src="/images/icons/online-users.svg" class="h-12 mr-2" /> <img src="/images/icons/online-users.svg" class="h-12 mr-2" />
<span id="counter"><%= @attendees_nb %></span> <span id="counter" phx-hook="UpdateAttendees" phx-update="ignore">
<%= @attendees_nb %>
</span>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -166,7 +166,7 @@ defmodule ClaperWeb.EventLive.Show do
def handle_info(%{event: "presence_diff"}, %{assigns: %{event: event}} = socket) do def handle_info(%{event: "presence_diff"}, %{assigns: %{event: event}} = socket) do
attendees = Presence.list("event:#{event.uuid}") attendees = Presence.list("event:#{event.uuid}")
{:noreply, assign(socket, :attendees_nb, Enum.count(attendees))} {:noreply, push_event(socket, "update-attendees", %{count: Enum.count(attendees)})}
end end
@impl true @impl true

View File

@@ -50,7 +50,9 @@
<div class="inline-flex justify-between items-center text-white text-sm"> <div class="inline-flex justify-between items-center text-white text-sm">
<img src="/images/icons/online-users.svg" class="h-6 mr-2" /> <img src="/images/icons/online-users.svg" class="h-6 mr-2" />
<span id="counter"><%= @attendees_nb %></span> <span id="counter" phx-update="ignore" phx-hook="UpdateAttendees">
<%= @attendees_nb %>
</span>
</div> </div>
</div> </div>
</div> </div>