Skip to content

Commit 61831db

Browse files
committed
some change
1 parent 2e4e9d5 commit 61831db

File tree

4 files changed

+95
-4
lines changed

4 files changed

+95
-4
lines changed

public/no-internet.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

src/App.css

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,45 @@ body { background: #13131374; }
3939
padding: 40px 20px;
4040
}
4141
}
42+
.offline-container {
43+
display: flex;
44+
flex-direction: column;
45+
justify-content: center;
46+
align-items: center;
47+
height: 100vh;
48+
background-color: #f0f2f5;
49+
text-align: center;
50+
}
51+
52+
.offline-container p {
53+
font-size: 1.5rem;
54+
font-weight: 600;
55+
color: #333;
56+
margin-top: 1rem;
57+
}
58+
59+
.offline-container span {
60+
font-size: 1rem;
61+
color: #666;
62+
margin-top: 0.5rem;
63+
}
64+
65+
.reload-button {
66+
margin-top: 1.5rem;
67+
padding: 0.75rem 1.5rem;
68+
font-size: 1rem;
69+
font-weight: 600;
70+
color: #fff;
71+
background-color: #007bff;
72+
border: none;
73+
border-radius: 8px;
74+
cursor: pointer;
75+
transition: background-color 0.3s ease;
76+
}
77+
78+
.reload-button:hover {
79+
background-color: #0056b3;
80+
}
4281

4382

4483

src/App.jsx

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { API_BASE_URL } from "./api";
2-
import React, { useContext, useEffect } from "react";
2+
import React, { useContext, useEffect, useState } from "react";
33
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
44
import Dashboard from "./components/Dashboard/Dashboard";
55
import Login from "./components/Login";
@@ -20,6 +20,7 @@ import DescriptionDashboard from "./components/DescriptionDetailPage";
2020
import DescriptionBill from "./components/MedicalDescriptions";
2121
import DoctorDashboard from "./components/Doctor/DoctorDashboard";
2222
import AppointmentDetail from "./components/Doctor/AppointmentDetail"; // new detail page
23+
import OfflineAnimation from "./components/OfflineAnimation";
2324

2425
const App = () => {
2526
const {
@@ -33,6 +34,28 @@ const App = () => {
3334
setDoctor
3435
} = useContext(Context);
3536

37+
const [isOnline, setIsOnline] = useState(navigator.onLine);
38+
39+
useEffect(() => {
40+
const handleOnline = () => {
41+
setIsOnline(true);
42+
// Reload the page to ensure everything is re-initialized correctly
43+
window.location.reload();
44+
};
45+
const handleOffline = () => {
46+
setIsOnline(false);
47+
};
48+
49+
window.addEventListener('online', handleOnline);
50+
window.addEventListener('offline', handleOffline);
51+
52+
// Cleanup listeners on component unmount
53+
return () => {
54+
window.removeEventListener('online', handleOnline);
55+
window.removeEventListener('offline', handleOffline);
56+
};
57+
}, []);
58+
3659
useEffect(() => {
3760
const fetchAdmin = async () => {
3861
try {
@@ -62,9 +85,15 @@ const App = () => {
6285
}
6386
};
6487

65-
fetchAdmin();
66-
fetchDoctor();
67-
}, [isAuthenticated, isDoctorAuthenticated]);
88+
if (isOnline) {
89+
fetchAdmin();
90+
fetchDoctor();
91+
}
92+
}, [isOnline, isAuthenticated, isDoctorAuthenticated, setAdmin, setDoctor, setIsAuthenticated, setIsDoctorAuthenticated]);
93+
94+
if (!isOnline) {
95+
return <OfflineAnimation />;
96+
}
6897

6998
return (
7099
<Router>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react';
2+
import Lottie from 'lottie-react';
3+
import noInternetAnimation from '../../public/no-internet.json';
4+
5+
const OfflineAnimation = () => {
6+
const handleReload = () => {
7+
window.location.reload();
8+
};
9+
10+
return (
11+
<div className="offline-container overflow-hidden">
12+
<Lottie animationData={noInternetAnimation} loop={true} style={{ width: 300, height: 300 , overflow: "hidden" }} />
13+
<p>No Internet Connection</p>
14+
<span>Please check your connection and try again.</span>
15+
<button onClick={handleReload} className="reload-button">
16+
Try Again
17+
</button>
18+
</div>
19+
);
20+
};
21+
22+
export default OfflineAnimation;

0 commit comments

Comments
 (0)