-
Notifications
You must be signed in to change notification settings - Fork 0
/
RenewableCards.tsx
98 lines (94 loc) · 3.72 KB
/
RenewableCards.tsx
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
import { Col, Modal, Row, Statistic } from "antd"
import { useEffect, useState } from "react"
import ResourcesModal from "./Resources/ResourcesModal"
import IconFont from "../../Iconfont"
import { RenewableCardRender, getAllDataRenewable, renderRenewableData } from "./utils"
import { EnergyType } from "../../types"
interface RenewableCards {
item: any,
bills: any,
resources: any
}
const RenewableCards = ({ item, bills, resources }: RenewableCards) => {
const [visible, setVisible] = useState(false)
const [visibleResource, setVisibleResource] = useState(false)
const [filter, setFilter] = useState<EnergyType>("Solar")
const [geoSum, setGeoSum] = useState(0)
const [hydroSum, setHydroSum] = useState(0)
const [windSum, setWindSum] = useState(0)
const [solarSum, setSolarSum] = useState(0)
const [totalSum, setTotalSum] = useState(0)
const [allBills, setAllBills] = useState<any>([])
const [deviceEarning, setDeviceEarning] = useState(0)
const [deviceCost, setDeviceCost] = useState(0)
const [metric, setMetric] = useState(true)
useEffect(() => {
setAllBills([])
getAllDataRenewable(
resources,
bills,
item,
filter,
setHydroSum,
setSolarSum,
setWindSum,
setGeoSum,
setTotalSum,
setDeviceEarning,
setDeviceCost,
setAllBills
)
}, [filter])
return (
<Row justify="center" gutter={[32, 32]}>
<Col span={24}>
<Statistic title="Total Energy Production"
value={
metric ? (solarSum + geoSum + hydroSum + windSum) / 1000 :
(solarSum + geoSum + hydroSum + windSum)
}
suffix={metric ? "KiloWatt (kW)" : "Watt"} precision={2} />
<Row align="middle">
<IconFont
type="i-arrow_up_down_circle"
onClick={() => setMetric(!metric)}
style={{ color: "blue", marginRight: 6, cursor: "pointer" }}
/>
<p style={{ color: "grey", fontSize: "18px", fontWeight: "lighter", margin: 0 }}>
{!metric ? "Total in Kilowatt (kW)" : "Total in Watt (W)"}
</p>
</Row>
</Col>
{RenewableCardRender("Total Solar Production", solarSum, metric, "Solar", "i-solar-panels", setFilter, setVisible)}
{RenewableCardRender("Total Hydro Production", hydroSum, metric, "Hydro", "i-hydro-power", setFilter, setVisible)}
{RenewableCardRender("Total Windy Production", windSum, metric, "Wind", "i-turbine", setFilter, setVisible)}
{RenewableCardRender("Total Geothermic Production", geoSum, metric, "Geo", "i-ecology", setFilter, setVisible)}
<Modal
destroyOnClose
open={visible}
onCancel={() => setVisible(false)}
width={800}
title={"Total " + filter + " Production"}
>
{renderRenewableData(
filter,
metric,
totalSum,
deviceEarning,
deviceCost,
allBills,
setMetric,
setVisibleResource
)}
</Modal>
<ResourcesModal
defaultActiveKey={filter}
building={item}
visible={visibleResource}
setVisible={setVisibleResource}
data={item.resources}
/>
</Row >
)
}
export default RenewableCards