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

isonline wifi check #123

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 18 additions & 12 deletions home/webapp/src/components/NavBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ const navIcons = {
settings: SettingsIcon,
};

const NavBar = ({ onPageChange, checkConnection, checkBatteryLevel }) => {
const wifiPages = ['community', 'classroom'];

const NavBar = ({ onPageChange, checkBatteryLevel }) => {
const [activePage, setActivePage] = useState('home');
const [isConnected, setIsConnected] = useState(true);
const [isConnected, setIsConnected] = useState(navigator.onLine);
const [currentTime, setCurrentTime] = useState("");
const [batteryLevel, setBatteryLevel] = useState(0.8); // Default battery level
const theme = useTheme()
Expand All @@ -25,12 +27,6 @@ const NavBar = ({ onPageChange, checkConnection, checkBatteryLevel }) => {
});
};

// Function to update the connection status
const updateConnectionStatus = async () => {
const status = await checkConnection();
setIsConnected(status);
};

// Function to update the battery level
const updateBatteryLevel = async () => {
const level = await checkBatteryLevel();
Expand All @@ -46,15 +42,21 @@ const NavBar = ({ onPageChange, checkConnection, checkBatteryLevel }) => {
// Use useEffect to set up intervals for updating connection status, time, and battery level
useEffect(() => {
// Update connection status every minute
const connectionIntervalId = setInterval(updateConnectionStatus, 60000);
// Update time every second

window.ononline = function() {
setIsConnected(true);
}

window.onoffline = function() {
setIsConnected(false)
}

const timeIntervalId = setInterval(updateTime, 1000);
// Update battery level every 5 minutes
const batteryLevelIntervalId = setInterval(updateBatteryLevel, 300000);

// Clean up intervals when the component unmounts
return () => {
clearInterval(connectionIntervalId);
clearInterval(timeIntervalId);
clearInterval(batteryLevelIntervalId);
};
Expand All @@ -75,12 +77,15 @@ const NavBar = ({ onPageChange, checkConnection, checkBatteryLevel }) => {
<NavButtonsContainer>
{Object.keys(navIcons).map((page) => {
const Icon = navIcons[page];
const pageSelectable = !wifiPages.includes(page) || wifiPages.includes(page) && isConnected
return (
<NavButton
key={page}
active={activePage === page}
onClick={() => handleButtonClick(page)}
tabIndex={0}
tabIndex={pageSelectable ? 0 : -1}
disabled={pageSelectable}
className={pageSelectable ? "" : 'disabled_nav'}
>
<Icon color={activePage === page ? theme.colors.textActive : theme.colors.text}/>
</NavButton>
Expand All @@ -92,6 +97,7 @@ const NavBar = ({ onPageChange, checkConnection, checkBatteryLevel }) => {
{<DynamicBatteryIcon level={batteryLevel} theme={theme}/>}
{/* Conditionally render WiFiIcon or NoSignalIcon based on isConnected */}
{isConnected ? <WiFiIcon color={theme.colors.text}/> : <NoSignalIcon color={theme.colors.text}/>}

<TimeContainer>
{currentTime}
</TimeContainer>
Expand Down
6 changes: 3 additions & 3 deletions home/webapp/src/components/Settings/NetworkSettingsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as Styled from "../styles/Settings.styled";

export default function NetworkSettingsPage() {
const [connectedNetwork, setConnectedNetwork] = useState(null);
const [wifiNetworks, setWifiNetworks] = useState(["Network1", "Network2"]);
const [wifiNetworks, setWifiNetworks] = useState(["Network1", "Network2", "n3", "n4", "n5", "n6", "n7", "n8"]);

const fetchNetworks = async () => {
try {
Expand Down Expand Up @@ -103,8 +103,8 @@ export default function NetworkSettingsPage() {
(<span>✗ Not Connected</span>)}
</Styled.ConnectedNetwork>

<Styled.DisconnectButton onClick={handleDisconnectButtonClick} tabIndex="0">Disconnect</Styled.DisconnectButton>
<Styled.RefreshButton onClick={handleRefreshButtonClick} tabIndex="0">↻</Styled.RefreshButton>
<Styled.DisconnectButton onClick={handleDisconnectButtonClick} tabIndex={0}>Disconnect</Styled.DisconnectButton>
<Styled.RefreshButton onClick={handleRefreshButtonClick} tabIndex={0}>↻</Styled.RefreshButton>
</Styled.NetworkActionBar>

{renderWifiContent()}
Expand Down
4 changes: 4 additions & 0 deletions home/webapp/src/components/styles/NavBar.styled.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export const NavButton = styled.div`
outline: 3px solid ${({ theme }) => theme.colors.text};
outline-offset: -3px;
}

&.disabled_nav {
opacity: 0.1
}
`;

export const StatusIconsContainer = styled.div`
Expand Down
2 changes: 2 additions & 0 deletions home/webapp/src/components/styles/Settings.styled.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export const NetworksList = styled.div`
flex-direction: column;
align-items: center;

max-height: 180px;

&::-webkit-scrollbar {
display: none;
}
Expand Down