Skip to content

Commit 505ee19

Browse files
authored
Merge pull request #29 from TaloDev/develop
Release 0.7.2
2 parents 6ec9d88 + 36e1586 commit 505ee19

File tree

6 files changed

+50
-39
lines changed

6 files changed

+50
-39
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: React tests
22

3-
on: [push, pull_request]
3+
on: push
44

55
jobs:
66
test:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,5 @@
6666
"lint-staged": {
6767
"*.{js,jsx}": "eslint --fix"
6868
},
69-
"version": "0.7.1"
69+
"version": "0.7.2"
7070
}

src/components/HeadlineStat.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
33

44
const HeadlineStat = (props) => {
55
return (
6-
<div className={`mt-4 rounded border-2 border-gray-700 w-full text-center md:text-left ${props.className ?? ''}`}>
6+
<div className={`rounded border-2 border-gray-700 w-full text-center md:text-left ${props.className ?? ''}`}>
77
<div className='p-4 bg-gray-700'>
88
<h3 className='text-lg font-bold'>{props.title}</h3>
99
</div>

src/components/events/EventsOverview.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const EventsOverview = () => {
2929
{ id: 'y', label: 'This year' }
3030
]
3131

32-
const [timePeriod, setTimePeriod] = useLocalStorage('eventsOverviewTimePeriod', timePeriods[1])
32+
const [timePeriod, setTimePeriod] = useLocalStorage('eventsOverviewTimePeriod', timePeriods[1].id)
3333
const { startDate, endDate } = useTimePeriod(timePeriod?.id)
3434

3535
const [selectedStartDate, setSelectedStartDate] = useLocalStorage('eventsOverviewStartDate', '')
@@ -78,8 +78,8 @@ const EventsOverview = () => {
7878
<div className='mb-4 md:mb-8'>
7979
<TimePeriodPicker
8080
periods={timePeriods}
81-
onPick={setTimePeriod}
82-
selectedPeriod={timePeriod?.id}
81+
onPick={(period) => setTimePeriod(period.id)}
82+
selectedPeriod={timePeriod}
8383
/>
8484
</div>
8585

src/pages/Dashboard.jsx

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import useHeadlines from '../api/useHeadlines'
66
import ErrorMessage from '../components/ErrorMessage'
77
import HeadlineStat from '../components/HeadlineStat'
88
import TimePeriodPicker from '../components/TimePeriodPicker'
9-
import Title from '../components/Title'
9+
import Page from '../components/Page'
1010
import routes from '../constants/routes'
1111
import activeGameState from '../state/activeGameState'
1212
import canViewPage from '../utils/canViewPage'
1313
import useLocalStorage from '../utils/useLocalStorage'
1414
import useTimePeriod from '../utils/useTimePeriod'
1515
import Link from '../components/Link'
1616
import userState from '../state/userState'
17+
import useStats from '../api/useStats'
1718

1819
const Dashboard = () => {
1920
const history = useHistory()
@@ -34,16 +35,17 @@ const Dashboard = () => {
3435
const activeGame = useRecoilValue(activeGameState)
3536

3637
const timePeriods = [
37-
{ id: '7d', label: '7 days', titleSuffix: 'the last 7 days' },
38-
{ id: '30d', label: '30 days', titleSuffix: 'the last 30 days' },
39-
{ id: 'w', label: 'This week', titleSuffix: 'this week' },
40-
{ id: 'm', label: 'This month', titleSuffix: 'this month' },
41-
{ id: 'y', label: 'This year', titleSuffix: 'this year' }
38+
{ id: '7d', label: '7 days', titlePrefix: 'Last 7 days' },
39+
{ id: '30d', label: '30 days', titlePrefix: 'Last 30 days' },
40+
{ id: 'w', label: 'This week', titlePrefix: 'This week' },
41+
{ id: 'm', label: 'This month', titlePrefix: 'This month' },
42+
{ id: 'y', label: 'This year', titlePrefix: 'This year' }
4243
]
4344

44-
const [timePeriod, setTimePeriod] = useLocalStorage('headlinesTimePeriod', timePeriods[1])
45-
const { startDate, endDate } = useTimePeriod(timePeriod.id)
46-
const { headlines, loading, error } = useHeadlines(activeGame, startDate, endDate)
45+
const [timePeriod, setTimePeriod] = useLocalStorage('headlinesTimePeriod', timePeriods[1].id)
46+
const { startDate, endDate } = useTimePeriod(timePeriod)
47+
const { headlines, loading: headlinesLoading, error: headlinesError } = useHeadlines(activeGame, startDate, endDate)
48+
const { stats, loading: statsLoading, error: statsError } = useStats(activeGame)
4749

4850
if (!intendedRouteChecked) return null
4951

@@ -56,45 +58,53 @@ const Dashboard = () => {
5658
)
5759
}
5860

59-
return (
60-
<div>
61-
<Title>{activeGame.name} dashboard</Title>
61+
const titlePrefix = timePeriods.find((period) => period.id === timePeriod).titlePrefix
6262

63-
<div className='flex flex-col-reverse md:flex-row md:justify-between md:items-center mt-8'>
64-
<h2 className='text-2xl mt-4 md:mt-0'>Stats for {timePeriod.titleSuffix}</h2>
63+
return (
64+
<Page title={`${activeGame.name} dashboard`} isLoading={headlinesLoading || statsLoading}>
65+
<div className='flex flex-col-reverse md:flex-row md:justify-between md:items-center'>
66+
<h2 className='text-2xl mt-4 md:mt-0'>{titlePrefix} at a glance</h2>
6567
<TimePeriodPicker
6668
periods={timePeriods}
67-
onPick={setTimePeriod}
68-
selectedPeriod={timePeriod.id}
69+
onPick={(period) => setTimePeriod(period.id)}
70+
selectedPeriod={timePeriod}
6971
/>
7072
</div>
7173

72-
{error &&
73-
<div className='mt-8'>
74-
<ErrorMessage error={{ message: 'Couldn\'t fetch headlines' }} />
74+
{headlinesError &&
75+
<ErrorMessage error={{ message: 'Couldn\'t fetch headlines' }} />
76+
}
77+
78+
{!headlinesLoading &&
79+
<div className='grid md:grid-cols-2 lg:grid-cols-4 gap-4'>
80+
<HeadlineStat title='New players' stat={headlines.new_players.count} />
81+
<HeadlineStat title='Returning players' stat={headlines.returning_players.count} />
82+
<HeadlineStat title='New events' stat={headlines.events.count} />
83+
<HeadlineStat title='Unique event submitters' stat={headlines.unique_event_submitters.count} />
7584
</div>
7685
}
7786

78-
{!loading && !error &&
79-
<div className='lg:flex'>
80-
<div className='md:flex md:space-x-4 lg:w-1/2'>
81-
<HeadlineStat title='New players' stat={headlines.new_players.count} />
82-
<HeadlineStat title='Returning players' stat={headlines.returning_players.count} />
83-
</div>
84-
<div className='md:flex md:space-x-4 lg:w-1/2 lg:ml-4'>
85-
<HeadlineStat title='New events' stat={headlines.events.count} />
86-
<HeadlineStat title='Unique event submitters' stat={headlines.unique_event_submitters.count} />
87-
</div>
87+
<h2 className='text-2xl'>Global stats</h2>
88+
89+
{statsError &&
90+
<ErrorMessage error={{ message: 'Couldn\'t fetch stats' }} />
91+
}
92+
93+
{!statsLoading &&
94+
<div className='grid md:grid-cols-2 lg:grid-cols-4 gap-4'>
95+
{stats.filter((stat) => stat.global).map((stat) => (
96+
<HeadlineStat key={stat.id} title={stat.name} stat={stat.globalValue} />
97+
))}
8898
</div>
8999
}
90100

91101
{canViewPage(user, routes.activity) &&
92-
<div className='mt-8'>
102+
<div className='!mb-24'>
93103
<h2 className='text-2xl mt-4 mb-2 md:mt-0'>Activity</h2>
94104
<Link to={routes.activity}>Go to activity log</Link>
95105
</div>
96106
}
97-
</div>
107+
</Page>
98108
)
99109
}
100110

src/pages/DataExports.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ const DataExports = () => {
109109
<p>Choose which entities you would like to generate CSVs for</p>
110110
</div>
111111

112-
<div className='flex space-x-8 p-4'>
113-
{entitiesError && <ErrorMessage error={{ message: 'Couldn\'t fetch available entities' }} />}
112+
<div className='grid grid-cols-1 md:grid-cols-2 gap-x-8 gap-y-4 p-4'>
114113
{!entitiesError && availableEntities && availableEntities.map((service) => (
115114
<div key={service}>
116115
<input
@@ -126,6 +125,8 @@ const DataExports = () => {
126125
</div>
127126
</div>
128127

128+
{entitiesError && <ErrorMessage error={{ message: 'Couldn\'t fetch available entities' }} />}
129+
129130
{createError && <ErrorMessage error={createError} />}
130131

131132
<Button

0 commit comments

Comments
 (0)