chore: more god module work

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-05-01 09:23:54 +02:00
parent 10e2355817
commit 8c7698adbe
14 changed files with 1442 additions and 1144 deletions

View File

@@ -0,0 +1,48 @@
defmodule BDS.Desktop.ShellLive.SessionUtil do
@moduledoc false
import Phoenix.Component, only: [assign: 3]
alias BDS.UI.{Session, Workbench}
@default_new_project_name "New Blog"
def restore_workbench_session(session_payload) do
Session.restore(session_payload)
rescue
_error -> Workbench.new()
end
def next_project_name(projects) do
existing_names = MapSet.new(Enum.map(projects, & &1.name))
Stream.iterate(1, &(&1 + 1))
|> Enum.find_value(fn index ->
candidate =
if index == 1, do: @default_new_project_name, else: "#{@default_new_project_name} #{index}"
if MapSet.member?(existing_names, candidate), do: nil, else: candidate
end)
end
def initial_handled_task_results do
BDS.Tasks.status_snapshot()
|> Map.get(:tasks, [])
|> Enum.filter(fn task -> task.status == :completed and is_map(task.result) end)
|> Enum.map(& &1.id)
|> MapSet.new()
end
def next_completed_task_result(socket, task_status) do
handled = Map.get(socket.assigns, :handled_task_results, MapSet.new())
Enum.find(Map.get(task_status, :tasks, []), fn task ->
task.status == :completed and is_map(task.result) and not MapSet.member?(handled, task.id)
end)
end
def mark_task_result_handled(socket, task_id) do
handled = Map.get(socket.assigns, :handled_task_results, MapSet.new())
assign(socket, :handled_task_results, MapSet.put(handled, task_id))
end
end