dzen.nstarikov.ru/dzen-assistant/docs/superpowers/plans/2026-08-15-mobile-article-editor.md

9.3 KiB
Raw Blame History

Mobile Article Editor Implementation Plan

For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (- [ ]) syntax for tracking.

Goal: Make the existing article editor usable on a 320–430 px phone, with an explicit safe return to drafts and no horizontal overflow.

Architecture: Keep the current selectedArticle overlay and Editor.js instance. Add a small, local editor-navigation state machine in App.tsx for close confirmation and a mobile-only command hierarchy: persistent back/status top bar, main save/publish bottom bar, and a native disclosure for secondary actions. Use scoped CSS in index.css so desktop controls preserve their current layout.

Tech Stack: React 19, TypeScript, Tailwind CSS, shadcn-style Button, Editor.js, Vite.


File structure

  • Modify: admin/src/App.tsx — editor return guard, responsive action groups, semantic feature-image trigger and keyboard handling.
  • Modify: admin/src/index.css — 640 px task-view layout, safe-area bottom actions, touch sizes and no-overflow rules.
  • Modify: admin/src/components/ui/button.tsx — add a reusable 44 px touch-icon button size without changing existing compact desktop sizes.

Task 1: Safe return from the editor

Files:

  • Modify: admin/src/App.tsx:1211-1235,1624-1640,2108-2115,2695-2773

  • Step 1: Reproduce the loss-of-context path

Run the Vite app, open a draft, make a title change, then use the current close icon.

Expected: the modal closes immediately, with no explicit return label or save/discard decision.

  • Step 2: Add local close-confirmation state and a single requestArticleClose function

Add articleCloseConfirmOpen beside the existing editor state. Implement requestArticleClose so it calls setSelectedArticle(null) immediately only when editorDirty is false; otherwise it opens a confirmation panel. Implement explicit handlers: stayInArticle, discardArticleChanges, and saveAndCloseArticle (await saveArticle(false) first; only close after it resolves).

function requestArticleClose() {
  if (!editorDirty) {
    setSelectedArticle(null)
    return
  }
  setArticleCloseConfirmOpen(true)
}

async function saveAndCloseArticle() {
  const saved = await saveArticle(false)
  if (saved) setSelectedArticle(null)
}
  • Step 3: Route all editor exits through the guard

Replace the header close callback with requestArticleClose. In saveAndPublishArticle, retain closing only after the successful publish request. Add a keydown effect active while selectedArticle is set: Escape closes the secondary-actions disclosure if open, otherwise calls requestArticleClose.

  • Step 4: Render an accessible confirmation panel

Render a labelled modal/panel only while articleCloseConfirmOpen is true. It must contain: title «Сохранить изменения?», text explaining that unsaved edits stay only in this browser, and buttons «Остаться», «Не сохранять», «Сохранить и выйти». Disable the save button while editorBusy is true. Return focus to the «К черновикам» trigger when the panel closes.

  • Step 5: Manually verify return behavior

Check each branch: clean back closes; dirty → stay remains; dirty → discard closes; dirty → save waits for the PATCH, then closes; publish still refreshes the list and closes only on success.

  • Step 6: Commit
git add admin/src/App.tsx
git commit -m "feat: guard article editor return"

Task 2: Establish the mobile command hierarchy

Files:

  • Modify: admin/src/App.tsx:2695-2776

  • Modify: admin/src/components/ui/button.tsx:5-30

  • Step 1: Establish the expected mobile arrangement

At 390 px, inspect the editor header. Expected failure before the change: the primary navigation competes with a copy button, a long generate button, save, date input, publish, delete, and close.

  • Step 2: Add a 44 px icon-button size

Extend the size variants in button.tsx with touch-icon: "size-11". Keep icon at 36 px so lists and desktop controls do not shift.

touchIcon: "size-11",

Use the TypeScript-compatible variant key actually chosen in the component (touchIcon), not a hyphenated prop.

  • Step 3: Split editor actions into persistent and secondary groups

