Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,26 @@ const openPathPickingDialogInjectable = getInjectable({
id: "open-path-picking-dialog",
instantiate: (di): OpenPathPickingDialog => {
const requestFromChannel = di.inject(requestFromChannelInjectionToken);
let isDialogOpen = false;

return async (options) => {
const { onPick, onCancel, ...dialogOptions } = options;
const response = await requestFromChannel(openPathPickingDialogChannel, dialogOptions);
if (isDialogOpen) {
return;
}

isDialogOpen = true;

try {
const { onPick, onCancel, ...dialogOptions } = options;
const response = await requestFromChannel(openPathPickingDialogChannel, dialogOptions);

if (response.canceled) {
await onCancel?.();
} else {
await onPick?.(response.paths);
if (response.canceled) {
await onCancel?.();
} else {
await onPick?.(response.paths);
}
} finally {
isDialogOpen = false;
}
};
},
Expand Down
18 changes: 16 additions & 2 deletions packages/core/src/renderer/components/path-picker/path-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Button } from "@freelensapp/button";
import { cssNames } from "@freelensapp/utilities";
import { withInjectables } from "@ogre-tools/injectable-react";
import { observer } from "mobx-react";
import React from "react";
import openPathPickingDialogInjectable from "../../../features/path-picking-dialog/renderer/pick-paths.injectable";

import type { FileFilter, OpenDialogOptions } from "electron";
Expand Down Expand Up @@ -36,14 +37,27 @@ interface Dependencies {

const NonInjectedPathPicker = observer((props: PathPickerProps & Dependencies) => {
const { className, disabled, openPathPickingDialog, ...pickOpts } = props;
const [isDialogOpen, setIsDialogOpen] = React.useState(false);

return (
<Button
primary
label={pickOpts.message}
disabled={disabled}
disabled={disabled || isDialogOpen}
className={cssNames("PathPicker", className)}
onClick={() => void openPathPickingDialog(pickOpts)}
onClick={async () => {
if (isDialogOpen) {
return;
}

setIsDialogOpen(true);

try {
await openPathPickingDialog(pickOpts);
} finally {
setIsDialogOpen(false);
}
}}
/>
);
});
Expand Down