Skip to content

Commit

Permalink
popup: fix creating new collection from popup, regression from switch…
Browse files Browse the repository at this point in the history
… to async storage options
  • Loading branch information
ikreymer committed Jan 19, 2023
1 parent 6da562c commit 89559f0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions src/ext/bg.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ function popupHandler(port) {
toggleBehaviors(tabId);
break;

case "newColl":
collLoader.initNewColl({title: message.title}).then(async (newColl) => {
defaultCollId = newColl.name;
await setLocalOption("defaultCollId", defaultCollId);
port.postMessage(await listAllMsg(collLoader));
});
case "newColl": {
const { name } = await collLoader.initNewColl({title: message.title});
defaultCollId = name;
port.postMessage(await listAllMsg(collLoader, {defaultCollId}));
await setLocalOption("defaultCollId", defaultCollId);
break;
}
}
});

port.onDisconnect.addListener(() => {
Expand Down
8 changes: 4 additions & 4 deletions src/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,15 +623,15 @@ class RecPopup extends LitElement
event.preventDefault();
}

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

this.sendMessage({
tabId: this.tabId,
type: "newColl",
title: this.renderRoot.querySelector("#new-name").value
title
});

removeLocalOption(`${this.tabId}-collId`);
this.collDrop = "";
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function ensureDefaultColl(collLoader)
}

// ===========================================================================
export async function listAllMsg(collLoader) {
export async function listAllMsg(collLoader, {defaultCollId = null} = {}) {
let colls = await ensureDefaultColl(collLoader);

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

const msg = {type: "collections"};
msg.collId = await getLocalOption("defaultCollId");
msg.collId = defaultCollId || await getLocalOption("defaultCollId");
msg.collections = colls.map(coll => ({
id: coll.id,
title: coll.title || coll.filename
Expand Down

0 comments on commit 89559f0

Please sign in to comment.