In the selected-article header, add a labelled back button containing ChevronLeft and visible text «К черновикам» that calls requestArticleClose. Keep the current article status and save state in the top section. Put copy, image generation, schedule input and deletion into a <details> / <summary> labelled «Ещё» on mobile; desktop keeps the existing direct controls through responsive utility classes. Leave the current save and publish callbacks unchanged.

  • Step 4: Add a mobile action footer

Render a .article-mobile-actions group after the scrollable editor body. It has a full-width «Сохранить» button (disabled if clean or busy) and a full-width «Опубликовать»/«Запланировать» button based on the existing isScheduledForFuture and publishAt state. Both reuse saveArticle and saveAndPublishArticle; no duplicate request code.

  • Step 5: Preserve keyboard semantics

Use real <button> controls for back, save, publish and the secondary disclosure. Set aria-expanded on the disclosure trigger and make Escape close it before requesting return. Ensure the newly introduced buttons use touchIcon or h-11 at mobile widths.

  • Step 6: Verify the 390 px primary flow

Open a draft at 390 px. Confirm «К черновикам», save state, save and publish are visible without horizontal scroll; copy/generate/date/delete are reachable through «Ещё»; desktop still shows direct actions.

  • Step 7: Commit
git add admin/src/App.tsx admin/src/components/ui/button.tsx
git commit -m "feat: prioritize mobile article editor actions"

Task 3: Make feature-image controls and layout responsive and accessible

Files:

  • Modify: admin/src/App.tsx:2775-2859

  • Modify: admin/src/index.css:454-511

  • Step 1: Capture the current responsive failure

At 390 px inspect .article-modal-content. Expected failure: its feature-image title, description, «Выбрать» and «Перегенерировать обложку» share one non-wrapping flex row; the document becomes wider than the viewport.

  • Step 2: Make feature-image actions reflow

Give the descriptive feature-image group min-w-0; give its control container flex flex-wrap gap-2; at max-width 640 px make its buttons grow to available width and allow their labels to wrap. Do not use horizontal scrolling or clipped text as the fix.

  • Step 3: Replace the clickable upload div with a semantic trigger

Keep the hidden file input, but make the visual upload area a <label htmlFor={...}> or a button type="button" with an accessible name such as «Выбрать обложку статьи». Retain drag/drop and paste enhancement handlers. If a button is used, preserve keyboard Enter/Space through native button behavior and prevent nested interactive controls.

  • Step 4: Add mobile safe-area and no-overflow CSS

At @media (max-width: 640px), ensure the article modal is a column with the editor body as its only scrolling region. Add bottom padding equal to the footer height plus env(safe-area-inset-bottom). Give .article-mobile-actions a sticky bottom position, padding-bottom: max(0.75rem, env(safe-area-inset-bottom)), opaque background and top border. Add min-width: 0 at flex boundaries and overflow-wrap: anywhere only to long control labels/status text.

  • Step 5: Build and inspect the bounded responsive matrix

Run:

npm run build --prefix admin

Expected: TypeScript and Vite build complete successfully.

Inspect at 320, 375, 390 and 430 px, plus desktop. At each phone width execute in DevTools:

document.documentElement.scrollWidth <= window.innerWidth

Expected: true. Check title at 200% text zoom, the feature-image picker by Tab/Enter, all close-confirmation paths, Escape and the iOS safe-area visual result.

  • Step 6: Run Impeccable detector and final diff checks

Run:

node /Users/dima/.agents/skills/impeccable/scripts/detect.mjs --json admin/src/App.tsx admin/src/index.css admin/src/components/ui/button.tsx
git diff --check

Expected: detector findings reviewed in context and git diff --check has no output.

  • Step 7: Commit
git add admin/src/App.tsx admin/src/index.css
git commit -m "fix: adapt article editor for mobile"

Plan review

  • Spec coverage: task 1 covers explicit return and unsaved-edit protection; task 2 covers persistent primary controls and secondary command disclosure; task 3 covers feature-image overflow, semantic upload, touch/safe-area rules, and responsive/a11y verification.
  • No API or database changes are required; all actions reuse existing callbacks and article state.
  • The project has no configured unit-test runner, so each behavior is verified through deterministic build output and the stated mobile interaction matrix instead of adding a test framework solely for this focused UI repair.