display records label on calendar

This commit is contained in:
Sam 2018-07-29 12:04:29 +02:00
parent 0c8921a6ff
commit d37db4a714
2 changed files with 15 additions and 6 deletions

View File

@ -6,7 +6,7 @@ import { connect } from 'react-redux'
import { Link } from 'react-router-dom'
import { getMonthActivities } from '../../actions/activities'
import { getDateWithTZ } from '../../utils'
import { getDateWithTZ, recordsLabels } from '../../utils'
const getStartAndEndMonth = date => {
const monthStart = dateFns.startOfMonth(date)
@ -125,7 +125,11 @@ class Calendar extends React.Component {
<i
className="fa fa-trophy custom-fa-small"
aria-hidden="true"
title={act.records.map(r => ` ${r.record_type}`)}
title={act.records.map(rec => ` ${
recordsLabels.filter(
r => r.record_type === rec.record_type
)[0].label
}`)}
/>
</sup>
)}

View File

@ -91,29 +91,34 @@ export const formatActivityDate = (
}
}
export const recordsLabels = [
{ record_type: 'AS', label: 'Avg speed' },
{ record_type: 'FD', label: 'Farest distance' },
{ record_type: 'LD', label: 'Longest duration' },
{ record_type: 'MS', label: 'Max speed' },
]
export const formatRecord = (record, tz) => {
let value, recordType = null
switch (record.record_type) {
case 'AS':
case 'MS':
value = `${record.value} km/h`
recordType = record.record_type === 'AS' ? 'Avg speed' : 'Max speed'
break
case 'FD':
value = `${record.value} km`
recordType = 'Farest distance'
break
default: // 'LD'
value = record.value // eslint-disable-line prefer-destructuring
recordType = 'Longest duration'
}
[recordType] = recordsLabels.filter(r => r.record_type === record.record_type)
return {
activity_date: formatActivityDate(
getDateWithTZ(record.activity_date, tz)
).activity_date,
activity_id: record.activity_id,
id: record.id,
record_type: recordType,
record_type: recordType.label,
value: value,
}
}