-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b73e3b0
commit ac41fc6
Showing
4 changed files
with
67 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...ents/YourStats/components/DailyClassificationsChart/DailyClassificationsChartConnector.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { MobXProviderContext, observer } from 'mobx-react' | ||
import { useContext } from 'react' | ||
|
||
import DailyClassificationsChartContainer from './DailyClassificationsChartContainer' | ||
|
||
function storeMapper(store) { | ||
const { | ||
project, | ||
user: { | ||
personalization: { | ||
counts, | ||
stats: { | ||
thisWeek | ||
} | ||
} | ||
} | ||
} = store | ||
|
||
return { | ||
counts, | ||
thisWeek, | ||
projectName: project['display_name'] | ||
} | ||
} | ||
|
||
function DailyClassificationsChartConnector() { | ||
const { store } = useContext(MobXProviderContext) | ||
const { counts, thisWeek, projectName } = storeMapper(store) | ||
return ( | ||
<DailyClassificationsChartContainer | ||
counts={counts} | ||
projectName={projectName} | ||
thisWeek={thisWeek} | ||
/> | ||
) | ||
} | ||
|
||
export default observer(DailyClassificationsChartConnector) |
64 changes: 26 additions & 38 deletions
64
...ents/YourStats/components/DailyClassificationsChart/DailyClassificationsChartContainer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,44 @@ | ||
import counterpart from 'counterpart' | ||
import { inject, observer } from 'mobx-react' | ||
import { array, number, shape, string } from 'prop-types' | ||
import { Component } from 'react' | ||
|
||
import DailyClassificationsChart from './DailyClassificationsChart' | ||
|
||
function storeMapper (stores) { | ||
const { project, user: { personalization: { counts, stats: { thisWeek } } } } = stores.store | ||
return { | ||
counts, | ||
thisWeek, | ||
projectName: project['display_name'] | ||
} | ||
const defaultCounts = { | ||
today: 0 | ||
} | ||
|
||
@inject(storeMapper) | ||
@observer | ||
class DailyClassificationsChartContainer extends Component { | ||
render () { | ||
const TODAY = new Date() | ||
const { counts, projectName, thisWeek } = this.props | ||
const stats = thisWeek.map(stat => { | ||
const day = new Date(stat.period) | ||
const locale = counterpart.getLocale() | ||
const count = (day.getUTCDay() === TODAY.getUTCDay()) ? counts.today : stat.count | ||
const longLabel = day.toLocaleDateString(locale, { weekday: 'long' }) | ||
const alt = `${longLabel}: ${count}` | ||
const label = day.toLocaleDateString(locale, { weekday: 'narrow' }) | ||
return Object.assign({}, stat, { alt, count, label, longLabel }) | ||
}) | ||
return ( | ||
<DailyClassificationsChart | ||
stats={stats} | ||
projectName={projectName} | ||
/> | ||
) | ||
} | ||
function DailyClassificationsChartContainer({ | ||
counts = defaultCounts, | ||
projectName, | ||
thisWeek = [] | ||
}) { | ||
const TODAY = new Date() | ||
const stats = thisWeek.map(stat => { | ||
const day = new Date(stat.period) | ||
const locale = counterpart.getLocale() | ||
const count = (day.getUTCDay() === TODAY.getUTCDay()) ? counts.today : stat.count | ||
const longLabel = day.toLocaleDateString(locale, { weekday: 'long' }) | ||
const alt = `${longLabel}: ${count}` | ||
const label = day.toLocaleDateString(locale, { weekday: 'narrow' }) | ||
return Object.assign({}, stat, { alt, count, label, longLabel }) | ||
}) | ||
return ( | ||
<DailyClassificationsChart | ||
stats={stats} | ||
projectName={projectName} | ||
/> | ||
) | ||
} | ||
|
||
DailyClassificationsChartContainer.propTypes = { | ||
/** Today's counts, updated as classifications are made. */ | ||
counts: shape({ | ||
today: number | ||
}), | ||
/** Project name */ | ||
projectName: string.isRequired, | ||
/** Array of daily stats from the stats server */ | ||
thisWeek: array | ||
} | ||
|
||
DailyClassificationsChartContainer.defaultProps = { | ||
counts: { | ||
today: 0 | ||
}, | ||
thisWeek: [] | ||
} | ||
|
||
export default DailyClassificationsChartContainer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters