neiam
/apollos_crib
It's Apollo's Crib
public · Issues · Pulls 1 · Labels · Forks · Compare · Actions success · Badges · Packages
⭐
Log in to mark this repository.
tint QOL
abf819f · gmorell · 2025-08-26 02:59
Files changed
modified
apps/room_sanctum/lib/room_sanctum_web/live/cfg_source_live/index.ex
+24
−3
@@ -7,11 +7,13 @@ defmodule RoomSanctumWeb.SourceLive.Index do
| 7 | 7 | @impl true |
| 8 | 8 | def mount(_params, _session, socket) do |
| 9 | 9 | sources = list_cfg_sources(socket.assigns.current_user.id) |
| 10 | + available_tints = get_available_tints(sources) | |
| 10 | 11 | |
| 11 | 12 | {:ok, |
| 12 | 13 | socket |
| 13 | 14 | |> assign(:show_info, false) |
| 14 | 15 | |> assign(:tint, nil) |
| 16 | + |> assign(:available_tints, available_tints) | |
| 15 | 17 | |> assign(:selected_sources, MapSet.new()) |
| 16 | 18 | |> assign(:export_json, nil) |
| 17 | 19 | |> assign(:show_export_modal, false) |
@@ -52,15 +54,25 @@ defmodule RoomSanctumWeb.SourceLive.Index do
| 52 | 54 | |
| 53 | 55 | @impl true |
| 54 | 56 | def handle_info({RoomSanctumWeb.SourceLive.FormComponent, {:saved, source}}, socket) do |
| 55 | − {:noreply, stream_insert(socket, :cfg_sources, source)} | |
| 57 | + sources = list_cfg_sources(socket.assigns.current_user.id) | |
| 58 | + available_tints = get_available_tints(sources) | |
| 59 | + | |
| 60 | + {:noreply, | |
| 61 | + socket | |
| 62 | + |> assign(:available_tints, available_tints) | |
| 63 | + |> stream_insert(:cfg_sources, source)} | |
| 56 | 64 | end |
| 57 | 65 | |
| 58 | 66 | @impl true |
| 59 | 67 | def handle_info({RoomSanctumWeb.SourceLive.ImportComponent, {:sources_imported, count}}, socket) do |
| 68 | + sources = list_cfg_sources(socket.assigns.current_user.id) | |
| 69 | + available_tints = get_available_tints(sources) | |
| 70 | + | |
| 60 | 71 | {:noreply, |
| 61 | 72 | socket |
| 62 | 73 | |> put_flash(:info, "Successfully imported #{count} sources") |
| 63 | − |> stream(:cfg_sources, list_cfg_sources(socket.assigns.current_user.id), reset: true)} | |
| 74 | + |> assign(:available_tints, available_tints) | |
| 75 | + |> stream(:cfg_sources, sources, reset: true)} | |
| 64 | 76 | end |
| 65 | 77 | |
| 66 | 78 | @impl true |
@@ -182,7 +194,16 @@ defmodule RoomSanctumWeb.SourceLive.Index do
| 182 | 194 | end |
| 183 | 195 | |
| 184 | 196 | defp list_cfg_sources(uid, tint) do |
| 185 | − Configuration.list_cfg_sources({:user, uid}) |> Enum.filter(fn s -> s.meta.tint == tint end) | |
| 197 | + Configuration.list_cfg_sources({:user, uid}) |> Enum.filter(fn s -> | |
| 198 | + s.meta && s.meta.tint == tint | |
| 199 | + end) | |
| 200 | + end | |
| 201 | + | |
| 202 | + defp get_available_tints(sources) do | |
| 203 | + sources | |
| 204 | + |> Enum.filter_map(&(&1.meta && &1.meta.tint), &(&1.meta.tint)) | |
| 205 | + |> Enum.uniq() | |
| 206 | + |> Enum.sort() | |
| 186 | 207 | end |
| 187 | 208 | |
| 188 | 209 | defp import_sources(sources_data, user_id) do |
modified
apps/room_sanctum/lib/room_sanctum_web/live/cfg_source_live/index.html.heex
+8
−1
@@ -97,6 +97,13 @@
| 97 | 97 | <span class="text-sky-500"></span> |
| 98 | 98 | <span class="text-stone-500"></span> |
| 99 | 99 | <span class="text-stone-950"></span> |
| 100 | + | |
| 101 | + <!-- Available tints - clickable filters --> | |
| 102 | + <%= for tint <- @available_tints do %> | |
| 103 | + <span class="cursor-pointer mx-1" phx-click="set-tint" phx-value-tint={tint}> | |
| 104 | + <i class={"fa-solid fa-circle text-#{tint}-500 hover:text-#{tint}-700 #{if @tint == tint, do: "text-lg", else: ""}"}></i> | |
| 105 | + </span> | |
| 106 | + <% end %> | |
| 100 | 107 | </th> |
| 101 | 108 | <th></th> |
| 102 | 109 | </tr> |
@@ -133,7 +140,7 @@
| 133 | 140 | </td> |
| 134 | 141 | <td> |
| 135 | 142 | <%= if source.meta.tint do %> |
| 136 | − <i class={"fa fa-circle text-#{source.meta.tint}-500"} phx-click="set-tint" phx-value-tint={source.meta.tint} ></i> | |
| 143 | + <i class={"fa fa-circle fa-fw fa-2x text-#{source.meta.tint}-500"} phx-click="set-tint" phx-value-tint={source.meta.tint} ></i> | |
| 137 | 144 | <% end %> |
| 138 | 145 | </td> |
| 139 | 146 | <td class={"bg-#{@tint}-500"}> |
Parents: 9448f80