+ <>
+
+
+
>
)
}
diff --git a/frontend/src/components/ToggleMode/DarkModeContext.js b/frontend/src/components/ToggleMode/DarkModeContext.js
new file mode 100644
index 0000000..7ff181d
--- /dev/null
+++ b/frontend/src/components/ToggleMode/DarkModeContext.js
@@ -0,0 +1,30 @@
+import React, { createContext, useEffect, useState } from 'react';
+import {FaSun,FaMoon} from 'react-icons/fa6'
+export const DarkModeContext = createContext();
+
+export function DarkModeProvider({ children }) {
+ const [isDarkMode, setIsDarkMode] = useState(false);
+
+ useEffect(() => {
+ const savedMode = localStorage.getItem('mode') || 'light';
+ setIsDarkMode(savedMode === 'dark');
+ }, []);
+
+ const toggleMode = () => {
+ if (isDarkMode) {
+ setIsDarkMode(false);
+ localStorage.setItem('mode', 'light');
+ } else {
+ setIsDarkMode(true);
+ localStorage.setItem('mode', 'dark');
+ }
+ };
+
+ return (
+
+
+ {children}
+
+
+ );
+}
diff --git a/frontend/src/pages/Home.js b/frontend/src/pages/Home.js
index 2b7a65a..2c535b3 100644
--- a/frontend/src/pages/Home.js
+++ b/frontend/src/pages/Home.js
@@ -1,4 +1,4 @@
-import React, { useEffect } from 'react'
+import React, { useContext, useEffect } from 'react'
import NavBar from '../components/HomeComponents/NavBar'
import Description from '../components/HomeComponents/Description'
import Service from './Service'
@@ -6,8 +6,9 @@ import { useState } from 'react'
import LoadingPage from './LoadingPage'
import { useNavigate } from 'react-router-dom'
+import { DarkModeContext } from '../components/ToggleMode/DarkModeContext'
export default function Home() {
-
+ const {isDarkMode}=useContext(DarkModeContext)
const navigate=useNavigate();
const [isLoading,setIsLoading]=useState(true);
@@ -15,7 +16,7 @@ export default function Home() {
const checkIfLoggedIn=async()=>{
const cookie=localStorage.getItem('jwt');
- const response=await fetch(`${process.env.REACT_APP_API_URL}/api/v1/users/protect`,{
+ const response=await fetch(`${process.env.REACT_APP_API_URL}/api/v1/users/protect`,{
method:'post',
headers:{
'Content-type':'application/json',
@@ -39,7 +40,7 @@ export default function Home() {
return (
{isLoading&&
}
- {!isLoading&&(<>
+ {!isLoading&&(<>
diff --git a/frontend/src/pages/Service.js b/frontend/src/pages/Service.js
index 22f5b92..db065d7 100644
--- a/frontend/src/pages/Service.js
+++ b/frontend/src/pages/Service.js
@@ -1,12 +1,14 @@
-import React from 'react'
+import React, { useContext } from 'react'
import Card from '../components/HomeComponents/Card'
+import { DarkModeContext } from '../components/ToggleMode/DarkModeContext'
export default function Service() {
+ const {isDarkMode}=useContext(DarkModeContext)
return (
-
+
-
Get the best of all the features
+
Get the best of all the features