perf: optimize member index selection calculations

Calculate selected_count, any_selected? and mailto_bcc once in assigns
instead of recalculating Enum.any? and Enum.count multiple times in template.
This improves render performance and makes the template code more readable.
This commit is contained in:
Moritz 2025-12-16 14:50:52 +01:00
parent 222af635ae
commit fb91f748c2
2 changed files with 43 additions and 14 deletions

View file

@ -7,25 +7,17 @@
id="copy-emails-btn"
phx-hook="CopyToClipboard"
phx-click="copy_emails"
disabled={not Enum.any?(@members, &MapSet.member?(@selected_members, &1.id))}
disabled={not @any_selected?}
aria-label={gettext("Copy email addresses of selected members")}
>
<.icon name="hero-clipboard-document" />
{gettext("Copy email addresses")} ({Enum.count(
@members,
&MapSet.member?(@selected_members, &1.id)
)})
{gettext("Copy email addresses")} ({@selected_count})
</.button>
<.button
class="secondary"
id="open-email-btn"
href={
"mailto:?bcc=" <>
(MvWeb.MemberLive.Index.format_selected_member_emails(@members, @selected_members)
|> Enum.join(", ")
|> URI.encode())
}
disabled={not Enum.any?(@members, &MapSet.member?(@selected_members, &1.id))}
href={"mailto:?bcc=" <> URI.encode(@mailto_bcc)}
disabled={not @any_selected?}
aria-label={gettext("Open email program with BCC recipients")}
>
<.icon name="hero-envelope" />