From 743b65f917fde792763614222cf66fe01fd3680d Mon Sep 17 00:00:00 2001 From: nstarikov Date: Sat, 15 Aug 2026 13:25:21 +0300 Subject: [PATCH] fix: adapt article editor for mobile --- dzen-assistant/admin/src/App.tsx | 185 +++++++++++++++--- .../admin/src/components/ui/button.tsx | 2 +- dzen-assistant/admin/src/index.css | 35 ++++ 3 files changed, 193 insertions(+), 29 deletions(-) diff --git a/dzen-assistant/admin/src/App.tsx b/dzen-assistant/admin/src/App.tsx index d6968e1..1de4e79 100644 --- a/dzen-assistant/admin/src/App.tsx +++ b/dzen-assistant/admin/src/App.tsx @@ -8,6 +8,8 @@ import { AlertTriangle, ArrowLeft, CheckCircle2, + ChevronDown, + ChevronLeft, Clock3, Copy, ExternalLink, @@ -1210,6 +1212,8 @@ export default function App() { const [publishAt, setPublishAt] = useState("") const [editorDirty, setEditorDirty] = useState(false) const [editorBusy, setEditorBusy] = useState(false) + const [articleCloseConfirmOpen, setArticleCloseConfirmOpen] = useState(false) + const [articleMoreOpen, setArticleMoreOpen] = useState(false) const [featureImageBusy, setFeatureImageBusy] = useState(false) const [featureImageDragActive, setFeatureImageDragActive] = useState(false) const [featureImageHoverActive, setFeatureImageHoverActive] = useState(false) @@ -1237,6 +1241,8 @@ export default function App() { const selectedArticleRef = useRef(null) const editorTitleRef = useRef("") const titleTextareaRef = useRef(null) + const articleBackButtonRef = useRef(null) + const articleMoreRef = useRef(null) const articlesOffsetRef = useRef(0) const articlesLoadingRef = useRef(false) const articlesHasMoreRef = useRef(false) @@ -1627,6 +1633,8 @@ export default function App() { setEditorTitle(result.title) setPublishAt(toDateTimeLocalValue(result.publishedAt) || currentDateTimeLocalValue()) setEditorDirty(false) + setArticleCloseConfirmOpen(false) + setArticleMoreOpen(false) appliedImageGenerationJobsRef.current = new Set() try { const active = await fetch(`/api/articles/${id}/image-generations/active`) @@ -1840,6 +1848,28 @@ export default function App() { } }, [selectedArticle?.id, selectedArticle?.videoSourceUrl]) + useEffect(() => { + if (!selectedArticle) return + function handleArticleKeyDown(event: KeyboardEvent) { + if (event.key !== "Escape") return + if (articleMoreOpen) { + event.preventDefault() + articleMoreRef.current?.removeAttribute("open") + setArticleMoreOpen(false) + return + } + if (articleCloseConfirmOpen) { + event.preventDefault() + stayInArticle() + return + } + event.preventDefault() + requestArticleClose() + } + window.addEventListener("keydown", handleArticleKeyDown) + return () => window.removeEventListener("keydown", handleArticleKeyDown) + }, [selectedArticle, articleCloseConfirmOpen, articleMoreOpen, editorDirty]) + function findImageBlockFromElement(target: EventTarget | null) { const editor = editorInstanceRef.current if (!editor || !(target instanceof Element)) return null @@ -2114,6 +2144,31 @@ export default function App() { setSelectedArticle(null) } + function requestArticleClose() { + if (!editorDirty) { + setSelectedArticle(null) + return + } + setArticleCloseConfirmOpen(true) + } + + function stayInArticle() { + setArticleCloseConfirmOpen(false) + window.requestAnimationFrame(() => articleBackButtonRef.current?.focus()) + } + + function discardArticleChanges() { + setArticleCloseConfirmOpen(false) + setSelectedArticle(null) + } + + async function saveAndCloseArticle() { + const saved = await saveArticle(false) + if (!saved) return + setArticleCloseConfirmOpen(false) + setSelectedArticle(null) + } + async function copyArticleText() { if (!selectedArticle) return let text = "" @@ -2698,6 +2753,10 @@ export default function App() {
+ {isScheduledForFuture(selectedArticle.publishedAt) ? ( @@ -2707,13 +2766,14 @@ export default function App() { )}

Редактирование статьи

- {editorDirty ? есть правки : null} + {editorDirty ? "Есть правки" : "Сохранено"}

Редактируйте блоки как в Medium. У изображения доступны случайный кадр и перегенерация по смыслу текста.

-
+
deleteArticle(selectedArticle.id)}> -
+
setArticleMoreOpen(event.currentTarget.open)} + > + + Ещё + +
+ + + {selectedArticle.status !== "published" || isScheduledForFuture(selectedArticle.publishedAt) ? ( + + ) : ( + + )} + +
+
-
-
+
+

Feature Image

Главная обложка публикации для RSS и Дзена.

- - +
+ + +
-
featureImageInputRef.current?.click()} onMouseEnter={() => { clearEditorImageHover() @@ -2856,7 +2957,7 @@ export default function App() {
) : null} -
+
{imageGenerationBatch ? (
@@ -2903,7 +3004,35 @@ export default function App() { />
+
+ + {selectedArticle.status !== "published" || isScheduledForFuture(selectedArticle.publishedAt) ? ( + + ) : null} +
+ {articleCloseConfirmOpen ? ( +
+
+

Сохранить изменения?

+

Несохранённые правки останутся только в этом браузере и будут потеряны при выходе.

+
+ + + +
+
+
+ ) : null} ) : null} diff --git a/dzen-assistant/admin/src/components/ui/button.tsx b/dzen-assistant/admin/src/components/ui/button.tsx index 6b2a331..3f2cd3e 100644 --- a/dzen-assistant/admin/src/components/ui/button.tsx +++ b/dzen-assistant/admin/src/components/ui/button.tsx @@ -19,6 +19,7 @@ const buttonVariants = cva( sm: "h-8 rounded-md px-3 text-xs", lg: "h-10 rounded-md px-8", icon: "size-9", + touchIcon: "size-11", }, }, defaultVariants: { @@ -40,4 +41,3 @@ const Button = React.forwardRef( Button.displayName = "Button" export { Button, buttonVariants } - diff --git a/dzen-assistant/admin/src/index.css b/dzen-assistant/admin/src/index.css index 845697a..5599d08 100644 --- a/dzen-assistant/admin/src/index.css +++ b/dzen-assistant/admin/src/index.css @@ -466,6 +466,10 @@ border-right: 0; } + .modal-panel:has(.article-modal-body) { + min-width: 0; + } + .article-modal-header { flex-direction: column; gap: 0.75rem; @@ -481,6 +485,11 @@ line-height: 1.35; } + .article-save-state { + max-width: 100%; + overflow-wrap: anywhere; + } + .article-modal-actions { width: 100%; justify-content: flex-start; @@ -497,13 +506,39 @@ } .article-modal-body { + min-height: 0; + flex: 1 1 auto; padding: 0.75rem; } .article-modal-content { + min-width: 0; padding: 1rem; } + .article-feature-image-heading { + align-items: flex-start; + flex-direction: column; + } + + .article-feature-image-controls { + width: 100%; + } + + .article-feature-image-controls > button { + min-height: 2.75rem; + flex: 1 1 100%; + white-space: normal; + overflow-wrap: anywhere; + } + + .article-mobile-actions { + position: sticky; + bottom: 0; + z-index: 2; + padding-bottom: max(0.75rem, env(safe-area-inset-bottom)); + } + .article-modal-content .article-editorjs .ce-block__content, .article-modal-content .article-editorjs .ce-toolbar__content { max-width: calc(100vw - 4rem);