From 3a848b3f560264c7a1e74f46acbb7ab81c792cba Mon Sep 17 00:00:00 2001 From: Jose Date: Tue, 17 Mar 2026 18:22:59 +0100 Subject: [PATCH] refactor: improve read-only logic and title handling in PastePanel --- src/components/Pastes/PastePanel.jsx | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/components/Pastes/PastePanel.jsx b/src/components/Pastes/PastePanel.jsx index e436ac8..68da3ac 100644 --- a/src/components/Pastes/PastePanel.jsx +++ b/src/components/Pastes/PastePanel.jsx @@ -42,7 +42,12 @@ const PastePanel = ({ onSubmit, publicPastes, mode, pasteKey: propKey, onConnect const lastSavedContent = useRef(formData.content); - const isReadOnly = !!selectedPaste || mode === 'rt'; + const isStaticView = mode === 'static' && !!activeKey; + const isReadOnly = isStaticView || mode === 'rt'; + const isEditorReadOnly = isStaticView; + const titleValue = mode === 'rt' + ? `Sesión: ${activeKey}` + : (selectedPaste?.title ?? formData.title ?? ""); const isRemoteChange = useRef(false); // Sincroniza el panel cuando cambia el modo o la clave activa: @@ -146,6 +151,8 @@ const PastePanel = ({ onSubmit, publicPastes, mode, pasteKey: propKey, onConnect // Actualiza estado local y, si hay sesión RT activa, propaga el cambio al resto de clientes. const handleChange = (key, value) => { + if (isReadOnly && mode !== 'rt') return; + const updatedData = { ...formData, [key]: value, isRt: mode === 'rt' }; setFormData(updatedData); @@ -266,7 +273,7 @@ const PastePanel = ({ onSubmit, publicPastes, mode, pasteKey: propKey, onConnect handleChange("content", val)} value={formData.content ?? ""} editorErrors={editorErrors} @@ -287,7 +294,7 @@ const PastePanel = ({ onSubmit, publicPastes, mode, pasteKey: propKey, onConnect handleChange("title", e.target.value)} isInvalid={!!fieldErrors.title} /> @@ -304,7 +311,7 @@ const PastePanel = ({ onSubmit, publicPastes, mode, pasteKey: propKey, onConnect } > handleChange("syntax", e.target.value)} > @@ -358,7 +365,7 @@ const PastePanel = ({ onSubmit, publicPastes, mode, pasteKey: propKey, onConnect disabled={isReadOnly} id="burnAfter" label="volátil" - checked={formData.burnAfter} + checked={formData.burnAfter && !isReadOnly} onChange={(e) => handleChange("burnAfter", e.target.checked)} className="ms-1 d-flex gap-2 align-items-center" /> @@ -368,12 +375,12 @@ const PastePanel = ({ onSubmit, publicPastes, mode, pasteKey: propKey, onConnect disabled={isReadOnly} id="isPrivate" label="privado" - checked={formData.isPrivate} + checked={formData.isPrivate && !isReadOnly} onChange={(e) => handleChange("isPrivate", e.target.checked)} className="ms-1 d-flex gap-2 align-items-center" /> - {formData.isPrivate && ( + {formData.isPrivate && !isReadOnly && ( handleChange("password", e.target.value)} /> )}