Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #54 #203

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .vscode-janus-debug
Empty file.
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"eslint.enable": false,
"tslint.enable": false
}
Binary file not shown.
48 changes: 48 additions & 0 deletions react-frontend/src/actions/alarms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

export let overflowAlarm = (currentWaterLevel, currentTankId) => {
const dangerousWaterLevel = 98;
const audio = new Audio('/sounds/zapsplat_science_fiction_alarm_big_warning_meltdown_wailing_deep_tone_fast_40027');
/* sound source: https://www.zapsplat.com/music/big-science-fiction-alarm-siren-warning-of-meltdown-or-catastrophe-wailing-deep-tone-fast/
license: https://www.zapsplat.com/license-type/standard-license/ */

const startAudioAlarm = () => {
audio.play();
audio.loop = true;
};

const stopAudioAlarm = () => {
audio.pause();
audio.currentTime = 0;
};

const addStopAlarmButton = () => {
let currentTank = document.getElementById(`${currentTankId}`);
const stopAlarmButton = document.createElement('button');
stopAlarmButton.className = 'alarm-button';
stopAlarmButton.style.display = 'flex';
stopAlarmButton.style.justifyContent = 'center';
stopAlarmButton.style.alignItems = 'center';
stopAlarmButton.addEventListener('click', stopAlarm);
currentTank.appendChild(stopAlarmButton);
};

const removeStopAlarmButton = (clickedButton) => {
clickedButton.parentNode.removeChild(clickedButton);
};

const stopAlarm = (event) => {
stopAudioAlarm();
removeStopAlarmButton(event.target);
};

// when water level becomes dangerous triggers the alarm
const checkWaterLevel = () => {
if (currentWaterLevel >= dangerousWaterLevel) {
startAudioAlarm();
addStopAlarmButton();
}
};

const repeatWaterLevelCheck = setInterval(checkWaterLevel, 1000);
repeatWaterLevelCheck();
};
1 change: 1 addition & 0 deletions react-frontend/src/actions/tankActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export const fetchTanks = () => {
]
};
};

15 changes: 10 additions & 5 deletions react-frontend/src/pages/Home.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import React, { Component } from "react";
import { TankCircle, TankWaterValue } from "../components/Tank";
import { Sticker } from "../components/Sticker";
import { connect } from "react-redux";
import { fetchTanks } from "../actions/tankActions";

import React, { Component } from 'react'
import {TankCircle, TankWaterValue} from '../components/Tank';
import {Sticker} from '../components/Sticker'
import { connect } from 'react-redux';
import { fetchTanks } from '../actions/tankActions';
import {overflowAlarm} from '../actions/alarms';


class Home extends Component {
componentWillMount() {
Expand Down Expand Up @@ -38,8 +41,10 @@ class Home extends Component {
<span className="tank-title">Tank{tank.id}</span>
</div>
</center>
{overflowAlarm(tank.value, tank.id)}
</div>
</div>

))}
</div>
</div>
Expand Down