Dialog management cleanup
Summary: This diff moves the dialogs * Settings * Plugin Manager * Doctor * Sign in * Changelog To use the imperative dialog APIs, rather then organising them through reducers which adds a lot of indirection which isn't really needed but hard to follow. Reviewed By: passy Differential Revision: D30192002 fbshipit-source-id: ba38b2e700da3e442653786448fcbf85074981ad
This commit is contained in:
committed by
Facebook GitHub Bot
parent
89b193b438
commit
9e5575cf69
@@ -13,7 +13,8 @@ import React from 'react';
|
||||
import {renderReactRoot} from '../utils/renderReactRoot';
|
||||
import {Layout} from './Layout';
|
||||
import {Spinner} from './Spinner';
|
||||
type DialogResult<T> = Promise<false | T> & {close: () => void};
|
||||
|
||||
export type DialogResult<T> = Promise<false | T> & {close: () => void};
|
||||
|
||||
type BaseDialogOptions = {
|
||||
title: string;
|
||||
@@ -104,6 +105,36 @@ export const Dialog = {
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Shows an item in the modal stack, but without providing any further UI, like .show does.
|
||||
*/
|
||||
showModal<T = void>(
|
||||
fn: (hide: (result?: T) => void) => React.ReactElement,
|
||||
): DialogResult<T> {
|
||||
let cancel: () => void;
|
||||
|
||||
return Object.assign(
|
||||
new Promise<false | T>((resolve) => {
|
||||
renderReactRoot((hide) => {
|
||||
cancel = () => {
|
||||
hide();
|
||||
resolve(false);
|
||||
};
|
||||
|
||||
return fn((result?: T) => {
|
||||
hide();
|
||||
resolve(result ?? false);
|
||||
});
|
||||
});
|
||||
}),
|
||||
{
|
||||
close() {
|
||||
cancel();
|
||||
},
|
||||
},
|
||||
);
|
||||
},
|
||||
|
||||
confirm({
|
||||
message,
|
||||
onConfirm,
|
||||
|
||||
Reference in New Issue
Block a user