aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/containers/latest_error.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/instant/src/containers/latest_error.tsx')
-rw-r--r--packages/instant/src/containers/latest_error.tsx54
1 files changed, 39 insertions, 15 deletions
diff --git a/packages/instant/src/containers/latest_error.tsx b/packages/instant/src/containers/latest_error.tsx
index b75ec00aa..c0da181f1 100644
--- a/packages/instant/src/containers/latest_error.tsx
+++ b/packages/instant/src/containers/latest_error.tsx
@@ -1,36 +1,60 @@
import * as React from 'react';
import { connect } from 'react-redux';
+import { Dispatch } from 'redux';
+import { SlideAnimationState } from '../components/animations/slide_animation';
import { SlidingError } from '../components/sliding_error';
+import { Overlay } from '../components/ui/overlay';
+import { Action } from '../redux/actions';
import { State } from '../redux/reducer';
-import { Asset, DisplayStatus } from '../types';
-import { errorUtil } from '../util/error';
+import { ScreenWidths } from '../style/media';
+import { generateOverlayBlack } from '../style/theme';
+import { zIndex } from '../style/z_index';
+import { Asset, DisplayStatus, Omit } from '../types';
+import { errorFlasher } from '../util/error_flasher';
export interface LatestErrorComponentProps {
asset?: Asset;
- latestError?: any;
- slidingDirection: 'down' | 'up';
+ latestErrorMessage?: string;
+ animationState: SlideAnimationState;
+ shouldRenderOverlay: boolean;
+ onOverlayClick: () => void;
}
export const LatestErrorComponent: React.StatelessComponent<LatestErrorComponentProps> = props => {
- if (!props.latestError) {
+ if (!props.latestErrorMessage) {
return <div />;
}
- const { icon, message } = errorUtil.errorDescription(props.latestError, props.asset);
- return <SlidingError direction={props.slidingDirection} icon={icon} message={message} />;
+ return (
+ <React.Fragment>
+ <SlidingError animationState={props.animationState} icon="😢" message={props.latestErrorMessage} />
+ {props.shouldRenderOverlay && (
+ <Overlay
+ onClick={props.onOverlayClick}
+ zIndex={zIndex.containerOverlay}
+ showMaxWidth={ScreenWidths.Sm}
+ backgroundColor={generateOverlayBlack(0.4)}
+ />
+ )}
+ </React.Fragment>
+ );
};
-interface ConnectedState {
- asset?: Asset;
- latestError?: any;
- slidingDirection: 'down' | 'up';
-}
export interface LatestErrorProps {}
+interface ConnectedState extends Omit<LatestErrorComponentProps, 'onOverlayClick'> {}
const mapStateToProps = (state: State, _ownProps: LatestErrorProps): ConnectedState => ({
asset: state.selectedAsset,
- latestError: state.latestError,
- slidingDirection: state.latestErrorDisplay === DisplayStatus.Present ? 'up' : 'down',
+ latestErrorMessage: state.latestErrorMessage,
+ animationState: state.latestErrorDisplayStatus === DisplayStatus.Present ? 'slidIn' : 'slidOut',
+ shouldRenderOverlay: state.latestErrorDisplayStatus === DisplayStatus.Present,
+});
+
+type ConnectedDispatch = Pick<LatestErrorComponentProps, 'onOverlayClick'>;
+const mapDispatchToProps = (dispatch: Dispatch<Action>, _ownProps: LatestErrorProps): ConnectedDispatch => ({
+ onOverlayClick: () => {
+ errorFlasher.clearError(dispatch);
+ },
});
-export const LatestError = connect(mapStateToProps)(LatestErrorComponent);
+export const LatestError = connect(mapStateToProps, mapDispatchToProps)(LatestErrorComponent);