Skip to content

Commit 89559f0

Browse files
committed
popup: fix creating new collection from popup, regression from switch to async storage options
1 parent 6da562c commit 89559f0

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/ext/bg.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ function popupHandler(port) {
7373
toggleBehaviors(tabId);
7474
break;
7575

76-
case "newColl":
77-
collLoader.initNewColl({title: message.title}).then(async (newColl) => {
78-
defaultCollId = newColl.name;
79-
await setLocalOption("defaultCollId", defaultCollId);
80-
port.postMessage(await listAllMsg(collLoader));
81-
});
76+
case "newColl": {
77+
const { name } = await collLoader.initNewColl({title: message.title});
78+
defaultCollId = name;
79+
port.postMessage(await listAllMsg(collLoader, {defaultCollId}));
80+
await setLocalOption("defaultCollId", defaultCollId);
8281
break;
8382
}
83+
}
8484
});
8585

8686
port.onDisconnect.addListener(() => {

src/popup.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -623,15 +623,15 @@ class RecPopup extends LitElement
623623
event.preventDefault();
624624
}
625625

626-
async onNewColl() {
627-
await removeLocalOption(`${this.tabId}-collId`);
626+
onNewColl() {
627+
const title = this.renderRoot.querySelector("#new-name").value;
628628

629629
this.sendMessage({
630630
tabId: this.tabId,
631631
type: "newColl",
632-
title: this.renderRoot.querySelector("#new-name").value
632+
title
633633
});
634-
634+
removeLocalOption(`${this.tabId}-collId`);
635635
this.collDrop = "";
636636
}
637637
}

src/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export async function ensureDefaultColl(collLoader)
3131
}
3232

3333
// ===========================================================================
34-
export async function listAllMsg(collLoader) {
34+
export async function listAllMsg(collLoader, {defaultCollId = null} = {}) {
3535
let colls = await ensureDefaultColl(collLoader);
3636

3737
colls = colls.map(x => getCollData(x));
@@ -49,7 +49,7 @@ export async function listAllMsg(collLoader) {
4949
});
5050

5151
const msg = {type: "collections"};
52-
msg.collId = await getLocalOption("defaultCollId");
52+
msg.collId = defaultCollId || await getLocalOption("defaultCollId");
5353
msg.collections = colls.map(coll => ({
5454
id: coll.id,
5555
title: coll.title || coll.filename

0 commit comments

Comments
 (0)