Skip to content

Commit

Permalink
feat: typescript conversion app.jsx and online status added
Browse files Browse the repository at this point in the history
  • Loading branch information
varun2948 authored and spwoodcock committed Mar 27, 2024
1 parent 21ad437 commit e6f2fbb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

<body>
<div id="app"></div>
<script type="module" src="/src/App.jsx"></script>
<script type="module" src="/src/App.tsx"></script>
</body>
</html>
28 changes: 26 additions & 2 deletions src/frontend/src/App.jsx → src/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import axios from 'axios';
import React, { useEffect } from 'react';
import ReactDOM from 'react-dom';
import { RouterProvider } from 'react-router-dom';
import { Provider } from 'react-redux';
import { Provider, useDispatch } from 'react-redux';
import { PersistGate } from 'redux-persist/integration/react';
import { CommonActions } from '@/store/slices/CommonSlice';

import { store, persistor } from '@/store/Store';
import routes from '@/routes';
Expand All @@ -13,6 +14,11 @@ import '@/index.css';
import 'ol/ol.css';
import 'react-loading-skeleton/dist/skeleton.css';

enum Status {
'online',
'offline',
}

// Added Fix of Console Error of MUI Issue
const consoleError = console.error;
const SUPPRESSED_WARNINGS = [
Expand Down Expand Up @@ -51,9 +57,27 @@ axios.interceptors.request.use(
);

const GlobalInit = () => {
const dispatch = useDispatch();
const checkStatus = (status: string) => {
console.log(status);
dispatch(
CommonActions.SetSnackBar({
open: true,
message: 'Connection Status: ' + status,
variant: status === 'online' ? 'success' : 'error',
duration: 2000,
}),
);
};
useEffect(() => {
window.addEventListener('offline', () => checkStatus('offline'));
window.addEventListener('online', () => checkStatus('online'));

// Do stuff at init here
return () => {};
return () => {
window.removeEventListener('offline', () => checkStatus('offline'));
window.removeEventListener('online', () => checkStatus('online'));
};
}, []);
return null; // Renders nothing
};
Expand Down

0 comments on commit e6f2fbb

Please sign in to comment.