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
26
src/App.js
26
src/App.js
@@ -26,6 +26,7 @@ import {
|
||||
ACTIVE_SHEET_SHARE_DATA,
|
||||
ACTIVE_SHEET_SIGN_IN,
|
||||
ACTIVE_SHEET_SHARE_DATA_IN_FILE,
|
||||
ACTIVE_SHEET_PLUGIN_SHEET,
|
||||
} from './reducers/application.js';
|
||||
|
||||
import type {Logger} from './fb-interfaces/Logger.js';
|
||||
@@ -66,27 +67,28 @@ export class App extends React.Component<Props> {
|
||||
}
|
||||
|
||||
getSheet = (onHide: () => mixed) => {
|
||||
if (this.props.activeSheet === ACTIVE_SHEET_BUG_REPORTER) {
|
||||
switch (this.props.activeSheet) {
|
||||
case ACTIVE_SHEET_BUG_REPORTER:
|
||||
return (
|
||||
<BugReporterDialog
|
||||
bugReporter={this.props.bugReporter}
|
||||
onHide={onHide}
|
||||
/>
|
||||
);
|
||||
} else if (this.props.activeSheet === ACTIVE_SHEET_PLUGIN_DEBUGGER) {
|
||||
case ACTIVE_SHEET_PLUGIN_DEBUGGER:
|
||||
return <PluginDebugger onHide={onHide} />;
|
||||
} else if (this.props.activeSheet === ACTIVE_SHEET_SHARE_DATA) {
|
||||
case ACTIVE_SHEET_SHARE_DATA:
|
||||
return <ShareSheet onHide={onHide} />;
|
||||
} else if (this.props.activeSheet === ACTIVE_SHEET_SIGN_IN) {
|
||||
case ACTIVE_SHEET_SIGN_IN:
|
||||
return <SignInSheet onHide={onHide} />;
|
||||
} else if (this.props.activeSheet === ACTIVE_SHEET_SHARE_DATA_IN_FILE) {
|
||||
const {exportFile} = this.props;
|
||||
if (!exportFile) {
|
||||
throw new Error('Tried to export data without passing the file path');
|
||||
}
|
||||
return <ShareSheetExportFile onHide={onHide} file={exportFile} />;
|
||||
} else {
|
||||
// contents are added via React.Portal
|
||||
case ACTIVE_SHEET_SHARE_DATA_IN_FILE:
|
||||
return (
|
||||
<ShareSheetExportFile onHide={onHide} file={this.props.exportFile} />
|
||||
);
|
||||
case ACTIVE_SHEET_PLUGIN_SHEET:
|
||||
// Currently unused.
|
||||
return null;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -65,7 +65,7 @@ const Padder = styled('div')(
|
||||
|
||||
type Props = {
|
||||
onHide: () => mixed,
|
||||
file: string,
|
||||
file: ?string,
|
||||
};
|
||||
type State = {
|
||||
errorArray: Array<Error>,
|
||||
@@ -86,6 +86,10 @@ export default class ShareSheetExportFile extends Component<Props, State> {
|
||||
};
|
||||
|
||||
async componentDidMount() {
|
||||
if (!this.props.file) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const {errorArray} = await reportPlatformFailures(
|
||||
exportStoreToFile(this.props.file, this.context.store),
|
||||
@@ -98,6 +102,10 @@ export default class ShareSheetExportFile extends Component<Props, State> {
|
||||
}
|
||||
|
||||
render() {
|
||||
if (!this.props.file) {
|
||||
return this.renderNoFileError();
|
||||
}
|
||||
|
||||
const {result} = this.state;
|
||||
if (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