From 99da71c25de59b4e282fed44e37c4cafa9d26c55 Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Wed, 10 Oct 2018 09:31:26 +0200 Subject: [PATCH] flowtype for Notification components --- .../components/NotificationButton/index.js | 25 ++++++--- src/components/Notification/index.js | 51 ++++++------------- .../App/components/OnlineStatus/index.js | 4 +- .../App/components/UpdateBridge/index.js | 3 +- .../App/components/UpdateFirmware/index.js | 3 +- .../Context/components/Account/index.js | 2 +- .../components/Group/index.js | 2 +- .../Context/components/Static/index.js | 11 +++- src/reducers/NotificationReducer.js | 2 + .../components/InitializationError/index.js | 2 +- src/views/Landing/index.js | 5 +- src/views/Wallet/views/Acquire/index.js | 2 +- .../Wallet/views/UnreadableDevice/index.js | 2 +- 13 files changed, 59 insertions(+), 55 deletions(-) diff --git a/src/components/Notification/components/NotificationButton/index.js b/src/components/Notification/components/NotificationButton/index.js index 97ef5ada..bd9a4d4f 100644 --- a/src/components/Notification/components/NotificationButton/index.js +++ b/src/components/Notification/components/NotificationButton/index.js @@ -1,10 +1,23 @@ -import React from 'react'; +/* @flow */ + +import * as React from 'react'; import styled, { css } from 'styled-components'; import PropTypes from 'prop-types'; import Icon from 'components/Icon'; import colors from 'config/colors'; import { TRANSITION } from 'config/variables'; +type Props = { + type: string; + icon?: { + type: Array; + color: string; + size: number; + }; + onClick: () => void; + children: React.Node; +}; + const Wrapper = styled.button` padding: 12px 58px; border-radius: 3px; @@ -62,10 +75,9 @@ const IconWrapper = styled.span` `; const NotificationButton = ({ - children, className, icon, onClick = () => { }, type = null, -}) => ( + type, icon, onClick, children, +}: Props) => ( , - close: (notif?: any) => Action, -}; - -type NProps = { + key?: React.Key, type: string, cancelable?: boolean; title: string; @@ -128,12 +122,11 @@ const ActionContent = styled.div` `} `; -export const Notification = (props: NProps): React$Element => { +const Notification = (props: Props): React$Element => { const close: Function = typeof props.close === 'function' ? props.close : () => {}; // TODO: add default close action - return ( - + {props.loading && } {props.cancelable && ( close()}> @@ -167,7 +160,6 @@ export const Notification = (props: NProps): React$Element => { { close(); action.callback(); }} >{action.label} @@ -179,26 +171,15 @@ export const Notification = (props: NProps): React$Element => { ); }; -export const NotificationGroup = (props: Props) => { - const { notifications, close } = props; - return notifications.map(n => ( - - )); +Notification.propTypes = { + key: PropTypes.string, + type: PropTypes.string.isRequired, + cancelable: PropTypes.bool, + title: PropTypes.string.isRequired, + message: PropTypes.string, + actions: PropTypes.arrayOf(PropTypes.func), + close: PropTypes.func, + loading: PropTypes.bool, }; -export default connect( - state => ({ - notifications: state.notifications, - }), - dispatch => ({ - close: bindActionCreators(NotificationActions.close, dispatch), - }), -)(NotificationGroup); +export default Notification; \ No newline at end of file diff --git a/src/components/notifications/App/components/OnlineStatus/index.js b/src/components/notifications/App/components/OnlineStatus/index.js index b7712253..d5acc265 100644 --- a/src/components/notifications/App/components/OnlineStatus/index.js +++ b/src/components/notifications/App/components/OnlineStatus/index.js @@ -1,11 +1,11 @@ /* @flow */ import * as React from 'react'; -import { Notification } from 'components/Notification'; +import Notification from 'components/Notification'; import type { Props } from '../../index'; export default (props: Props) => { const { online } = props.wallet; if (online) return null; - return (); + return (); }; \ No newline at end of file diff --git a/src/components/notifications/App/components/UpdateBridge/index.js b/src/components/notifications/App/components/UpdateBridge/index.js index e418bb37..071dddde 100644 --- a/src/components/notifications/App/components/UpdateBridge/index.js +++ b/src/components/notifications/App/components/UpdateBridge/index.js @@ -1,6 +1,6 @@ /* @flow */ import * as React from 'react'; -import { Notification } from 'components/Notification'; +import Notification from 'components/Notification'; import type { Props } from '../../index'; @@ -8,6 +8,7 @@ export default (props: Props) => { if (props.connect.transport && props.connect.transport.outdated) { return ( { if (!outdated) return null; return ( { if (!location) return null; const notifications: Array = []; + // Example: // if (location.state.device) { // notifications.push(); // } - return notifications; + return ( + + {notifications} + + ); }; \ No newline at end of file diff --git a/src/reducers/NotificationReducer.js b/src/reducers/NotificationReducer.js index 0ca86f47..720d6883 100644 --- a/src/reducers/NotificationReducer.js +++ b/src/reducers/NotificationReducer.js @@ -13,6 +13,7 @@ export type CallbackAction = { } export type NotificationEntry = { + +key: string; // React.Key +id: ?string; +devicePath: ?string; +type: string; @@ -38,6 +39,7 @@ const initialState: State = [ const addNotification = (state: State, payload: any): State => { const newState: State = state.filter(e => !e.cancelable); newState.push({ + key: new Date().getTime().toString(), id: payload.id, devicePath: payload.devicePath, type: payload.type, diff --git a/src/views/Landing/components/InitializationError/index.js b/src/views/Landing/components/InitializationError/index.js index 2db65aee..a3fc17cb 100644 --- a/src/views/Landing/components/InitializationError/index.js +++ b/src/views/Landing/components/InitializationError/index.js @@ -2,7 +2,7 @@ import React from 'react'; import styled from 'styled-components'; -import { Notification } from 'components/Notification'; +import Notification from 'components/Notification'; const Wrapper = styled.div` min-width: 720px; diff --git a/src/views/Landing/index.js b/src/views/Landing/index.js index a7702939..7c6ea3e9 100644 --- a/src/views/Landing/index.js +++ b/src/views/Landing/index.js @@ -7,7 +7,8 @@ import Footer from 'components/Footer'; import Log from 'components/Log'; import Link from 'components/Link'; import Loader from 'components/Loader'; -import Notifications, { Notification } from 'components/Notification'; +import Notification from 'components/Notification'; +import ContextNotifications from 'components/notifications/Context'; import colors from 'config/colors'; import P from 'components/Paragraph'; import { H2 } from 'components/Heading'; @@ -98,7 +99,7 @@ export default (props: Props) => { type="error" /> )} - + {shouldShowInitializationError && } diff --git a/src/views/Wallet/views/Acquire/index.js b/src/views/Wallet/views/Acquire/index.js index b514b9c7..1df45e01 100644 --- a/src/views/Wallet/views/Acquire/index.js +++ b/src/views/Wallet/views/Acquire/index.js @@ -4,7 +4,7 @@ import styled from 'styled-components'; import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; import colors from 'config/colors'; -import { Notification } from 'components/Notification'; +import Notification from 'components/Notification'; import * as TrezorConnectActions from 'actions/TrezorConnectActions'; import type { State, Dispatch } from 'flowtype'; diff --git a/src/views/Wallet/views/UnreadableDevice/index.js b/src/views/Wallet/views/UnreadableDevice/index.js index 15e99283..e00e8956 100644 --- a/src/views/Wallet/views/UnreadableDevice/index.js +++ b/src/views/Wallet/views/UnreadableDevice/index.js @@ -2,7 +2,7 @@ import React from 'react'; import styled from 'styled-components'; -import { Notification } from 'components/Notification'; +import Notification from 'components/Notification'; const Wrapper = styled.div``;