refactor: improve read-only logic and title handling in PastePanel

This commit is contained in:
2026-03-17 18:22:59 +01:00
parent d9eb92300a
commit 3a848b3f56

View File

@@ -42,7 +42,12 @@ const PastePanel = ({ onSubmit, publicPastes, mode, pasteKey: propKey, onConnect
const lastSavedContent = useRef(formData.content); 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); const isRemoteChange = useRef(false);
// Sincroniza el panel cuando cambia el modo o la clave activa: // 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. // Actualiza estado local y, si hay sesión RT activa, propaga el cambio al resto de clientes.
const handleChange = (key, value) => { const handleChange = (key, value) => {
if (isReadOnly && mode !== 'rt') return;
const updatedData = { ...formData, [key]: value, isRt: mode === 'rt' }; const updatedData = { ...formData, [key]: value, isRt: mode === 'rt' };
setFormData(updatedData); setFormData(updatedData);
@@ -266,7 +273,7 @@ const PastePanel = ({ onSubmit, publicPastes, mode, pasteKey: propKey, onConnect
<CodeEditor <CodeEditor
className="flex-fill custom-border rounded-4 overflow-hidden pt-4 pe-4" className="flex-fill custom-border rounded-4 overflow-hidden pt-4 pe-4"
syntax={formData.syntax} syntax={formData.syntax}
readOnly={!!selectedPaste} readOnly={isEditorReadOnly}
onChange={(val) => handleChange("content", val)} onChange={(val) => handleChange("content", val)}
value={formData.content ?? ""} value={formData.content ?? ""}
editorErrors={editorErrors} editorErrors={editorErrors}
@@ -287,7 +294,7 @@ const PastePanel = ({ onSubmit, publicPastes, mode, pasteKey: propKey, onConnect
<Form.Control <Form.Control
disabled={isReadOnly} disabled={isReadOnly}
type="text" type="text"
value={mode === 'rt' ? `Sesión: ${activeKey}` : formData.title} value={titleValue}
onChange={(e) => handleChange("title", e.target.value)} onChange={(e) => handleChange("title", e.target.value)}
isInvalid={!!fieldErrors.title} isInvalid={!!fieldErrors.title}
/> />
@@ -304,7 +311,7 @@ const PastePanel = ({ onSubmit, publicPastes, mode, pasteKey: propKey, onConnect
} }
> >
<Form.Select <Form.Select
disabled={!!selectedPaste} disabled={isReadOnly}
value={formData.syntax} value={formData.syntax}
onChange={(e) => handleChange("syntax", e.target.value)} onChange={(e) => handleChange("syntax", e.target.value)}
> >
@@ -358,7 +365,7 @@ const PastePanel = ({ onSubmit, publicPastes, mode, pasteKey: propKey, onConnect
disabled={isReadOnly} disabled={isReadOnly}
id="burnAfter" id="burnAfter"
label="volátil" label="volátil"
checked={formData.burnAfter} checked={formData.burnAfter && !isReadOnly}
onChange={(e) => handleChange("burnAfter", e.target.checked)} onChange={(e) => handleChange("burnAfter", e.target.checked)}
className="ms-1 d-flex gap-2 align-items-center" className="ms-1 d-flex gap-2 align-items-center"
/> />
@@ -368,12 +375,12 @@ const PastePanel = ({ onSubmit, publicPastes, mode, pasteKey: propKey, onConnect
disabled={isReadOnly} disabled={isReadOnly}
id="isPrivate" id="isPrivate"
label="privado" label="privado"
checked={formData.isPrivate} checked={formData.isPrivate && !isReadOnly}
onChange={(e) => handleChange("isPrivate", e.target.checked)} onChange={(e) => handleChange("isPrivate", e.target.checked)}
className="ms-1 d-flex gap-2 align-items-center" className="ms-1 d-flex gap-2 align-items-center"
/> />
{formData.isPrivate && ( {formData.isPrivate && !isReadOnly && (
<PasswordInput disabled={isReadOnly} onChange={(e) => handleChange("password", e.target.value)} /> <PasswordInput disabled={isReadOnly} onChange={(e) => handleChange("password", e.target.value)} />
)} )}