-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
migrate commands to command palette (Closes #389) #391
Changes from 9 commits
d0ccc5a
ae8823a
d20b071
50c04dd
8aa7028
ba608a4
3ccadf2
d4d78f7
ccf5232
3eb2707
3d3ccae
e8fb9ec
31a12e3
5dfb015
654a756
7451e61
f1dff63
ed1661a
b21a052
f9bfbe5
4629860
830cdd8
0a42854
dadf190
239152e
dac7911
630cc94
c1d368c
73cfcfe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ import getParentUidByBlockUid from "roamjs-components/queries/getParentUidByBloc | |
import getFullTreeByParentUid from "roamjs-components/queries/getFullTreeByParentUid"; | ||
import createBlockObserver from "roamjs-components/dom/createBlockObserver"; | ||
import getReferenceBlockUid from "roamjs-components/dom/getReferenceBlockUid"; | ||
import type { OnloadArgs } from "roamjs-components/types"; | ||
|
||
const TODO_REGEX = /{{(\[\[)?TODO(\]\])?}}\s*/; | ||
|
||
|
@@ -263,7 +264,7 @@ const settings = [ | |
"Context Enabled", | ||
"Hex Color Preview Enabled", | ||
] as const; | ||
const DecoratorSettings = ({ isOpen, onClose }: RoamOverlayProps) => { | ||
const DecoratorSettings = ({ isOpen, onClose, extensionAPI }: RoamOverlayProps) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll need to fix the type here: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I went a different route and removed the |
||
const [opts, setOpts] = useState(() => | ||
JSON.parse(localStorageGet("decorators") || "{}") | ||
); | ||
|
@@ -295,8 +296,8 @@ const DecoratorSettings = ({ isOpen, onClose }: RoamOverlayProps) => { | |
text={"Save"} | ||
onClick={() => { | ||
localStorageSet("decorators", JSON.stringify(opts)); | ||
toggleFeature(false); | ||
toggleFeature(true); | ||
toggleFeature(false, extensionAPI); | ||
toggleFeature(true, extensionAPI); | ||
renderToast({ | ||
content: "Successfully saved new decorators!", | ||
id: "decorators-saved", | ||
|
@@ -311,15 +312,15 @@ const DecoratorSettings = ({ isOpen, onClose }: RoamOverlayProps) => { | |
}; | ||
|
||
const unloads = new Set<() => void>(); | ||
export const toggleFeature = (flag: boolean) => { | ||
export const toggleFeature = (flag: boolean, extensionAPI: OnloadArgs["extensionAPI"] ) => { | ||
if (flag) { | ||
const archivedDefault = !!get("decoratorsMoveArchives"); // Improve the UX for this if feature is re-requested | ||
window.roamAlphaAPI.ui.commandPalette.addCommand({ | ||
extensionAPI.ui.commandPalette.addCommand({ | ||
label: "Toggle Block Decorators", | ||
callback: () => renderOverlay({ Overlay: DecoratorSettings }), | ||
callback: () => renderOverlay({ Overlay: DecoratorSettings, props: { extensionAPI } }), | ||
}); | ||
unloads.add(() => | ||
window.roamAlphaAPI.ui.commandPalette.removeCommand({ | ||
extensionAPI.ui.commandPalette.removeCommand({ | ||
label: "Toggle Block Decorators", | ||
}) | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to change for this PR, but a note for future reference.
In typescript, when there's more than one parameter I often prefer a single object instead of multiple params. So for example, I probably would have done:
The reason being is life becomes way easier for consumers: