Show current consumption chart
This commit is contained in:
@ -26,12 +26,6 @@ export function CachedConsumptionWidget(): React.ReactElement {
|
||||
});
|
||||
|
||||
return (
|
||||
<StatCard
|
||||
title="Cached consumption"
|
||||
data={[]}
|
||||
interval="Current data"
|
||||
trend="neutral"
|
||||
value={val?.toString() ?? "Loading"}
|
||||
/>
|
||||
<StatCard title="Cached consumption" value={val?.toString() ?? "Loading"} />
|
||||
);
|
||||
}
|
||||
|
@ -7,11 +7,14 @@ export function CurrConsumptionWidget(): React.ReactElement {
|
||||
const snackbar = useSnackbar();
|
||||
|
||||
const [val, setVal] = React.useState<undefined | number>();
|
||||
const [history, setHistory] = React.useState<number[] | undefined>();
|
||||
|
||||
const refresh = async () => {
|
||||
try {
|
||||
const s = await EnergyApi.CurrConsumption();
|
||||
const s = await EnergyApi.GridConsumption();
|
||||
const history = await EnergyApi.GridConsumptionHistory();
|
||||
setVal(s);
|
||||
setHistory(history);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
snackbar("Failed to refresh current consumption!");
|
||||
@ -19,7 +22,6 @@ export function CurrConsumptionWidget(): React.ReactElement {
|
||||
};
|
||||
|
||||
React.useEffect(() => {
|
||||
refresh();
|
||||
const i = setInterval(() => refresh(), 3000);
|
||||
|
||||
return () => clearInterval(i);
|
||||
@ -28,9 +30,8 @@ export function CurrConsumptionWidget(): React.ReactElement {
|
||||
return (
|
||||
<StatCard
|
||||
title="Current consumption"
|
||||
data={[]}
|
||||
interval="Current data"
|
||||
trend="neutral"
|
||||
data={history ?? []}
|
||||
interval="Last day"
|
||||
value={val?.toString() ?? "Loading"}
|
||||
/>
|
||||
);
|
||||
|
Reference in New Issue
Block a user