Skip to content

Commit

Permalink
Merge pull request #400 from ar-io/PE-5031-no-network-handling
Browse files Browse the repository at this point in the history
feat(PE-5031): Block network calls when no network and show banner
  • Loading branch information
atticusofsparta authored Jan 11, 2024
2 parents 417ee44 + 91fe7ea commit bf557e2
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/components/layout/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect, useState } from 'react';
import { Link } from 'react-router-dom';

import { useRegistrationState } from '../../../state/contexts/RegistrationState';
Expand All @@ -8,12 +9,36 @@ import './styles.css';

function NavBar() {
const [, dispatchRegisterState] = useRegistrationState();
const [online, setOnline] = useState(navigator.onLine);

useEffect(() => {
window.addEventListener('online', () => setOnline(true));
window.addEventListener('offline', () => setOnline(false));
return () => {
window.removeEventListener('online', () => setOnline(true));
window.removeEventListener('offline', () => setOnline(false));
};
}, []);

return (
<div
className="flex flex-column"
style={{ gap: '0px', position: 'relative' }}
>
{online ? null : (
<div
className="flex flex-row center"
style={{
backgroundColor: 'var(--accent)',
padding: '10px',
}}
>
<span className="text black bold">
We can&apos;t connect to the Internet. Please check your connection
and try again.
</span>
</div>
)}
<div className="navbar" style={{ position: 'relative' }}>
<div className="flex-row flex-left" style={{ width: 'fit-content' }}>
<Link
Expand Down

0 comments on commit bf557e2

Please sign in to comment.