Refactor share sheet selection
Summary: We're if-ing over an enum, so this should be a switch. Also removed the edge case for the share sheet and made the error handling part of the component so the user actually sees it. Reviewed By: jknoxville Differential Revision: D15853056 fbshipit-source-id: 241ed0f2e042b08c4c157db9616175297b683ac3
This commit is contained in:
committed by
Facebook Github Bot
parent
5aaf0c4f29
commit
9c75ea7665
46
src/App.js
46
src/App.js
@@ -26,6 +26,7 @@ import {
|
|||||||
ACTIVE_SHEET_SHARE_DATA,
|
ACTIVE_SHEET_SHARE_DATA,
|
||||||
ACTIVE_SHEET_SIGN_IN,
|
ACTIVE_SHEET_SIGN_IN,
|
||||||
ACTIVE_SHEET_SHARE_DATA_IN_FILE,
|
ACTIVE_SHEET_SHARE_DATA_IN_FILE,
|
||||||
|
ACTIVE_SHEET_PLUGIN_SHEET,
|
||||||
} from './reducers/application.js';
|
} from './reducers/application.js';
|
||||||
|
|
||||||
import type {Logger} from './fb-interfaces/Logger.js';
|
import type {Logger} from './fb-interfaces/Logger.js';
|
||||||
@@ -66,28 +67,29 @@ export class App extends React.Component<Props> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getSheet = (onHide: () => mixed) => {
|
getSheet = (onHide: () => mixed) => {
|
||||||
if (this.props.activeSheet === ACTIVE_SHEET_BUG_REPORTER) {
|
switch (this.props.activeSheet) {
|
||||||
return (
|
case ACTIVE_SHEET_BUG_REPORTER:
|
||||||
<BugReporterDialog
|
return (
|
||||||
bugReporter={this.props.bugReporter}
|
<BugReporterDialog
|
||||||
onHide={onHide}
|
bugReporter={this.props.bugReporter}
|
||||||
/>
|
onHide={onHide}
|
||||||
);
|
/>
|
||||||
} else if (this.props.activeSheet === ACTIVE_SHEET_PLUGIN_DEBUGGER) {
|
);
|
||||||
return <PluginDebugger onHide={onHide} />;
|
case ACTIVE_SHEET_PLUGIN_DEBUGGER:
|
||||||
} else if (this.props.activeSheet === ACTIVE_SHEET_SHARE_DATA) {
|
return <PluginDebugger onHide={onHide} />;
|
||||||
return <ShareSheet onHide={onHide} />;
|
case ACTIVE_SHEET_SHARE_DATA:
|
||||||
} else if (this.props.activeSheet === ACTIVE_SHEET_SIGN_IN) {
|
return <ShareSheet onHide={onHide} />;
|
||||||
return <SignInSheet onHide={onHide} />;
|
case ACTIVE_SHEET_SIGN_IN:
|
||||||
} else if (this.props.activeSheet === ACTIVE_SHEET_SHARE_DATA_IN_FILE) {
|
return <SignInSheet onHide={onHide} />;
|
||||||
const {exportFile} = this.props;
|
case ACTIVE_SHEET_SHARE_DATA_IN_FILE:
|
||||||
if (!exportFile) {
|
return (
|
||||||
throw new Error('Tried to export data without passing the file path');
|
<ShareSheetExportFile onHide={onHide} file={this.props.exportFile} />
|
||||||
}
|
);
|
||||||
return <ShareSheetExportFile onHide={onHide} file={exportFile} />;
|
case ACTIVE_SHEET_PLUGIN_SHEET:
|
||||||
} else {
|
// Currently unused.
|
||||||
// contents are added via React.Portal
|
return null;
|
||||||
return null;
|
default:
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ const Padder = styled('div')(
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onHide: () => mixed,
|
onHide: () => mixed,
|
||||||
file: string,
|
file: ?string,
|
||||||
};
|
};
|
||||||
type State = {
|
type State = {
|
||||||
errorArray: Array<Error>,
|
errorArray: Array<Error>,
|
||||||
@@ -86,6 +86,10 @@ export default class ShareSheetExportFile extends Component<Props, State> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
|
if (!this.props.file) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const {errorArray} = await reportPlatformFailures(
|
const {errorArray} = await reportPlatformFailures(
|
||||||
exportStoreToFile(this.props.file, this.context.store),
|
exportStoreToFile(this.props.file, this.context.store),
|
||||||
@@ -98,6 +102,10 @@ export default class ShareSheetExportFile extends Component<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
if (!this.props.file) {
|
||||||
|
return this.renderNoFileError();
|
||||||
|
}
|
||||||
|
|
||||||
const {result} = this.state;
|
const {result} = this.state;
|
||||||
if (result) {
|
if (result) {
|
||||||
const {success, error} = result;
|
const {success, error} = result;
|
||||||
@@ -161,4 +169,20 @@ export default class ShareSheetExportFile extends Component<Props, State> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderNoFileError() {
|
||||||
|
return (
|
||||||
|
<Container>
|
||||||
|
<Center>
|
||||||
|
<Title bold>No file selected</Title>
|
||||||
|
</Center>
|
||||||
|
<FlexRow>
|
||||||
|
<Spacer />
|
||||||
|
<Button compact padded onClick={this.props.onHide}>
|
||||||
|
Close
|
||||||
|
</Button>
|
||||||
|
</FlexRow>
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user