Skip to content

Commit c9df8a2

Browse files
committed
second release
1 parent 17876ff commit c9df8a2

File tree

5 files changed

+24
-13
lines changed

5 files changed

+24
-13
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
"@types/luxon": "^2.3.1",
8181
"@types/react": "^17.0.38",
8282
"@types/react-dom": "^17.0.11",
83+
"@types/react-timeago": "^4.1.3",
8384
"@typescript-eslint/eslint-plugin": "^5.15.0",
8485
"@typescript-eslint/parser": "^5.9.1",
8586
"@vercel/webpack-asset-relocator-loader": "^1.7.0",
@@ -104,13 +105,13 @@
104105
"electron-squirrel-startup": "^1.0.0",
105106
"express": "^4.17.3",
106107
"http-server": "^14.1.0",
107-
"javascript-time-ago": "^2.3.13",
108108
"jwt-decode": "^3.1.2",
109109
"keycloak-js": "^17.0.0",
110110
"luxon": "^2.3.1",
111111
"react": "^17.0.2",
112112
"react-dom": "^17.0.2",
113113
"react-redux": "^7.2.6",
114-
"react-router-dom": "^6.2.2"
114+
"react-router-dom": "^6.2.2",
115+
"react-timeago": "^6.2.1"
115116
}
116117
}

src/components/Status.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import React, { useEffect, useState } from 'react';
22
import Scheduler, { Statuses } from '../scheduler';
3-
import TimeAgo, { LocaleData } from 'javascript-time-ago';
4-
import en from 'javascript-time-ago/locale/en';
3+
import MyTimeAgo from 'react-timeago';
54
import './Status.css';
65

7-
TimeAgo.addLocale(en as LocaleData);
8-
const timeAgo = new TimeAgo('en-EN');
9-
106
const Status = () => {
117
const [data, setData] = useState<Statuses>();
128

@@ -26,7 +22,7 @@ const Status = () => {
2622
<div key={index}>
2723
{element.calledAt !== '' && element.receivedAt !== '' &&
2824
<div>
29-
{element.name}: {timeAgo.format(new Date(element.calledAt))} - {timeAgo.format(new Date(element.receivedAt))}
25+
{element.name}: <MyTimeAgo date={new Date(element.calledAt)}/> - <MyTimeAgo date={new Date(element.receivedAt)}/>
3026
</div>
3127
}
3228
</div>

src/scheduler.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Sensors } from './types/planetWatch/sensors';
55
import { DateTime } from 'luxon';
66
import { AwairToPlanetWatchMapper } from './mappers/AwairToPlanetWatchMapper';
77
import constants from './constants';
8+
import { authorization } from './utils/authorization';
89
export interface AwairAccount {
910
jwt: string;
1011
devices: AwairDevice[];
@@ -168,8 +169,9 @@ export class Scheduler {
168169
}
169170

170171
private async fetchAndSendData(accounts: AwairAccounts) {
172+
await authorization.refreshToken();
171173
// Grab all the data from awair and save them in a structure
172-
accounts .forEach((account) => {
174+
accounts.forEach((account) => {
173175
const jwt = account.jwt;
174176

175177
account.devices.forEach((device) => {
@@ -182,14 +184,24 @@ export class Scheduler {
182184

183185
AwairController.getLatestData(jwt, deviceType, deviceId)
184186
.then((res) => {
185-
PlanetWatchService.sendData(AwairToPlanetWatchMapper.map(device.deviceUUID, res))
186-
.catch((err) => console.log(err));
187187
this.statuses[device.deviceUUID].receivedAt = DateTime.now().toISO();
188188
this.statusSubscribers.forEach((callback) => callback({ ...this.statuses }));
189-
this.logs.push(DateTime.now().toFormat('[HH:mm:ss]') + ' - Retrieving data from ' + deviceId + '\n');
189+
this.logs.push(DateTime.now().toFormat('[HH:mm:ss]') + ' - Retrieved data from ' + deviceId + '\n');
190190
this.logSubscribers.forEach((callback) => callback([...this.logs]));
191+
PlanetWatchService.sendData(AwairToPlanetWatchMapper.map(device.deviceUUID, res))
192+
.then(() => {
193+
this.logs.push(DateTime.now().toFormat('[HH:mm:ss]') + ' - Successfully sent data to PW servers ' + deviceId + '\n');
194+
this.logSubscribers.forEach((callback) => callback([...this.logs]));
195+
})
196+
.catch((err) => {
197+
this.logs.push(DateTime.now().toFormat('[HH:mm:ss]') + ' - Error while sending data to PW servers of ' + deviceId + ' ' + err.response.data.errorMessage + '\n');
198+
this.logSubscribers.forEach((callback) => callback([...this.logs]));
199+
console.log(err.response.data.errorMessage);
200+
});
191201
})
192202
.catch((error) => {
203+
this.logs.push(DateTime.now().toFormat('[HH:mm:ss]') + ' - Error while retrieving data from ' + deviceId + ' ' + error.message + '\n');
204+
this.logSubscribers.forEach((callback) => callback([...this.logs]));
193205
console.log(error);
194206
});
195207
});

src/services/planetWatchService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const getSensors = async () => {
77
const main = constants.planetWatch.sensors;
88

99
const response = await axios.get<Sensors>(main);
10-
10+
1111
return response.data;
1212
};
1313

src/utils/authorization.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class Authorization {
4747
this.keycloak?.logout({ redirectUri: 'http://localhost:33333/keycloak-redirect' });
4848
};
4949

50+
refreshToken = async () => this.keycloak!.updateToken(60);
51+
5052
}
5153

5254
export type AuthorizationProviderProps = {

0 commit comments

Comments
 (0)