change modal on error

This commit is contained in:
Mateusz Gruszczyński
2026-08-05 10:38:17 +02:00
parent 73286d921b
commit c4d04adb40
5 changed files with 25 additions and 8 deletions
+11 -3
View File
@@ -27,6 +27,7 @@ import { bindNoteFiles } from "@rustpad/note-files";
import { currentShareUrl, readEditorState, writeEditorState } from "@rustpad/url-state";
import { toast } from "@rustpad/toast";
import { getTheme } from "@rustpad/theme";
import { isResourceAccessError } from "@rustpad/security";
export function startNoteEditor(adapter) {
const editor = document.querySelector("#editor"), preview = document.querySelector("#preview"), editorWorkspace = document.querySelector("#editor-workspace"), gutter = document.querySelector("#line-gutter"), ownerLabels = document.querySelector("#owner-labels"), authorshipLayer = document.querySelector("#authorship-layer");
@@ -1353,7 +1354,6 @@ export function startNoteEditor(adapter) {
onError: message => {
hideConnectionNotice();
const friendly = /read-only access/i.test(message) ? "This note is read only. Enter the password or ask the owner to grant write access." : message;
document.querySelector("#password-error").textContent = friendly;
if (/read-only access/i.test(message)) {
toast(friendly);
accessLevel.textContent = "Access: read only";
@@ -1368,9 +1368,17 @@ export function startNoteEditor(adapter) {
if (saveState.textContent === "Saving…") saveState.textContent = "Save failed";
if (/nickname|session|account/i.test(message)) {
if (!identityDialog.open) identityDialog.showModal();
} else if (info?.protected && !passwordDialog.open) {
passwordDialog.showModal();
return;
}
if (info?.protected && isResourceAccessError(message)) {
resourceUnlocked = false;
setDocumentReadOnly(true, "Password required");
document.querySelector("#password-error").textContent = friendly;
if (!passwordDialog.open) passwordDialog.showModal();
document.querySelector("#open-password")?.focus();
return;
}
toast(friendly);
},
});
socket.connect();