Skip to content

Commit

Permalink
feat: theme color changing when toggling sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
raaymax committed Oct 25, 2024
1 parent 4780c4a commit e21c883
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/src/js/components/layout/Main.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import styled from 'styled-components';
import styled, { useTheme } from 'styled-components';
import { useSelector } from '../../store';
import { cn, isMobile } from '../../utils';
import { useSidebar } from '../contexts/useSidebar';
import { SidebarProvider } from '../contexts/sidebar';
import { ButtonWithIcon } from '../molecules/ButtonWithIcon';
import { Logo, LogoPic } from '../atoms/Logo';
import { LogoPic } from '../atoms/Logo';
import { SizeProvider } from '../contexts/size';
import { ProfilePic } from '../atoms/ProfilePic';
import { NavChannels } from '../molecules/NavChannels';
Expand All @@ -13,6 +13,7 @@ import { NavButton } from '../molecules/NavButton';
import { logout } from '../../services/session';
import { useParams } from 'react-router-dom';
import { useThemeControl } from '../contexts/useThemeControl';
import { useEffect } from 'react';

export const Container = styled.div`
display: flex;
Expand Down Expand Up @@ -127,7 +128,6 @@ export const Container = styled.div`
`;

export const Sidebar = () => {
const { toggleSidebar } = useSidebar();
const themeControl = useThemeControl();
const otherTheme = themeControl.themeNames.find((name) => name !== themeControl.theme);
return (
Expand Down Expand Up @@ -182,6 +182,11 @@ export const Desktop = ({children}: {children: React.ReactNode}) => {
export const Mobile = ({children}: {children: React.ReactNode}) => {
const { sidebar } = useSidebar();
const { parentId } = useParams();
const theme = useTheme();
useEffect(() => {
document.querySelector('meta[name="theme-color"]')
?.setAttribute('content', sidebar ? theme.Navbar.Background : theme.Chatbox.Background);
}, [sidebar, theme]);
return (
<Container className={cn({
'side-stream': Boolean(parentId),
Expand Down
1 change: 1 addition & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e21c883

Please sign in to comment.