-
Notifications
You must be signed in to change notification settings - Fork 146
/
Copy pathPerPartySearchPanelContainer.js
197 lines (189 loc) · 5.71 KB
/
PerPartySearchPanelContainer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import React, { useMemo } from "react"
import { DESKTOP_MIN_WIDTH, media, DISPLAY_FONT } from "../styles"
import PartyDropdown from "./PartyDropdown"
import { faQuestionCircle } from "@fortawesome/free-solid-svg-icons"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import Unimplemented from "./Unimplemented"
import { numberWithCommas } from "../util/format"
import { useSummaryData } from "../models/LiveDataSubscription"
import AnimatedNumber from "./AnimatedNumber"
import Loading from "./Loading"
import { nationwidePartyStatsFromSummaryJSON } from "../models/PartyStats"
const sectionStyling = { borderBottom: "1px solid #000", padding: "10px 0" }
export default function PerPartySearchPanelContainer({ partyId }) {
const summaryState = useSummaryData()
const totalVote = summaryState.completed ? (
<AnimatedNumber value={summaryState.data.partyScoreMap[partyId] || 0}>
{v => numberWithCommas(v)}
</AnimatedNumber>
) : (
<Loading />
)
const partyStatsRow = useMemo(() => {
if (!summaryState.completed) return null
return nationwidePartyStatsFromSummaryJSON(summaryState.data).find(
row => row.party.id === +partyId
)
}, [summaryState])
const totalDistrictCouncilor = partyStatsRow ? (
<AnimatedNumber value={partyStatsRow.constituencySeats} />
) : (
<Loading />
)
const totalPartyListCouncilor = partyStatsRow ? (
<AnimatedNumber value={partyStatsRow.partyListSeats} />
) : (
<Loading />
)
return (
<div
css={{
fontFamily: DISPLAY_FONT,
margin: "20px 0 0 0",
position: "relative",
[media(DESKTOP_MIN_WIDTH)]: {
display: "block",
order: 1,
padding: 0,
width: "275px",
},
}}
>
<div
css={{
background: "red",
position: "absolute",
top: 0,
width: "100%",
}}
>
<PartyDropdown partyId={partyId} dropdownOpen={false} />
</div>
<div css={{ paddingTop: 56 }}>
<PartyTotalVote totalVote={totalVote} />
<PartyTotalCouncilorEstimationVisualization />
<PartyTotalCouncilorEstimationNumber
totalDistrictCouncilor={totalDistrictCouncilor}
totalPartyListCouncilor={totalPartyListCouncilor}
/>
<PartyPresidentCandidateList partyId={partyId} />
</div>
</div>
)
}
function PartyTotalVote({ totalVote }) {
return (
<div css={{ ...sectionStyling }}>
<div>คะแนนเสียงทั้งประเทศ</div>
<div
css={{ fontWeight: "bold", fontSize: "2.2em", padding: "10px 0 0 0" }}
>
{totalVote}
</div>
</div>
)
}
// @todo #1 implement search and select with visualization of each party
function PartyTotalCouncilorEstimationVisualization() {
return (
<div css={{ ...sectionStyling }}>
<div>
จำนวนส.ส.พึงมี
<FontAwesomeIcon css={{ marginLeft: "5px" }} icon={faQuestionCircle} />
</div>
<div>
{/* @todo #1 implement estimated councoilor graph */}
<Unimplemented componentName="PartyTotalCouncilorGraph" />
</div>
</div>
)
}
function PartyTotalCouncilorEstimationNumber({
totalDistrictCouncilor,
totalPartyListCouncilor,
}) {
const blockStyling = {
display: "flex",
width: "50%",
position: "relative",
padding: "15px 0 0 0",
}
const numberStyling = {
position: "absolute",
right: 0,
fontSize: "2em",
top: 0,
fontWeight: "bold",
}
return (
<div css={{ ...sectionStyling, display: "flex" }}>
<div css={{ ...blockStyling, borderRight: "1px solid #000" }}>
<div>ส.ส.เขต</div>
<div css={{ ...numberStyling, paddingRight: "10px" }}>
{totalDistrictCouncilor}
</div>
</div>
<div css={{ ...blockStyling }}>
<div css={{ paddingLeft: "10px" }}>ส.ส.บัญชีรายชื่อ</div>
<div css={{ ...numberStyling }}>{totalPartyListCouncilor}</div>
</div>
</div>
)
}
function PartyPresidentCandidateList({ partyId }) {
// @todo #1 PartyView - PartyPresidentCandidateList - bind presiddent candidate data by party id
const mockData = [
{
firstName: "ชื่อ",
lastName: "นามสกุล",
photoSrc: require(`../styles/images/pmcan/${partyId}-s.png`),
},
{
firstName: "ชื่อ",
lastName: "นามสกุล",
photoSrc: require(`../styles/images/pmcan/${partyId}-s.png`),
},
{
firstName: "ชื่อ",
lastName: "นามสกุล",
photoSrc: require(`../styles/images/pmcan/${partyId}-s.png`),
},
]
const presidentCandidateList = mockData
return (
<div css={{ ...sectionStyling }}>
<div>แคนดิเดตนายกฯ</div>
<div css={{ display: "flex" }}>
{presidentCandidateList.map(item => {
return (
<div css={{ padding: "10px", width: "100%" }}>
<div>
<img
src={item.photoSrc}
css={{
display: "block",
padding: 0,
margin: "auto",
width: "35px",
height: "35px",
borderRadius: "50%",
}}
/>
</div>
<div
css={{
fontSize: "0.8em",
marginTop: "5px",
textAlign: "center",
}}
>
<div>{item.firstName}</div>
<div css={{ marginTop: "-1px" }}>{item.lastName}</div>
</div>
</div>
)
})}
</div>
</div>
)
}