| Total Complexity | 2 |
| Complexity/F | 2 |
| Lines of Code | 26 |
| Function Count | 1 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { connect } from 'react-redux' |
||
| 2 | import parse from 'date-fns/parse' |
||
| 3 | import { getPostTime, getEditedTime } from 'post/state/selectors' |
||
| 4 | import { editPostTime } from 'post/state/actions' |
||
| 5 | import Time from 'post/components/Time' |
||
| 6 | |||
| 7 | const mapStateToProps = state => { |
||
| 8 | const editedTime = getEditedTime(state) |
||
| 9 | const time = getPostTime(state) |
||
| 10 | let displayTime = editedTime |
||
| 11 | if (typeof editedTime !== 'number') { |
||
| 12 | displayTime = parse(displayTime, 'dd/MM/yyyy', new Date()) |
||
| 13 | } else { |
||
| 14 | displayTime = Date.now() |
||
| 15 | } |
||
| 16 | return { |
||
| 17 | time: displayTime, |
||
| 18 | isEdited: editedTime.length > 0 && editedTime !== time |
||
| 19 | } |
||
| 20 | } |
||
| 21 | |||
| 22 | const mapDispatchToProps = { |
||
| 23 | editPostTime |
||
| 24 | } |
||
| 25 | |||
| 26 | export default connect(mapStateToProps, mapDispatchToProps)(Time) |
||
| 27 |