Skip to content

Commit b9cdb1b

Browse files
committed
Format frontend js files
1 parent 1e98efd commit b9cdb1b

File tree

5 files changed

+150
-108
lines changed

5 files changed

+150
-108
lines changed

src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ export const millisecondsSinceSleepEntry = (sleepEntry: SheetsSleepEntry) => {
2121
};
2222

2323
export const millisecondsToHours = (milliseconds: number) =>
24-
// biome-ignore lint/style/noMagicNumbers: <obvious>
24+
// biome-ignore lint/style/noMagicNumbers: <milliseconds in hour>
2525
milliseconds / 1000 / 60 / 60;
26-
// biome-ignore lint/style/noMagicNumbers: <obvious>
26+
// biome-ignore lint/style/noMagicNumbers: <milliseconds in minute>
2727
export const minutesToMilliseconds = (minutes: number) => minutes * 60 * 1000;
2828

2929
export const getTimezoneFromCoords = (lat: number, lng: number) => {

src/views/js/api.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import type { ApiResponse, GetLastSleepRouteResponse } from '../../types.js';
2-
import { getApiKey } from './params.js'
1+
import type { ApiResponse, GetLastSleepRouteResponse } from "../../types.js";
2+
import { getApiKey } from "./params.js";
33

44
export const getSleepEntries = async () => {
55
const apiKey = getApiKey();
66
const url = getEndpointUrl("api/sleep", apiKey);
77

88
return await fetch(url)
9-
.then(res => res.json())
10-
.catch(err => console.error(err));
9+
.then((res) => res.json())
10+
.catch((err) => console.error(err));
1111
};
1212

1313
export const getLastSleepEntry = async () => {
1414
const apiKey = getApiKey();
1515
const url = getEndpointUrl("api/sleep/last", apiKey);
1616

1717
const response = await fetch(url)
18-
.then(res => res.json())
19-
.catch(err => console.error(err));
18+
.then((res) => res.json())
19+
.catch((err) => console.error(err));
2020

2121
return response as ApiResponse<GetLastSleepRouteResponse>;
2222
};
@@ -30,25 +30,25 @@ export const submitSleepEntry = async (position: GeolocationPosition) => {
3030
accuracy: position.coords.accuracy,
3131
altitudeAccuracy: position.coords.altitudeAccuracy,
3232
heading: position.coords.heading,
33-
speed: position.coords.speed
33+
speed: position.coords.speed,
3434
},
3535
timestamp: position.timestamp,
3636
};
3737

3838
const options = {
39-
method: 'POST',
39+
method: "POST",
4040
body: JSON.stringify(json),
4141
headers: {
42-
'Content-Type': 'application/json',
42+
"Content-Type": "application/json",
4343
},
4444
};
4545

4646
const apiKey = getApiKey();
4747
const url = getEndpointUrl("api/sleep", apiKey);
4848

4949
return await fetch(url, options)
50-
.then(res => res.json())
51-
.catch(err => console.error(err));
50+
.then((res) => res.json())
51+
.catch((err) => console.error(err));
5252
};
5353

5454
export const replaceLastSleepEntry = async (position: GeolocationPosition) => {
@@ -60,31 +60,31 @@ export const replaceLastSleepEntry = async (position: GeolocationPosition) => {
6060
accuracy: position.coords.accuracy,
6161
altitudeAccuracy: position.coords.altitudeAccuracy,
6262
heading: position.coords.heading,
63-
speed: position.coords.speed
63+
speed: position.coords.speed,
6464
},
6565
timestamp: position.timestamp,
6666
};
6767

6868
const options = {
69-
method: 'PUT',
69+
method: "PUT",
7070
body: JSON.stringify(json),
7171
headers: {
72-
'Content-Type': 'application/json',
72+
"Content-Type": "application/json",
7373
},
7474
};
7575

7676
const apiKey = getApiKey();
7777
const url = getEndpointUrl("api/sleep/replace", apiKey);
7878

7979
return await fetch(url, options)
80-
.then(res => res.json())
81-
.catch(err => console.error(err));
82-
}
80+
.then((res) => res.json())
81+
.catch((err) => console.error(err));
82+
};
8383

8484
const getEndpointUrl = (endpoint: string, apiKey?: string) => {
8585
const url = new URL(endpoint, window.location.href);
8686
if (apiKey) {
87-
url.searchParams.append('apiKey', apiKey);
87+
url.searchParams.append("apiKey", apiKey);
8888
}
8989
return url;
90-
}
90+
};

src/views/js/params.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
export const getApiKey = () => {
22
const searchParams = new URLSearchParams(window.location.search);
3-
if (!searchParams.has('apiKey')) {
4-
const textElement = document.getElementById('text');
3+
if (!searchParams.has("apiKey")) {
4+
const textElement = document.getElementById("text");
55
if (textElement) {
6-
textElement.innerHTML = 'No API key provided';
6+
textElement.innerHTML = "No API key provided";
77
}
88
return;
99
}
10-
const apiKey = searchParams.get('apiKey');
10+
const apiKey = searchParams.get("apiKey");
1111
return apiKey ?? undefined;
12-
}
12+
};
1313

1414
export const getAutoLog = () => {
1515
const searchParams = new URLSearchParams(window.location.search);
16-
if (!searchParams.has('autoLog')) {
16+
if (!searchParams.has("autoLog")) {
1717
return null;
1818
}
19-
const autoLog = searchParams.get('autoLog');
19+
const autoLog = searchParams.get("autoLog");
2020
return autoLog;
21-
}
21+
};

0 commit comments

Comments
 (0)