Display alarm status on home page
This commit is contained in:
parent
d990a64efb
commit
e925a184c3
|
@ -128,7 +128,7 @@ function MemberInfo(props) {
|
||||||
};
|
};
|
||||||
|
|
||||||
export function Home(props) {
|
export function Home(props) {
|
||||||
const { user } = props;
|
const { user, token } = props;
|
||||||
const [stats, setStats] = useState(JSON.parse(localStorage.getItem('stats', 'false')));
|
const [stats, setStats] = useState(JSON.parse(localStorage.getItem('stats', 'false')));
|
||||||
const [refreshCount, refreshStats] = useReducer(x => x + 1, 0);
|
const [refreshCount, refreshStats] = useReducer(x => x + 1, 0);
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
@ -136,7 +136,7 @@ export function Home(props) {
|
||||||
const bypass_code = location.hash.replace('#', '');
|
const bypass_code = location.hash.replace('#', '');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
requester('/stats/', 'GET')
|
requester('/stats/', 'GET', token)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
setStats(res);
|
setStats(res);
|
||||||
localStorage.setItem('stats', JSON.stringify(res));
|
localStorage.setItem('stats', JSON.stringify(res));
|
||||||
|
@ -159,6 +159,8 @@ export function Home(props) {
|
||||||
const getTrackAgo = (x) => stats && stats.track && stats.track[x] ? moment.unix(stats.track[x]['time']).tz('America/Edmonton').fromNow() : '';
|
const getTrackAgo = (x) => stats && stats.track && stats.track[x] ? moment.unix(stats.track[x]['time']).tz('America/Edmonton').fromNow() : '';
|
||||||
const getTrackName = (x) => stats && stats.track && stats.track[x] && stats.track[x]['username'] ? stats.track[x]['username'] : 'Unknown';
|
const getTrackName = (x) => stats && stats.track && stats.track[x] && stats.track[x]['username'] ? stats.track[x]['username'] : 'Unknown';
|
||||||
|
|
||||||
|
const alarmStat = () => stats && stats.alarm && moment().unix() - stats.alarm['time'] < 300 ? stats.alarm['data'] > 200 ? 'Armed' : 'Disarmed' : 'Unknown';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container>
|
<Container>
|
||||||
<Grid stackable padded columns={2}>
|
<Grid stackable padded columns={2}>
|
||||||
|
@ -273,6 +275,8 @@ export function Home(props) {
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
} trigger={<a>[more]</a>} />
|
} trigger={<a>[more]</a>} />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
{user && user.member.vetted_date && <p>Alarm status: {alarmStat()}</p>}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</Segment>
|
</Segment>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user