Skip to content

Commit 0a74eaa

Browse files
authored
Merge pull request #961 from eetu/mobile-tempbox
Redesign temperature and solis cards for mobile
2 parents 7852d6d + 3daf40c commit 0a74eaa

4 files changed

Lines changed: 447 additions & 93 deletions

File tree

‎frontend/src/components/SolisBox.tsx‎

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { memo } from "react";
33
import useSWR from "swr";
44

55
import { api, HttpError, jsonFetcher } from "../api";
6+
import { mq } from "../mq";
67
import { SolisData } from "../types/solis";
78
import Box, { DrawerRow } from "./Box";
89
import Icon from "./Icon";
@@ -99,53 +100,90 @@ const SolisBox: React.FC<SolisBoxProps> = ({ className }) => {
99100
>
100101
<div
101102
css={{
103+
position: "relative",
102104
display: "flex",
103105
flexDirection: "column",
104106
alignItems: "center",
105107
justifyContent: "space-between",
106108
flex: 1,
109+
[mq[0]]: {
110+
flexDirection: "row",
111+
alignItems: "flex-start",
112+
justifyContent: "space-between",
113+
gap: 16,
114+
},
107115
}}
108116
>
109117
<div
110118
css={{
111119
display: "flex",
120+
flexDirection: "column",
112121
alignItems: "center",
113-
gap: "0.3em",
114-
...theme.typography.label,
115-
color: theme.colors.text.muted,
116-
letterSpacing: "0.04em",
122+
[mq[0]]: { alignItems: "flex-start", gap: 4 },
117123
}}
118124
>
119-
<Icon
120-
size={18}
125+
<div
121126
css={{
122-
color: isAlarm ? theme.colors.error : "inherit",
123-
opacity: 0.7,
127+
display: "flex",
128+
alignItems: "center",
129+
gap: "0.3em",
130+
...theme.typography.label,
131+
color: theme.colors.text.muted,
132+
letterSpacing: "0.04em",
124133
}}
125134
>
126-
{isAlarm ? "warning" : "solar_power"}
127-
</Icon>
128-
{data.power_unit}
129-
</div>
130-
<div
131-
css={{
132-
marginTop: "5px",
133-
display: "flex",
134-
flexDirection: "column",
135-
alignItems: "center",
136-
}}
137-
>
135+
<Icon
136+
size={18}
137+
css={{
138+
color: isAlarm ? theme.colors.error : "inherit",
139+
opacity: 0.7,
140+
}}
141+
>
142+
{isAlarm ? "warning" : "solar_power"}
143+
</Icon>
144+
{data.power_unit}
145+
</div>
138146
<div
139147
css={{
148+
marginTop: "5px",
149+
display: "flex",
140150
fontWeight: 400,
141151
fontSize: 50,
142152
lineHeight: 1,
143153
fontVariantNumeric: "tabular-nums",
154+
[mq[0]]: { marginTop: 0, fontSize: 64 },
144155
}}
145156
>
146157
{displayPower}
147158
</div>
148159
</div>
160+
161+
<div
162+
css={{
163+
display: "none",
164+
[mq[0]]: {
165+
display: "flex",
166+
flexDirection: "column",
167+
alignItems: "flex-end",
168+
justifyContent: "center",
169+
gap: 6,
170+
...theme.typography.caption,
171+
color: theme.colors.text.muted,
172+
},
173+
}}
174+
>
175+
<span css={{ fontVariantNumeric: "tabular-nums" }}>
176+
{`${data.today_energy} ${data.today_energy_unit} tänään`}
177+
</span>
178+
{data.battery_soc !== null && (
179+
<span css={{ fontVariantNumeric: "tabular-nums" }}>
180+
{`akku ${Math.round(data.battery_soc)} %`}
181+
</span>
182+
)}
183+
{batteryLabel && batteryLabel !== "lepotila" && (
184+
<span>{batteryLabel}</span>
185+
)}
186+
</div>
149187
</div>
150188
</Box>
151189
);
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { FC } from "react";
2+
3+
type SparklineProps = {
4+
points: number[];
5+
color: string;
6+
height?: number;
7+
className?: string;
8+
};
9+
10+
const Sparkline: FC<SparklineProps> = ({
11+
points,
12+
color,
13+
height = 50,
14+
className,
15+
}) => {
16+
if (points.length < 2) return null;
17+
18+
const minY = Math.min(...points);
19+
const maxY = Math.max(...points);
20+
const range = maxY - minY || 1;
21+
const width = 200;
22+
const stepX = width / (points.length - 1);
23+
const padY = 2;
24+
25+
const coords = points.map(
26+
(y, i) =>
27+
[
28+
i * stepX,
29+
height - padY - ((y - minY) / range) * (height - 2 * padY),
30+
] as const,
31+
);
32+
const linePath = coords
33+
.map(([x, y], i) => `${i === 0 ? "M" : "L"}${x.toFixed(2)},${y.toFixed(2)}`)
34+
.join(" ");
35+
const fillPath = `${linePath} L${width},${height} L0,${height} Z`;
36+
37+
return (
38+
<svg
39+
className={className}
40+
width="100%"
41+
height={height}
42+
viewBox={`0 0 ${width} ${height}`}
43+
preserveAspectRatio="none"
44+
aria-hidden
45+
>
46+
<path d={fillPath} fill={color} opacity={0.18} />
47+
<path
48+
d={linePath}
49+
fill="none"
50+
stroke={color}
51+
strokeWidth={1.5}
52+
vectorEffect="non-scaling-stroke"
53+
/>
54+
</svg>
55+
);
56+
};
57+
58+
export default Sparkline;

0 commit comments

Comments
 (0)