Skip to content

Commit d256b6a

Browse files
committed
feat: save local draft for each wiki page patch
1 parent 75f6015 commit d256b6a

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

wiki/public/js/editor.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function saveDraftLocally() {
121121

122122
if (content || title) {
123123
localStorage.setItem(
124-
`wiki_draft_${wikiPageName}`,
124+
getDraftKey(),
125125
JSON.stringify({
126126
content: content,
127127
title: title,
@@ -131,8 +131,17 @@ function saveDraftLocally() {
131131
}
132132
}
133133

134+
function getDraftKey() {
135+
const urlParams = new URLSearchParams(window.location.search);
136+
const patchId = urlParams.get("wikiPagePatch");
137+
if (patchId) {
138+
return `wiki_page_patch_draft_${patchId}`;
139+
}
140+
return `wiki_page_draft_${wikiPageName}`;
141+
}
142+
134143
function getLocalDraft() {
135-
const draftKey = `wiki_draft_${wikiPageName}`;
144+
const draftKey = getDraftKey();
136145
const draft = localStorage.getItem(draftKey);
137146
if (draft) {
138147
try {
@@ -165,7 +174,7 @@ function showOutdatedDraftWarning(wikiPage) {
165174
editor.setValue(wikiPage.content || "", 1);
166175
wikiTitleInput.val(wikiPage.title || "");
167176
isSettingEditor = false;
168-
localStorage.removeItem(`wiki_draft_${wikiPageName}`);
177+
localStorage.removeItem(getDraftKey());
169178
outdatedDraftWarning.hide();
170179
frappe.show_alert({
171180
message: __("Updated with latest changes"),
@@ -196,7 +205,7 @@ function saveWikiPage(draft = false) {
196205
},
197206
callback: (r) => {
198207
// Clear draft from localStorage after successful save
199-
localStorage.removeItem(`wiki_draft_${wikiPageName}`);
208+
localStorage.removeItem(getDraftKey());
200209
// route back to the main page
201210
window.location.href = "/" + r.message.route;
202211
},

wiki/public/js/render_wiki.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,17 @@ window.RenderWiki = class RenderWiki extends Wiki {
238238
primary_action: {
239239
label: "Yes",
240240
action() {
241+
// clear draft from localstorage
242+
const urlParams = new URLSearchParams(window.location.search);
243+
const patchId = urlParams.get("wikiPagePatch");
244+
const draftKey = patchId
245+
? `wiki_page_patch_draft_${patchId}`
246+
: `wiki_page_draft_${wikiPageName}`;
247+
localStorage.removeItem(draftKey);
248+
241249
toggleEditor();
242250
$('.sidebar-item[data-name="new-wiki-page"]').remove();
243251
set_search_params();
244-
localStorage.removeItem(`wiki_draft_${wikiPageName}`);
245252
discardDialog.hide();
246253
},
247254
},

0 commit comments

Comments
 (0)