fix: Update permission handling in Editor and EditorPage components

This commit is contained in:
M1ngdaXie
2026-01-12 16:57:51 -08:00
parent b19eafb497
commit a1f2102c90
2 changed files with 10 additions and 2 deletions

View File

@@ -12,7 +12,8 @@ interface 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({
extensions: [
@@ -34,6 +35,13 @@ const Editor = ({ providers, permission }: EditorProps) => {
editable: isEditable,
});
// Update editable state when permission changes
useEffect(() => {
if (editor) {
editor.setEditable(permission === "edit");
}
}, [editor, permission]);
useEffect(() => {
if (editor && providers.awareness) {
const user = providers.awareness.getLocalState()?.user;

View File

@@ -24,7 +24,7 @@ const EditorPage = () => {
<div className="page-header">
<button onClick={() => navigate("/")}> Back to Home</button>
<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' }}>
<span>👁</span>
<span>View only</span>