1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fix pick paths import type error and simplify signature

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-12-06 09:11:15 -05:00
parent bae2aa0884
commit a81873fe52
3 changed files with 14 additions and 18 deletions

View File

@ -4,18 +4,21 @@
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { FileFilter } from "electron";
import { requestOpenFilePickingDialog } from "../../../../../../../renderer/ipc";
import openPathPickingDialogInjectable from "../../../../../../path-picking-dialog/renderer/pick-paths.injectable";
const getFilePathsInjectable = getInjectable({
id: "get-file-paths",
instantiate: () => async (fileFilter: FileFilter) =>
await requestOpenFilePickingDialog({
instantiate: (di) => {
const openPathPickingDialog = di.inject(openPathPickingDialogInjectable);
return async (fileFilter: FileFilter) => await openPathPickingDialog({
properties: ["openFile", "showHiddenFiles"],
message: `Select file`,
buttonLabel: `Use file`,
message: "Select file",
buttonLabel: "Use file",
filters: [fileFilter, { name: "Any", extensions: ["*"] }],
}),
});
},
causesSideEffects: true,
});

View File

@ -15,11 +15,8 @@ const openPathPickingDialogInjectable = getInjectable({
const requestFromChannel = di.inject(requestFromChannelInjectable);
return async (options) => {
const { onPick, onCancel, label, ...dialogOptions } = options;
const response = await requestFromChannel(openPathPickingDialogChannel, {
message: label,
...dialogOptions,
});
const { onPick, onCancel, ...dialogOptions } = options;
const response = await requestFromChannel(openPathPickingDialogChannel, dialogOptions);
if (response.canceled) {
await onCancel?.();

View File

@ -13,7 +13,7 @@ import { cssNames } from "../../utils";
import { Button } from "../button";
export interface PathPickOpts {
label: string;
message: string;
onPick?: (paths: string[]) => any;
onCancel?: () => any;
defaultPath?: string;
@ -35,7 +35,6 @@ interface Dependencies {
const NonInjectedPathPicker = observer((props: PathPickerProps & Dependencies) => {
const {
className,
label,
disabled,
openPathPickingDialog,
...pickOpts
@ -44,13 +43,10 @@ const NonInjectedPathPicker = observer((props: PathPickerProps & Dependencies) =
return (
<Button
primary
label={label}
label={pickOpts.message}
disabled={disabled}
className={cssNames("PathPicker", className)}
onClick={() => void openPathPickingDialog({
label,
...pickOpts,
})}
onClick={() => void openPathPickingDialog(pickOpts)}
/>
);
});