Passed
Pull Request — master (#132)
by Huu-Phat
04:05
created

cms/src/post/containers/Time.js   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 26
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 19
mnd 1
bc 1
fnc 1
dl 0
loc 26
bpm 1
cpm 2
noi 0
c 0
b 0
f 0
rs 10
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