meriadec
7 years ago
7 changed files with 121 additions and 25 deletions
@ -0,0 +1,36 @@ |
|||
// @flow
|
|||
|
|||
import React, { PureComponent } from 'react' |
|||
import { connect } from 'react-redux' |
|||
import type { MapStateToProps } from 'react-redux' |
|||
import styled from 'styled-components' |
|||
|
|||
import { getUpdateStatus } from 'reducers/update' |
|||
import type { State } from 'reducers' |
|||
import type { UpdateStatus } from 'reducers/update' |
|||
|
|||
type Props = { |
|||
updateStatus: UpdateStatus, |
|||
} |
|||
|
|||
const mapStateToProps: MapStateToProps<*, *, *> = (state: State) => ({ |
|||
updateStatus: getUpdateStatus(state), |
|||
}) |
|||
|
|||
const Container = styled.div` |
|||
position: fixed; |
|||
bottom: 0; |
|||
left: 0; |
|||
right: 0; |
|||
display: flex; |
|||
justify-content: center; |
|||
` |
|||
|
|||
class UpdateNotifier extends PureComponent<Props> { |
|||
render() { |
|||
const { updateStatus } = this.props |
|||
return <Container>{updateStatus}</Container> |
|||
} |
|||
} |
|||
|
|||
export default connect(mapStateToProps, null)(UpdateNotifier) |
@ -0,0 +1,44 @@ |
|||
// @flow
|
|||
|
|||
import { handleActions, createAction } from 'redux-actions' |
|||
|
|||
export type UpdateStatus = |
|||
| 'idle' |
|||
| 'checking' |
|||
| 'available' |
|||
| 'progress' |
|||
| 'unavailable' |
|||
| 'error' |
|||
| 'downloaded' |
|||
|
|||
export type UpdateState = { |
|||
status: UpdateStatus, |
|||
data?: Object, |
|||
} |
|||
|
|||
const state: UpdateState = { |
|||
status: 'idle', |
|||
data: {}, |
|||
} |
|||
|
|||
const handlers = { |
|||
UPDATE_SET_STATUS: (state: UpdateState, { payload }: { payload: UpdateState }): UpdateState => |
|||
payload, |
|||
} |
|||
|
|||
// Actions
|
|||
|
|||
export const setUpdateStatus = createAction( |
|||
'UPDATE_SET_STATUS', |
|||
(status: UpdateStatus, data?: Object): UpdateState => ({ status, data }), |
|||
) |
|||
|
|||
// Selectors
|
|||
|
|||
export function getUpdateStatus(state: { update: UpdateState }): UpdateStatus { |
|||
return state.update.status |
|||
} |
|||
|
|||
// Default export
|
|||
|
|||
export default handleActions(handlers, state) |
Loading…
Reference in new issue