Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
feat(ops status): visible indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricpoon committed Oct 24, 2024
1 parent 27b61ad commit dc6df4b
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 28 deletions.
11 changes: 10 additions & 1 deletion src/components/Navbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,13 @@

.navbar a:hover {
text-decoration: underline;
}
}

.status-indicator {
display: flex;
align-items: center;
}

.status-indicator .icon {
margin-right: 0.5rem;
}
49 changes: 33 additions & 16 deletions src/components/Navbar.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import React from 'react';
import { AppBar, Toolbar, Typography, Button, IconButton, Drawer, List, ListItem, ListItemText, useTheme, useMediaQuery, Select, MenuItem } from '@mui/material';
import { Menu as MenuIcon } from '@mui/icons-material';
import { AppBar, Toolbar, Typography, Button, IconButton, Drawer, List, ListItem, ListItemText, Select, MenuItem, useTheme, useMediaQuery } from '@mui/material';
import MenuIcon from '@mui/icons-material/Menu';
import { Link } from 'react-router-dom';
import { useSelector, useDispatch } from 'react-redux';
import { useDispatch, useSelector } from 'react-redux';
import { setSelectedCurrency } from '../redux/slices/currencySlice';
import useOnlineStatus from '../hooks/useOnlineStatus';
import CircleIcon from '@mui/icons-material/Circle'; // Icon for status indicator
import { green, red } from '@mui/material/colors';
import './Navbar.css'; // Ensure you have appropriate styles

function Navbar() {
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
const [drawerOpen, setDrawerOpen] = React.useState(false);
const dispatch = useDispatch();
const { availableCurrencies, selectedCurrency } = useSelector((state) => state.currency);
const isOnline = useOnlineStatus(); // Get online status

const handleDrawerToggle = () => {
setDrawerOpen(!drawerOpen);
Expand Down Expand Up @@ -49,6 +54,12 @@ function Navbar() {
))}
</Select>
</ListItem>
<ListItem>
<Typography variant="body2" display="flex" alignItems="center">
<CircleIcon sx={{ color: isOnline ? green[500] : red[500], mr: 1 }} />
{isOnline ? 'Online' : 'Offline'}
</Typography>
</ListItem>
</List>
</div>
);
Expand All @@ -72,19 +83,25 @@ function Navbar() {
</Button>
))}
{!isMobile && (
<Select
value={selectedCurrency}
onChange={handleCurrencyChange}
variant="outlined"
size="small"
style={{ marginLeft: '1rem', color: 'white', borderColor: 'white' }}
>
{availableCurrencies.map((currency) => (
<MenuItem key={currency} value={currency}>
{currency}
</MenuItem>
))}
</Select>
<>
<Select
value={selectedCurrency}
onChange={handleCurrencyChange}
variant="outlined"
size="small"
style={{ marginLeft: '1rem', color: 'white', borderColor: 'white' }}
>
{availableCurrencies.map((currency) => (
<MenuItem key={currency} value={currency}>
{currency}
</MenuItem>
))}
</Select>
<Typography variant="body2" display="flex" alignItems="center" sx={{ ml: 2 }}>
<CircleIcon sx={{ color: isOnline ? green[500] : red[500], mr: 0.5 }} />
{isOnline ? 'Online' : 'Offline'}
</Typography>
</>
)}
</Toolbar>
</AppBar>
Expand Down
15 changes: 15 additions & 0 deletions src/config/currencyConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const currencyConfig = {
currencies: ['USD', 'EUR', 'GBP', 'JPY', 'HKD', 'CNY', 'TWD'],
currencyToCountry: {
USD: 'US', // United States
EUR: 'DE', // Germany (as a representative of the Eurozone)
GBP: 'GB', // United Kingdom
JPY: 'JP', // Japan
HKD: 'HK', // Hong Kong
CNY: 'CN', // China
TWD: 'TW', // Taiwan
// Add more currencies as needed
},
};

export default currencyConfig;
3 changes: 2 additions & 1 deletion src/redux/slices/currencySlice.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit';
import currencyService from '../../services/currencyService';
import currencyConfig from '../../config/currencyConfig'; // Import the config

// Async thunk to fetch exchange rates
export const fetchExchangeRates = createAsyncThunk(
Expand All @@ -13,7 +14,7 @@ export const fetchExchangeRates = createAsyncThunk(
const currencySlice = createSlice({
name: 'currency',
initialState: {
availableCurrencies: ['USD', 'EUR', 'GBP', 'JPY', 'HKD', 'CNY', 'TWD'],
availableCurrencies: currencyConfig.currencies, // Use config
selectedCurrency: 'USD',
exchangeRates: { USD: 1 },
lastUpdated: null, // Add lastUpdated field
Expand Down
13 changes: 3 additions & 10 deletions src/utils/currencyToCountry.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
const currencyToCountry = {
USD: 'US', // United States
EUR: 'DE', // Germany (as a representative of the Eurozone)
GBP: 'GB', // United Kingdom
JPY: 'JP', // Japan
HKD: 'HK', // Hong Kong
CNY: 'CN', // China
TWD: 'TW', // Taiwan
// Add more currencies as needed
};
import currencyConfig from '../config/currencyConfig';

const { currencyToCountry } = currencyConfig;

export default currencyToCountry;

0 comments on commit dc6df4b

Please sign in to comment.