Compare commits
No commits in common. "a1dc088a2339dad8c4dce47b2b471a6f0f54c074" and "fe9f7e81e980f15b4f2212b071046f1eda96c0c0" have entirely different histories.
a1dc088a23
...
fe9f7e81e9
|
@ -9,18 +9,18 @@ import { TG_API, TG_USERID } from "../config";
|
||||||
function sendNotification(close) {
|
function sendNotification(close) {
|
||||||
if (window.sendingAccidentAlert)
|
if (window.sendingAccidentAlert)
|
||||||
return;
|
return;
|
||||||
window.sendingAccidentAlert = true;
|
window.sending = true;
|
||||||
const bot = new Telegram(TG_API);
|
const bot = new Telegram(TG_API);
|
||||||
bot.sendMessage(TG_USERID, "User detected in an accident. Location has been attached below.");
|
bot.sendMessage(TG_USERID, "User detected in an accident. Location has been attached below.");
|
||||||
navigator.geolocation.getCurrentPosition(
|
navigator.geolocation.getCurrentPosition(
|
||||||
position => {
|
position => {
|
||||||
window.sendingAccidentAlert = false;
|
|
||||||
bot.sendLocation( TG_USERID,
|
bot.sendLocation( TG_USERID,
|
||||||
position.coords.latitude, position.coords.longitude);
|
position.coords.latitude, position.coords.longitude);
|
||||||
|
window.sendingAccidentAlert = false;
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
window.sendingAccidentAlert = false;
|
|
||||||
bot.sendMessage(TG_USERID, "Error retrieving location");
|
bot.sendMessage(TG_USERID, "Error retrieving location");
|
||||||
|
window.sendingAccidentAlert = false;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
setTimeout(close, 2000);
|
setTimeout(close, 2000);
|
||||||
|
|
|
@ -3,38 +3,16 @@ import PropTypes from "prop-types";
|
||||||
import GenericPageWithIcon from "./GenericPageWithIcon";
|
import GenericPageWithIcon from "./GenericPageWithIcon";
|
||||||
import { Sun } from "grommet-icons";
|
import { Sun } from "grommet-icons";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import { CAR_API } from "../config";
|
||||||
import Telegram from "../utils/telegram";
|
|
||||||
import { CAR_API, TG_API, TG_USERID } from "../config";
|
|
||||||
|
|
||||||
function sendNotification(temp) {
|
|
||||||
if (window.sendingPetAlert)
|
|
||||||
return;
|
|
||||||
window.sendingPetAlert = true;
|
|
||||||
const bot = new Telegram(TG_API);
|
|
||||||
bot.sendMessage(TG_USERID, `The temperature in the car is ${temp}°C. Please check your child/pet.`);
|
|
||||||
window.sendingPetAlert = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function PetMode(props) {
|
function PetMode(props) {
|
||||||
const [ temp, setTemp ] = useState(null);
|
const [ temp, setTemp ] = useState(null);
|
||||||
const [ , setNotified ] = useState(false);
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
axios.get(`${CAR_API}data/InsideTemperature`)
|
axios.get(`${CAR_API}data/InsideTemperature`)
|
||||||
.then(resp => setTemp(resp.data.value));
|
.then(resp => setTemp(resp.data.value));
|
||||||
const id = setInterval(
|
const id = setInterval(
|
||||||
() => axios.get(`${CAR_API}data/InsideTemperature`)
|
() => axios.get(`${CAR_API}data/InsideTemperature`)
|
||||||
.then(resp => {
|
.then(resp => setTemp(resp.data.value)),
|
||||||
setTemp(resp.data.value);
|
|
||||||
if (resp.data.value > 35 || resp.data.value < 5) {
|
|
||||||
setNotified(notified => {
|
|
||||||
if (notified)
|
|
||||||
return true;
|
|
||||||
sendNotification(resp.data.value);
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
1000
|
1000
|
||||||
);
|
);
|
||||||
return () => clearInterval(id);
|
return () => clearInterval(id);
|
||||||
|
|
Loading…
Reference in New Issue