fix: Update permission handling in Editor and EditorPage components
This commit is contained in:
@@ -12,7 +12,8 @@ interface EditorProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const Editor = ({ providers, permission }: EditorProps) => {
|
const Editor = ({ providers, permission }: EditorProps) => {
|
||||||
const isEditable = permission !== "view";
|
// Default to false (read-only) until permission is loaded
|
||||||
|
const isEditable = permission === "edit";
|
||||||
|
|
||||||
const editor = useEditor({
|
const editor = useEditor({
|
||||||
extensions: [
|
extensions: [
|
||||||
@@ -34,6 +35,13 @@ const Editor = ({ providers, permission }: EditorProps) => {
|
|||||||
editable: isEditable,
|
editable: isEditable,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Update editable state when permission changes
|
||||||
|
useEffect(() => {
|
||||||
|
if (editor) {
|
||||||
|
editor.setEditable(permission === "edit");
|
||||||
|
}
|
||||||
|
}, [editor, permission]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (editor && providers.awareness) {
|
if (editor && providers.awareness) {
|
||||||
const user = providers.awareness.getLocalState()?.user;
|
const user = providers.awareness.getLocalState()?.user;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ const EditorPage = () => {
|
|||||||
<div className="page-header">
|
<div className="page-header">
|
||||||
<button onClick={() => navigate("/")}>← Back to Home</button>
|
<button onClick={() => navigate("/")}>← Back to Home</button>
|
||||||
<div className="header-actions">
|
<div className="header-actions">
|
||||||
{permission === "view" && (
|
{permission !== "edit" && permission !== null && (
|
||||||
<div className="view-only-badge" style={{ display: 'flex', alignItems: 'center', gap: '4px', padding: '4px 12px', backgroundColor: '#f0f0f0', borderRadius: '4px', fontSize: '14px' }}>
|
<div className="view-only-badge" style={{ display: 'flex', alignItems: 'center', gap: '4px', padding: '4px 12px', backgroundColor: '#f0f0f0', borderRadius: '4px', fontSize: '14px' }}>
|
||||||
<span>👁️</span>
|
<span>👁️</span>
|
||||||
<span>View only</span>
|
<span>View only</span>
|
||||||
|
|||||||
Reference in New Issue
Block a user