Compare commits

..

No commits in common. "a1dc088a2339dad8c4dce47b2b471a6f0f54c074" and "fe9f7e81e980f15b4f2212b071046f1eda96c0c0" have entirely different histories.

2 changed files with 5 additions and 27 deletions

View File

@ -9,18 +9,18 @@ import { TG_API, TG_USERID } from "../config";
function sendNotification(close) {
if (window.sendingAccidentAlert)
return;
window.sendingAccidentAlert = true;
window.sending = true;
const bot = new Telegram(TG_API);
bot.sendMessage(TG_USERID, "User detected in an accident. Location has been attached below.");
navigator.geolocation.getCurrentPosition(
position => {
window.sendingAccidentAlert = false;
bot.sendLocation( TG_USERID,
position.coords.latitude, position.coords.longitude);
window.sendingAccidentAlert = false;
},
() => {
window.sendingAccidentAlert = false;
bot.sendMessage(TG_USERID, "Error retrieving location");
window.sendingAccidentAlert = false;
}
);
setTimeout(close, 2000);

View File

@ -3,38 +3,16 @@ import PropTypes from "prop-types";
import GenericPageWithIcon from "./GenericPageWithIcon";
import { Sun } from "grommet-icons";
import axios from "axios";
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;
}
import { CAR_API } from "../config";
function PetMode(props) {
const [ temp, setTemp ] = useState(null);
const [ , setNotified ] = useState(false);
useEffect(() => {
axios.get(`${CAR_API}data/InsideTemperature`)
.then(resp => setTemp(resp.data.value));
const id = setInterval(
() => axios.get(`${CAR_API}data/InsideTemperature`)
.then(resp => {
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;
});
}
}),
.then(resp => setTemp(resp.data.value)),
1000
);
return () => clearInterval(id);