fix: A1-1 implement archived→draft/published transitions, wire archive/unarchive into post editor quick actions, complete all i18n translations

This commit is contained in:
2026-05-28 18:39:52 +02:00
parent f99e139fa5
commit 82ce445c44
12 changed files with 1417 additions and 1001 deletions

View File

@@ -204,6 +204,14 @@ defmodule BDS.Desktop.ShellLive.PostEditor do
{:noreply, do_delete(socket)}
end
def handle_event("archive_post_editor", _params, socket) do
{:noreply, do_archive(socket)}
end
def handle_event("unarchive_post_editor", _params, socket) do
{:noreply, do_unarchive(socket)}
end
def handle_event("set_post_editor_mode", %{"mode" => mode}, socket) do
normalized_mode = normalize_mode(mode)
@@ -370,6 +378,8 @@ defmodule BDS.Desktop.ShellLive.PostEditor do
editing_canonical_language?(translations, active_language, canonical_language),
can_publish?: post.status == :draft,
can_delete?: post.status == :published,
can_archive?: post.status in [:draft, :published],
can_unarchive?: post.status == :archived,
has_published_version?: has_published_version?(post),
discard_label: discard_label(post),
discard_title: discard_title(post),
@@ -559,6 +569,72 @@ defmodule BDS.Desktop.ShellLive.PostEditor do
end
end
defp do_archive(socket) do
case socket.assigns.post do
nil ->
socket
%Post{} = post ->
case Posts.archive_post(post.id) do
{:ok, archived_post} ->
socket =
socket
|> assign(:post, archived_post)
|> assign(:drafts, %{})
|> assign(:dirty?, false)
|> assign(:quick_actions_open?, false)
|> build_data()
Notify.tab_meta(
:post,
post.id,
archived_post.title || archived_post.slug || archived_post.id,
"archived"
)
Notify.dirty(:post, post.id, false)
notify_output(socket, dgettext("ui", "Post"), dgettext("ui", "Post archived"))
{:error, reason} ->
notify_output(socket, dgettext("ui", "Post"), inspect(reason), "error")
|> build_data()
end
end
end
defp do_unarchive(socket) do
case socket.assigns.post do
nil ->
socket
%Post{} = post ->
case Posts.unarchive_post(post.id) do
{:ok, unarchived_post} ->
socket =
socket
|> assign(:post, unarchived_post)
|> assign(:drafts, %{})
|> assign(:dirty?, false)
|> assign(:quick_actions_open?, false)
|> build_data()
Notify.tab_meta(
:post,
post.id,
unarchived_post.title || unarchived_post.slug || unarchived_post.id,
"draft"
)
Notify.dirty(:post, post.id, false)
notify_output(socket, dgettext("ui", "Post"), dgettext("ui", "Post unarchived"))
{:error, reason} ->
notify_output(socket, dgettext("ui", "Post"), inspect(reason), "error")
|> build_data()
end
end
end
defp do_detect_language(socket) do
if Map.get(socket.assigns, :offline_mode, true) do
notify_output(

View File

@@ -61,6 +61,42 @@
<small><%= dgettext("ui", "Select a target language for this post") %></small>
</span>
</button>
<%= if @post_editor.can_archive? or @post_editor.can_unarchive? do %>
<div class="quick-actions-divider"></div>
<%= if @post_editor.can_archive? do %>
<button
class="quick-action-item ui-dropdown-item flex items-start gap-3 text-left"
data-testid="post-archive-button"
type="button"
phx-click="archive_post_editor"
phx-target={@myself}
>
<span class="quick-action-icon">📦</span>
<span class="quick-action-text flex min-w-0 flex-1 flex-col">
<strong><%= dgettext("ui", "Archive") %></strong>
<small><%= dgettext("ui", "Move this post to the archive") %></small>
</span>
</button>
<% end %>
<%= if @post_editor.can_unarchive? do %>
<button
class="quick-action-item ui-dropdown-item flex items-start gap-3 text-left"
data-testid="post-unarchive-button"
type="button"
phx-click="unarchive_post_editor"
phx-target={@myself}
>
<span class="quick-action-icon">📤</span>
<span class="quick-action-text flex min-w-0 flex-1 flex-col">
<strong><%= dgettext("ui", "Unarchive") %></strong>
<small><%= dgettext("ui", "Restore this post to draft") %></small>
</span>
</button>
<% end %>
<% end %>
</div>
<% end %>
</div>