From 51cfe86c398b6c7e554c41c2f7f1a68141311754 Mon Sep 17 00:00:00 2001 From: roll Date: Thu, 26 Sep 2024 09:15:56 +0100 Subject: [PATCH] Fixed remote file input --- client/components/Application/Content.tsx | 8 ++++++++ client/store/actions/file.ts | 3 +-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/client/components/Application/Content.tsx b/client/components/Application/Content.tsx index ead194903..12a69b656 100644 --- a/client/components/Application/Content.tsx +++ b/client/components/Application/Content.tsx @@ -30,6 +30,7 @@ export default function Content() { function FileContent() { const record = store.useStore((state) => state.record) + const dialog = store.useStore((state) => state.dialog) if (!record) return null const Controller = CONTROLLERS[record.type] || File @@ -50,6 +51,13 @@ function FileContent() { mouseEvent="onMouseDown" touchEvent="onTouchStart" onClickAway={(event) => { + // Generally speaking, it will be better to migrate away + // from using ClickAwayListener for this purpose. See this weird bug: + // https://github.com/okfn/opendataeditor/issues/559 + // As alternative, store's actions just check for unsaved changes + // when the user does something that requires it. + if (dialog) return + event.preventDefault() store.onFileLeave() }} diff --git a/client/store/actions/file.ts b/client/store/actions/file.ts index f402262ec..78f4ff0c4 100644 --- a/client/store/actions/file.ts +++ b/client/store/actions/file.ts @@ -290,10 +290,9 @@ export async function onFileDeleted(paths: string[]) { } export function onFileLeave() { - const { dialog } = store.getState() const isUpdated = getIsFileOrResourceUpdated(store.getState()) - if (isUpdated && !dialog) { + if (isUpdated) { openDialog('unsavedChanges') } }