Skip to content

Commit 181cb58

Browse files
✨ Support nested Oura sleep data
1 parent b058ddd commit 181cb58

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

index.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { Line, Bar } from "react-chartjs-2";
77
import dayjs from "dayjs";
88
import "./styles.scss";
99

10+
const ucFirst = (str: string) => str.charAt(0).toUpperCase() + str.slice(1);
11+
1012
const subDirectories = ["rescuetime-time-tracking", "oura-activity", "oura-sleep"];
1113

1214
const categoryColors: { [index: string]: string } = {
@@ -21,6 +23,10 @@ const categoryColors: { [index: string]: string } = {
2123
"Social Networking": "#cc423a",
2224
Entertainment: "#da422b",
2325
Shopping: "#e84118",
26+
rem: "#272740",
27+
deep: "#514b83",
28+
light: "#8d569f",
29+
awake: "#f7e1ef",
2430
};
2531

2632
const itemNames: { [index: string]: string } = {
@@ -83,7 +89,7 @@ const getDatasets = (
8389
return Object.keys(total)
8490
.sort((a, b) => Object.keys(categoryColors).indexOf(a) - Object.keys(categoryColors).indexOf(b))
8591
.map((key) => ({
86-
label: key,
92+
label: ucFirst(key || ""),
8793
data: total[key],
8894
borderWidth: 1,
8995
borderColor: "#fff",
@@ -172,7 +178,15 @@ const App: FunctionComponent<{}> = () => {
172178
})
173179
.catch(() => setError(true));
174180
useMemoApiData(repo, api, path)
175-
.then(setGraphData)
181+
.then((data) => {
182+
Object.keys(data).forEach((key) => {
183+
if (data[key].rem) {
184+
delete data[key].total;
185+
delete data[key].duration;
186+
}
187+
});
188+
setGraphData(data);
189+
})
176190
.catch(() => setError(true));
177191
}
178192

0 commit comments

Comments
 (0)