A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
web: add `onBeforeOpen` hook to dialog manager
Abdullah Atta31bb78bfca53
diff --git a/apps/web/src/common/dialog-manager.tsx b/apps/web/src/common/dialog-manager.tsxindex ff9ecec77..e9aa12003 100644--- a/apps/web/src/common/dialog-manager.tsx+++ b/apps/web/src/common/dialog-manager.tsx@@ -24,6 +24,17 @@ export interface BaseDialogProps<T = unknown> {onClose: (result: T) => void;}+type PropsWithoutOnClose<Props extends BaseDialogProps<any>> = Omit<+ Props,+ "onClose"+>;++type DialogOptions<Props extends BaseDialogProps<any>> = {+ onBeforeOpen?: (+ props: PropsWithoutOnClose<Props>+ ) => boolean | Promise<boolean>;+};+class _DialogManager {private openedDialogs: Map<React.JSXElementConstructor<any>, () => void> =new Map();@@ -83,10 +94,15 @@ class _DialogManager {}register<Props extends BaseDialogProps<any>>(- component: React.ComponentType<Props>+ component: React.ComponentType<Props>,+ options?: DialogOptions<Props>) {return {- show: (props: Omit<Props, "onClose">) => this.open(component, props),+ show: async (props: PropsWithoutOnClose<Props>) => {+ if (options?.onBeforeOpen && !(await options?.onBeforeOpen?.(props)))+ return false;+ return await this.open(component, props);+ },close: () => {const dialog = this.openedDialogs.get(component);if (!dialog) return;