Skip to content

Commit

Permalink
adjust styling for black and white theme
Browse files Browse the repository at this point in the history
  • Loading branch information
YeonV committed Sep 26, 2024
1 parent cc2648b commit 0f5c9bd
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 36 deletions.
8 changes: 4 additions & 4 deletions src/components/AddButton/AddButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Fab, IconButton } from '@mui/material'
import { Fab, IconButton, useTheme } from '@mui/material'
import { AddSharp as Add, ElectricalServices } from '@mui/icons-material'
import { useState } from 'react'
import useStore from '../../store/useStore'
Expand All @@ -16,7 +16,7 @@ import {

const AddButton = ({ className, style, setBackdrop, sx }: AddButtonProps) => {
const classes = useStyles()

const theme = useTheme()
const features = useStore((state) => state.features)
const openAddScene = useStore((state) => state.setDialogOpenAddScene)
const openAddDevice = useStore((state) => state.setDialogOpenAddDevice)
Expand Down Expand Up @@ -80,12 +80,12 @@ const AddButton = ({ className, style, setBackdrop, sx }: AddButtonProps) => {
sx={sx}
>
<Fab
color="primary"
variant="circular"
aria-label="add"
onClick={handleClick}
sx={{ bgcolor: theme.palette.primary.main }}
>
<Add />
<Add sx={{color: theme.palette.primary.contrastText }} />
</Fab>
<StyledMenu
id="customized-menu"
Expand Down
92 changes: 72 additions & 20 deletions src/components/Bars/BarTop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ import {
MenuItem,
ListItemIcon,
Button,
useTheme
useTheme,
Select,
Stack,
ListItemText,
Divider
} from '@mui/material'
import { styled } from '@mui/styles'

Expand All @@ -42,6 +46,7 @@ import pkg from '../../../package.json'
import { Ledfx } from '../../api/ledfx'
import TourHome from '../Tours/TourHome'
import { backendUrl } from '../../pages/Device/Cloud/CloudComponents'
import { ledfxThemes } from '../../themes/AppThemes'

export const StyledBadge = styled(Badge)(() => ({
'& .MuiBadge-badge': {
Expand Down Expand Up @@ -81,6 +86,7 @@ const LeftButtons = (
color="inherit"
startIcon={<ChevronLeft />}
onClick={() => history(-1)}
sx={{ mt: .9 }}
>
Back
</Button>
Expand Down Expand Up @@ -121,7 +127,8 @@ const Title = (
pathname: string,
latestTag: string,
updateAvailable: boolean,
virtuals: any
virtuals: any,
frConfig: Record<string, any>
) => {
const newVerOnline =
latestTag.replace('v', '').includes('-b')
Expand All @@ -134,13 +141,13 @@ const Title = (
return (
<>
{`LedFx v${pkg.version}`}
{!process.env.MS_STORE && newVerOnline ? (
{!process.env.MS_STORE && newVerOnline && frConfig.updateUrl ? (
<Button
color="error"
variant="contained"
onClick={() =>
window.open(
'https://github.com/YeonV/LedFx-Builds/releases/latest'
frConfig.updateUrl
)
}
sx={{ ml: 2 }}
Expand Down Expand Up @@ -175,25 +182,28 @@ const Title = (
}

const TopBar = () => {
// const classes = useStyles();
// const classes = useStyles()
const navigate = useNavigate()
const theme = useTheme()
const [updateAvailable, setUpdateAvailable] = useState(false)

const [loggingIn, setLogginIn] = useState(false)

const open = useStore((state) => state.ui.bars && state.ui.bars?.leftBar.open)
const [frConfig, setFrConfig] = useState({ updateUrl: '' })
const latestTag = useStore((state) => state.ui.latestTag)
const currentTheme = useStore((state) => state.ui.currentTheme)
const setCurrentTheme = useStore((state) => state.ui.setCurrentTheme)
const setLatestTag = useStore((state) => state.ui.setLatestTag)
const setLeftBarOpen = useStore((state) => state.ui.setLeftBarOpen)
// const darkMode = useStore((state) => state.ui.darkMode);
// const setDarkMode = useStore((state) => state.ui.setDarkMode);
// const darkMode = useStore((state) => state.ui.darkMode)
// const setDarkMode = useStore((state) => state.ui.setDarkMode)
const virtuals = useStore((state) => state.virtuals)
const setDialogOpen = useStore((state) => state.setDialogOpen)
const setHostManager = useStore((state) => state.setHostManager)
const toggleGraphs = useStore((state) => state.toggleGraphs)
const graphs = useStore((state) => state.graphs)
// const config = useStore((state) => state.config);
// const config = useStore((state) => state.config)
const isLogged = useStore((state) => state.isLogged)
const setIsLogged = useStore((state) => state.setIsLogged)
const disconnected = useStore((state) => state.disconnected)
Expand Down Expand Up @@ -244,8 +254,8 @@ const TopBar = () => {
setAnchorEl(null)
}
// const toggleDarkMode = () => {
// setDarkMode(!darkMode);
// };
// setDarkMode(!darkMode)
// }

const changeGraphs = () => {
toggleGraphs()
Expand All @@ -263,6 +273,15 @@ const TopBar = () => {
localStorage.removeItem('ledfx-cloud-role')
setIsLogged(false)
}
useEffect(() => {
const fetchConfig = async () => {
const res = await fetch('/frontend_config.json')
const configData = await res.json()
setFrConfig(configData)
}

fetchConfig()
}, [])

useEffect(() => {
setIsLogged(!!localStorage.getItem('jwt'))
Expand Down Expand Up @@ -303,16 +322,15 @@ const TopBar = () => {
}, [updateNotificationInterval, getUpdateInfo, latestTag])

useEffect(() => {
const latest = async () => {
const res = await fetch(
'https://api.github.com/repos/YeonV/LedFx-Builds/releases/latest'
)
const resp = await res.json()
return resp.tag_name as string
if (frConfig.updateUrl) {
const latest = async () => {
const res = await fetch(frConfig.updateUrl);
const resp = await res.json();
return resp.tag_name as string;
};
latest().then((r) => r !== latestTag && setLatestTag(r));
}
latest().then((r) => r !== latestTag && setLatestTag(r))
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
}, [frConfig]);

useEffect(() => {
const handleDisconnect = (e: any) => {
Expand All @@ -335,6 +353,13 @@ const TopBar = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

useEffect(() => {
const t = window.localStorage.getItem('ledfx-theme')
if (t && t !== currentTheme) {
setCurrentTheme(t)
}
}, [])

return (
<>
{isElectron() && platform !== 'darwin' && (
Expand Down Expand Up @@ -380,7 +405,7 @@ const TopBar = () => {
{LeftButtons(pathname, history, open, handleLeftBarOpen)}
</div>
<Typography variant="h6" noWrap style={{ margin: '0 auto' }}>
{Title(pathname, latestTag, updateAvailable, virtuals)}
{Title(pathname, latestTag, updateAvailable, virtuals, frConfig)}
</Typography>
<div
style={{
Expand Down Expand Up @@ -556,6 +581,33 @@ const TopBar = () => {
{isLogged ? 'Logout' : 'Login with Github'}
</MenuItem>
)}
{localStorage.getItem('username') === 'YeonV' && <>
<Divider />
<Select
IconComponent={()=>null}
fullWidth
sx={{ pl: 2}}
disableUnderline
value={currentTheme} onChange={(e) => {
setCurrentTheme(e.target.value)
window.localStorage.setItem('ledfx-theme', e.target.value)
window.location.reload()
}}
>
{Object.keys(ledfxThemes).map((t) => (
<MenuItem key={t} value={t}>
<Stack direction={'row'}>
<ListItemIcon sx={{ alignItems: 'center', minWidth: 38}}>
<BladeIcon name={t.startsWith('Dark') ? 'DarkMode' : 'LightMode'} />
</ListItemIcon>
<ListItemText>
{t}
</ListItemText>
</Stack>
</MenuItem>
))}
</Select>
</>}
</Menu>
)}
</Toolbar>
Expand Down
7 changes: 5 additions & 2 deletions src/components/Tours/TourHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ const steps = [
const TourHome = ({
className = '',
cally,
variant = 'button'
variant = 'button',
sx
}: {
className?: string
variant?: string
cally?: any
sx?: any
}) => {
const theme = useTheme()
const tour = useStore((state) => state.tours.home)
Expand All @@ -126,7 +128,8 @@ const TourHome = ({
bgcolor: theme.palette.primary.main,
'&:hover': {
bgcolor: theme.palette.primary.light
}
},
...sx
}}
>
<LiveHelp />
Expand Down
20 changes: 12 additions & 8 deletions src/pages/Home/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ const Dashboard = () => {
<Stack spacing={2} direction="row">
<Tooltip title="Startup Assistant">
<Fab
aria-label="scan"
aria-label="intro"
onClick={() => {
setIntro(true)
}}
Expand All @@ -201,7 +201,7 @@ const Dashboard = () => {
height="auto"
src={fx}
alt="wled"
style={{ filter: 'grayscale(100%) brightness(0)' }}
style={{ filter: `grayscale(100%) brightness(0)${theme.palette.primary.contrastText === '#fff' ? ' invert(1)' : ''}` }}
/>
</Fab>
</Tooltip>
Expand Down Expand Up @@ -239,7 +239,7 @@ const Dashboard = () => {
{`${Math.round((scanning / 30) * 100)}%`}
</Typography>
) : (
<BladeIcon name="wled" />
<BladeIcon name="wled" sx={{ color: theme.palette.primary.contrastText}} />
)}
{scanning > -1 && (
<CircularProgress5
Expand Down Expand Up @@ -278,7 +278,7 @@ const Dashboard = () => {
height="auto"
src={openrgbLogo}
alt="wled"
style={{ filter: 'grayscale(100%) brightness(0)' }}
style={{ filter: `grayscale(100%) brightness(0)${theme.palette.primary.contrastText === '#fff' ? ' invert(1)' : ''}` }}
/>
</Fab>
</Tooltip>
Expand Down Expand Up @@ -307,6 +307,7 @@ const Dashboard = () => {
type="fab"
color="primary"
style={{ margin: '8px' }}
sx={{ color: theme.palette.primary.contrastText}}
icon={<DeleteForever />}
text="Delete frontend data?"
onConfirm={() => {
Expand Down Expand Up @@ -334,7 +335,7 @@ const Dashboard = () => {
</Tooltip> */}
<Tooltip title="Guided Tour">
<span style={{ margin: 0, zIndex: 0 }}>
<TourHome className="step-one" variant="fab" />
<TourHome className="step-one" variant="fab" sx={{ color: theme.palette.primary.contrastText}} />
</span>
</Tooltip>
</Stack>
Expand All @@ -354,7 +355,8 @@ const Dashboard = () => {
zIndex: 0
}}
sx={{
bgcolor: theme.palette.text.disabled,
color: theme.palette.primary.contrastText,
bgcolor: theme.palette.mode === 'dark' ? theme.palette.primary.dark : theme.palette.primary.light,
'&:hover': {
bgcolor: theme.palette.primary.main
}
Expand All @@ -378,7 +380,8 @@ const Dashboard = () => {
zIndex: 0
}}
sx={{
bgcolor: theme.palette.text.disabled,
color: theme.palette.primary.contrastText,
bgcolor: theme.palette.mode === 'dark' ? theme.palette.primary.dark : theme.palette.primary.light,
'&:hover': {
bgcolor: theme.palette.primary.main
}
Expand All @@ -402,7 +405,8 @@ const Dashboard = () => {
zIndex: 0
}}
sx={{
bgcolor: theme.palette.text.disabled,
fill: theme.palette.primary.contrastText,
bgcolor: theme.palette.mode === 'dark' ? theme.palette.primary.dark : theme.palette.primary.light,
'&:hover': {
bgcolor: theme.palette.primary.main
}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Home/Gauge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ export default function Gauge(props: any) {
>
<Typography
variant="h2"
color="secondary"
color="primary"
fontSize={`${size / 4}em`}
style={{ lineHeight: 1 }}
>
{current}
</Typography>
<Typography
variant="caption"
color="secondary"
color="GrayText"
fontSize={`${size / 12}em`}
style={{ lineHeight: 1 }}
>
Expand Down
9 changes: 9 additions & 0 deletions src/store/ui/storeUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import pkg from '../../../package.json'
import type { IStore } from '../useStore'

const storeUI = (set: any) => ({
currentTheme: '',
setCurrentTheme: (theme: string): void =>
set(
produce((state: IStore) => {
state.ui.currentTheme = theme
}),
false,
'ui/currentTheme'
),
effectDescriptions: 'Hide' as 'Auto' | 'Show' | 'Hide',
setEffectDescriptions: (mode: 'Auto' | 'Show' | 'Hide'): void =>
set(
Expand Down

0 comments on commit 0f5c9bd

Please sign in to comment.