2020-08-17 21:07:16 +01:00
|
|
|
import React from 'react'
|
2020-08-17 21:59:29 +01:00
|
|
|
import PropTypes from 'prop-types'
|
2020-08-17 21:39:25 +01:00
|
|
|
import { connect } from 'react-redux'
|
2020-07-22 04:24:26 +01:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
|
|
|
import { fetchShortcuts } from '../actions/shortcuts'
|
|
|
|
import ColumnIndicator from '../components/column_indicator'
|
|
|
|
import List from '../components/list'
|
|
|
|
|
|
|
|
class Shortcuts extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
componentDidMount() {
|
2021-01-09 07:01:11 +00:00
|
|
|
this.props.onFetchShortcuts()
|
2020-07-22 04:24:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
isLoading,
|
|
|
|
isError,
|
|
|
|
shortcuts,
|
|
|
|
} = this.props
|
|
|
|
|
2020-08-01 05:05:00 +01:00
|
|
|
if (isError) {
|
2020-07-22 04:24:26 +01:00
|
|
|
return <ColumnIndicator type='error' message='Error fetching shortcuts' />
|
|
|
|
}
|
|
|
|
|
|
|
|
const listItems = shortcuts.map((s) => ({
|
|
|
|
to: s.get('to'),
|
|
|
|
title: s.get('title'),
|
|
|
|
image: s.get('image'),
|
|
|
|
}))
|
|
|
|
|
|
|
|
return (
|
|
|
|
<List
|
|
|
|
scrollKey='shortcuts'
|
|
|
|
emptyMessage='You have no shortcuts'
|
|
|
|
items={listItems}
|
2020-08-01 05:05:00 +01:00
|
|
|
showLoading={isLoading}
|
2020-07-22 04:24:26 +01:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-08-19 01:22:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => ({
|
|
|
|
isError: state.getIn(['shortcuts', 'isError']),
|
|
|
|
isLoading: state.getIn(['shortcuts', 'isLoading']),
|
|
|
|
shortcuts: state.getIn(['shortcuts', 'items']),
|
|
|
|
})
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
onFetchShortcuts() {
|
|
|
|
dispatch(fetchShortcuts())
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
Shortcuts.propTypes = {
|
|
|
|
isLoading: PropTypes.bool.isRequired,
|
|
|
|
isError: PropTypes.bool.isRequired,
|
|
|
|
onFetchShortcuts: PropTypes.func.isRequired,
|
|
|
|
shortcuts: ImmutablePropTypes.list,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Shortcuts)
|