Skip to content

Commit

Permalink
feat(core): fixed typo and added useContext
Browse files Browse the repository at this point in the history
Signed-off-by: coder12git <[email protected]>
  • Loading branch information
coder12git committed Nov 7, 2023
1 parent bb15cc8 commit b29f6e0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
8 changes: 3 additions & 5 deletions site/src/components/Navigation/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from "react";
import React, {useContext} from "react";
import Search from '../../assets/images/Search.svg';
import SearchDark from "../../assets/images/SearchDark.svg";
import ThemeContext from "../Theme";
import Weather from '../../assets/images/Weather.svg';
import WeatherDark from '../../assets/images/WeatherDark.svg';

const Navbar = () => {
const theme = useContext(ThemeContext)

return (
<ThemeContext.Consumer>
{theme => (
<>
<div className=" w-[1440px] h-[100px] px-10 py-6 bg-background-default justify-between items-center inline-flex">
<div className="h-12 justify-center items-center gap-4 flex">
Expand Down Expand Up @@ -37,8 +37,6 @@ const Navbar = () => {
</div>
<hr className="border-border-default border-solid"/>
</>
)}
</ThemeContext.Consumer>
)
};

Expand Down
6 changes: 3 additions & 3 deletions site/src/components/Theme/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ function ThemeProvider({ children }) {

useEffect(() => {
// Getting dark mode value from localStorage!
const lsDark = JSON.parse(localStorage.getItem("dark"));
if (lsDark) {
setDark(lsDark);
const isDark = JSON.parse(localStorage.getItem("dark"));
if (isDark) {
setDark(isDark);
} else if (supportsDarkMode()) {
setDark(true);
}
Expand Down
7 changes: 2 additions & 5 deletions site/src/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from "react";
import React, {useContext} from "react";
import {
BrowserRouter as Router,
Route,
Expand All @@ -18,6 +18,7 @@ import '../styles/global.css';
import ThemeContext from "../components/Theme";

const IndexPage = () => {
const theme = useContext(ThemeContext);
const routes = (
<Routes>
<Route path="/" element={<Home />} exact />
Expand All @@ -33,8 +34,6 @@ const IndexPage = () => {
);

return (
<ThemeContext.Consumer>
{theme => (
<div className={`${theme.dark? 'dark' : 'light'} bg-background-default`} >
<Router>
<Navbar />
Expand All @@ -45,8 +44,6 @@ const IndexPage = () => {
<Footer />
</Router>
</div>
)}
</ThemeContext.Consumer>
);
}

Expand Down

0 comments on commit b29f6e0

Please sign in to comment.