mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
/**
|
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
*/
|
|
import { getInjectable } from "@ogre-tools/injectable";
|
|
import { messageToChannelInjectionToken } from "../../common/utils/channel/message-to-channel-injection-token";
|
|
import askBooleanQuestionChannelInjectable from "../../common/ask-boolean/ask-boolean-question-channel.injectable";
|
|
import askBooleanPromiseInjectable from "./ask-boolean-promise.injectable";
|
|
import getRandomIdInjectable from "../../common/utils/get-random-id.injectable";
|
|
|
|
export type AskBoolean = ({
|
|
title,
|
|
question,
|
|
}: {
|
|
title: string;
|
|
question: string;
|
|
}) => Promise<boolean>;
|
|
|
|
const askBooleanInjectable = getInjectable({
|
|
id: "ask-boolean",
|
|
|
|
instantiate: (di): AskBoolean => {
|
|
const messageToChannel = di.inject(messageToChannelInjectionToken);
|
|
const askBooleanChannel = di.inject(askBooleanQuestionChannelInjectable);
|
|
const getRandomId = di.inject(getRandomIdInjectable);
|
|
|
|
return async ({ title, question }) => {
|
|
const id = getRandomId();
|
|
|
|
const returnValuePromise = di.inject(askBooleanPromiseInjectable, id);
|
|
|
|
await messageToChannel(askBooleanChannel, { id, title, question });
|
|
|
|
return await returnValuePromise.promise;
|
|
};
|
|
},
|
|
});
|
|
|
|
export default askBooleanInjectable;
|