Skip to content

Commit 93e5548

Browse files
authored
Fix addShortcutToLeftSidebar, use new API (Closes #509) (#511)
* Refactor addShortcutToLeftSidebar function to use Roam API for adding current page shortcuts. Update command label for clarity. * 1.7.3
1 parent 32fbada commit 93e5548

3 files changed

Lines changed: 10 additions & 20 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@types/mozilla-readability": "^0.2.0",
2424
"@types/turndown": "^5.0.1"
2525
},
26-
"version": "1.7.2",
26+
"version": "1.7.3",
2727
"samepage": {
2828
"extends": "node_modules/roamjs-components/package.json"
2929
}

src/features/jumpNav.tsx

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -478,22 +478,12 @@ const toggleQueries = () =>
478478
.forEach((element) => {
479479
element.click();
480480
});
481-
const addShortcutToLeftSidebar = () => {
482-
const previousElement = document.activeElement as HTMLElement;
483-
const emptyShortcuts = document.getElementsByClassName(
484-
"bp3-button bp3-icon-star-empty"
485-
) as HTMLCollectionOf<HTMLSpanElement>;
486-
const shortcuts = document.getElementsByClassName(
487-
"bp3-button bp3-icon-star"
488-
) as HTMLCollectionOf<HTMLSpanElement>;
489-
if (emptyShortcuts.length) {
490-
emptyShortcuts[0].click();
491-
previousElement?.focus();
492-
} else if (shortcuts.length) {
493-
shortcuts[0]?.click();
494-
previousElement?.focus();
495-
}
496-
};
481+
const addShortcutToLeftSidebar = () =>
482+
getCurrentPageUid().then((uid) =>
483+
window.roamAlphaAPI.data.page
484+
// @ts-expect-error - addShortcut is not yet in roamjs-components types
485+
.addShortcut(uid, 0)
486+
);
497487
const pasteBlockWithChildrenAsReferences = () => {
498488
const uid = window.roamAlphaAPI.ui.getFocusedBlock()?.["block-uid"];
499489
if (uid) {
@@ -630,7 +620,7 @@ const commands = [
630620
{ label: "Collapse all blocks on page", callback: collapseAllBlocksOnPage },
631621
{ label: "Open this page in sidebar", callback: openPageInSidebar },
632622
{
633-
label: "Add shortcut to page to left sidebar",
623+
label: "Add current page to shortcuts",
634624
callback: addShortcutToLeftSidebar,
635625
},
636626
{ label: "Toggle Linked Refs", callback: toggleLinkedRefs },

0 commit comments

Comments
 (0)