From dea385384a06832fa36a64d6c940d035d1b8ed3b Mon Sep 17 00:00:00 2001 From: ManishMadan2882 Date: Thu, 1 Feb 2024 03:43:05 +0530 Subject: [PATCH] fixes, update Nav images on theme toggle --- frontend/src/App.tsx | 9 ---- frontend/src/Hero.tsx | 5 +-- frontend/src/Navigation.tsx | 42 +++++++++++-------- frontend/src/Setting.tsx | 21 ++++------ frontend/src/conversation/Conversation.tsx | 3 +- .../src/conversation/ConversationTile.tsx | 4 +- 6 files changed, 39 insertions(+), 45 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 27eda07d..de75c73e 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -13,15 +13,6 @@ inject(); export default function App() { const { isMobile } = useMediaQuery(); const [navOpen, setNavOpen] = useState(!isMobile); - const selectedTheme = localStorage.getItem('selectedTheme'); - useEffect(()=>{ - if (selectedTheme === 'Dark') { - document.documentElement.classList.add('dark'); - document.body.classList.add('dark:bg-raisin-black'); - } else { - document.documentElement.classList.remove('dark'); - } - },[]) return (
diff --git a/frontend/src/Hero.tsx b/frontend/src/Hero.tsx index 5eb9a11b..1f0b94ca 100644 --- a/frontend/src/Hero.tsx +++ b/frontend/src/Hero.tsx @@ -1,11 +1,10 @@ -import { useMediaQuery } from './hooks'; +import { useDarkTheme, useMediaQuery } from './hooks'; import DocsGPT3 from './assets/cute_docsgpt3.svg'; export default function Hero({ className = '' }: { className?: string }) { // const isMobile = window.innerWidth <= 768; const { isMobile } = useMediaQuery(); - const isDarkTheme = document.documentElement.classList.contains('dark'); - console.log(isDarkTheme) + const [isDarkTheme] = useDarkTheme() return (
diff --git a/frontend/src/Navigation.tsx b/frontend/src/Navigation.tsx index e954a55f..c85b87bd 100644 --- a/frontend/src/Navigation.tsx +++ b/frontend/src/Navigation.tsx @@ -41,12 +41,28 @@ import Upload from './upload/Upload'; import { Doc, getConversations } from './preferences/preferenceApi'; import SelectDocsModal from './preferences/SelectDocsModal'; import ConversationTile from './conversation/ConversationTile'; +import { useDarkTheme } from './hooks'; interface NavigationProps { navOpen: boolean; setNavOpen: React.Dispatch>; } - +const NavImage: React.FC<{ Light: string, Dark: string }> = ({ Light, Dark }) => { + return ( + <> + icon + icon + + ) +} export default function Navigation({ navOpen, setNavOpen }: NavigationProps) { const dispatch = useDispatch(); const docs = useSelector(selectSourceDocs); @@ -54,7 +70,7 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) { const conversations = useSelector(selectConversations); const conversationId = useSelector(selectConversationId); const { isMobile } = useMediaQuery(); - const isDarkTheme = document.documentElement.classList.contains('dark'); + const [isDarkTheme] = useDarkTheme(); const [isDocsListOpen, setIsDocsListOpen] = useState(false); const isApiKeySet = useSelector(selectApiKeyStatus); @@ -176,7 +192,6 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) { useEffect(() => { setNavOpen(!isMobile); }, [isMobile]); - return ( <> {!navOpen && ( @@ -340,11 +355,7 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) { }` } > - settings +

Settings

@@ -357,7 +368,7 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) { }` } > - info +

About

@@ -367,11 +378,7 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) { rel="noreferrer" className="my-auto mx-4 flex h-9 cursor-pointer gap-4 rounded-3xl hover:bg-gray-100 dark:hover:bg-purple-taupe" > - documentation +

Documentation

- discord-link + + {/* discord-link */}

Visit our Discord

@@ -392,7 +400,7 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) { rel="noreferrer" className="mt-auto mx-4 flex h-9 cursor-pointer gap-4 rounded-3xl hover:bg-gray-100 dark:hover:bg-purple-taupe" > - github-link +

Visit our Github

@@ -405,7 +413,7 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) { className="mt-5 ml-6 h-6 w-6 md:hidden" onClick={() => setNavOpen(true)} > - menu toggle + menu toggle
{ const General: React.FC = () => { const themes = ['Light', 'Dark']; const languages = ['English']; - const [selectedTheme, setSelectedTheme] = useState(localStorage.getItem('selectedTheme') || themes[0]); + const [isDarkTheme, toggleTheme] = useDarkTheme(); + const [selectedTheme, setSelectedTheme] = useState(isDarkTheme ? 'Dark' : 'Light'); const [selectedLanguage, setSelectedLanguage] = useState(languages[0]); - - useEffect(() => { - if (selectedTheme === 'Dark') { - document.documentElement.classList.add('dark'); - document.documentElement.classList.add('dark:bg-raisin-black'); - } else { - document.documentElement.classList.remove('dark'); - } - localStorage.setItem('selectedTheme', selectedTheme); - }, [selectedTheme]); - return (
@@ -207,7 +199,10 @@ const General: React.FC = () => { { + setSelectedTheme(option); + option !==selectedTheme && toggleTheme(); + }} />
diff --git a/frontend/src/conversation/Conversation.tsx b/frontend/src/conversation/Conversation.tsx index 17a9468c..b541c873 100644 --- a/frontend/src/conversation/Conversation.tsx +++ b/frontend/src/conversation/Conversation.tsx @@ -1,5 +1,6 @@ import { Fragment, useEffect, useRef, useState } from 'react'; import { useDispatch, useSelector } from 'react-redux'; +import { useDarkTheme } from '../hooks'; import Hero from '../Hero'; import { AppDispatch } from '../store'; import ConversationBubble from './ConversationBubble'; @@ -23,7 +24,7 @@ export default function Conversation() { const dispatch = useDispatch(); const endMessageRef = useRef(null); const inputRef = useRef(null); - const isDarkTheme = document.documentElement.classList.contains('dark'); + const [isDarkTheme]= useDarkTheme(); const [hasScrolledToLast, setHasScrolledToLast] = useState(true); useEffect(() => { diff --git a/frontend/src/conversation/ConversationTile.tsx b/frontend/src/conversation/ConversationTile.tsx index ce37d160..60153457 100644 --- a/frontend/src/conversation/ConversationTile.tsx +++ b/frontend/src/conversation/ConversationTile.tsx @@ -4,7 +4,7 @@ import Edit from '../assets/edit.svg'; import Exit from '../assets/exit.svg'; import Message from '../assets/message.svg'; import MessageDark from '../assets/message-dark.svg'; - +import { useDarkTheme } from '../hooks'; import CheckMark2 from '../assets/checkMark2.svg'; import Trash from '../assets/trash.svg'; @@ -29,7 +29,7 @@ export default function ConversationTile({ }: ConversationTileProps) { const conversationId = useSelector(selectConversationId); const tileRef = useRef(null); - const isDarkTheme = document.documentElement.classList.contains('dark'); + const [isDarkTheme]= useDarkTheme(); const [isEdit, setIsEdit] = useState(false); const [conversationName, setConversationsName] = useState(''); // useOutsideAlerter(