1
1
import React from 'react'
2
2
import { connect } from 'react-redux'
3
- import { Grid } from 'semantic-ui-react'
3
+ import { Grid , Loader } from 'semantic-ui-react'
4
4
5
5
const toPercent = ( val ) => {
6
6
if ( ! val ) {
@@ -24,8 +24,13 @@ const humanReadable = (el) => {
24
24
// election should be dropdown with curr elec selected
25
25
const TopDetailsContainer = ( { election, margin, winningParty,
26
26
mrTurnout, winningCandidate, totalPop,
27
- dbdo, pctRegistered} ) => (
28
- < Grid >
27
+ dbdo, pctRegistered, isLoading} ) => {
28
+ let content ;
29
+ if ( isLoading ) {
30
+ content = < Loader active />
31
+ }
32
+ else {
33
+ content = (
29
34
< Grid . Row centered divided className = 'top-details' >
30
35
< Grid . Column width = { 3 } className = 'top-label' >
31
36
< strong > { humanReadable ( election ) } winner:</ strong > { winningCandidate } ({ winningParty . split ( '' ) . slice ( 0 , 3 ) . join ( '' ) } ) -- { margin } %
@@ -42,9 +47,14 @@ const TopDetailsContainer = ({election, margin, winningParty,
42
47
< Grid . Column width = { 3 } className = 'top-label' >
43
48
< strong > Registered:</ strong > { pctRegistered }
44
49
</ Grid . Column >
45
- </ Grid . Row >
50
+ </ Grid . Row > )
51
+ }
52
+ return (
53
+ < Grid >
54
+ { content }
46
55
</ Grid >
47
- )
56
+ )
57
+ }
48
58
49
59
const mapStateToProps = ( state ) => (
50
60
{ election : state . selectedElection ,
@@ -54,7 +64,8 @@ const mapStateToProps = (state) => (
54
64
mrTurnout : toPercent ( state . highlightedEdData . turnout . turnout_17 ) || '' ,
55
65
totalPop : state . highlightedEdData . edMetrics . total ,
56
66
dbdo : toPercent ( 1 - state . highlightedEdData . edMetrics [ `dbdo_${ state . selectedElection . toLowerCase ( ) } ` ] ) || '' ,
57
- pctRegistered : toPercent ( state . highlightedEdData . edMetrics . registered_pct ) || ''
67
+ pctRegistered : toPercent ( state . highlightedEdData . edMetrics . registered_pct ) || '' ,
68
+ isLoading : state . isLoading
58
69
} )
59
70
60
71
const TopDetails = connect ( mapStateToProps ) ( TopDetailsContainer )
0 commit comments