Skip to content

Commit

Permalink
web: fix duplicate api call when change energy chart type multiple time
Browse files Browse the repository at this point in the history
  • Loading branch information
hoang-rio committed Dec 19, 2024
1 parent 2e89c81 commit 233212b
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 30 deletions.
15 changes: 9 additions & 6 deletions web_viewer/fe_src/src/components/DailyChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,17 @@ const DailyChart = forwardRef((_, ref: ForwardedRef<IFetchChart>) => {
})
);

const onVisiblityChange = useCallback(() => {
if (!document.hidden) {
fetchChart();
}
}, [fetchChart]);

useEffect(() => {
fetchChart();
document.addEventListener("visibilitychange", () => {
if (!document.hidden) {
fetchChart();
}
});
}, [fetchChart]);
document.addEventListener("visibilitychange", onVisiblityChange);
return () => document.removeEventListener("visibilitychange", onVisiblityChange);
}, [fetchChart, onVisiblityChange]);

useEffect(() => {
const mq = window.matchMedia("(prefers-color-scheme: dark)");
Expand Down
16 changes: 10 additions & 6 deletions web_viewer/fe_src/src/components/MonthlyChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,18 @@ const MonthlyChart = forwardRef((_, ref: ForwardedRef<IFetchChart>) => {
})
);

const onVisiblityChange = useCallback(() => {
if (!document.hidden) {
fetchChart();
}
}, [fetchChart]);

useEffect(() => {
fetchChart();
document.addEventListener("visibilitychange", () => {
if (!document.hidden) {
fetchChart();
}
});
}, [fetchChart]);
document.addEventListener("visibilitychange", onVisiblityChange);
return () =>
document.removeEventListener("visibilitychange", onVisiblityChange);
}, [fetchChart, onVisiblityChange]);

useEffect(() => {
const mq = window.matchMedia("(prefers-color-scheme: dark)");
Expand Down
16 changes: 10 additions & 6 deletions web_viewer/fe_src/src/components/YearlyChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,18 @@ const YearlyChart = forwardRef((_, ref: ForwardedRef<IFetchChart>) => {
})
);

const onVisiblityChange = useCallback(() => {
if (!document.hidden) {
fetchChart();
}
}, [fetchChart]);

useEffect(() => {
fetchChart();
document.addEventListener("visibilitychange", () => {
if (!document.hidden) {
fetchChart();
}
});
}, [fetchChart]);
document.addEventListener("visibilitychange", onVisiblityChange);
return () =>
document.removeEventListener("visibilitychange", onVisiblityChange);
}, [fetchChart, onVisiblityChange]);

useEffect(() => {
const mq = window.matchMedia("(prefers-color-scheme: dark)");
Expand Down
2 changes: 2 additions & 0 deletions web_viewer/public/assets/EnergyChart-CqgWYZ6D.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions web_viewer/public/assets/EnergyChart-yyp8EL_K.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
import{j as e}from"./index-bn3fLlzU.js";function l({value:r,unit:s,className:n}){return e.jsxs("div",{className:`${n||""} general-value`,children:[e.jsx("strong",{children:r}),s]})}export{l as G};
import{j as e}from"./index-2Fv8VwMK.js";function l({value:r,unit:s,className:n}){return e.jsxs("div",{className:`${n||""} general-value`,children:[e.jsx("strong",{children:r}),s]})}export{l as G};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions web_viewer/public/assets/MonthlyChart-2LzxHQgP.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion web_viewer/public/assets/MonthlyChart-CPAcdl1p.js

This file was deleted.

Loading

0 comments on commit 233212b

Please sign in to comment.