diff --git a/client/src/App.jsx b/client/src/App.jsx index 28fadcc..d4d47c7 100644 --- a/client/src/App.jsx +++ b/client/src/App.jsx @@ -1,5 +1,6 @@ import React from "react"; import { UserContextProvider } from "./Context/UserContext"; +import { ThemeProvider } from "./Context/ThemeContext"; import { Analytics } from "@vercel/analytics/react"; import { SpeedInsights } from "@vercel/speed-insights/react"; import { Routes, Route } from "react-router"; @@ -19,28 +20,33 @@ import MasterPage from "./MasterPage"; function App() { return ( - - - } /> - } /> - } /> - - }> - }/> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - - - - - + + + + } /> + } /> + } /> + + }> + } /> + } /> + } + /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + + + + + + ); } diff --git a/client/src/Context/ThemeContext.jsx b/client/src/Context/ThemeContext.jsx new file mode 100644 index 0000000..87ababa --- /dev/null +++ b/client/src/Context/ThemeContext.jsx @@ -0,0 +1,20 @@ +import React, { createContext, useState, useContext } from 'react'; + +const ThemeContext = createContext(); + +export const useTheme = () => useContext(ThemeContext); + +export const ThemeProvider = ({ children }) => { + const [isDarkMode, setIsDarkMode] = useState(false); + + const toggleTheme = () => { + setIsDarkMode(prevMode => !prevMode); + document.documentElement.classList.toggle('dark'); + }; + + return ( + + {children} + + ); +}; \ No newline at end of file diff --git a/client/src/Context/UserContext.jsx b/client/src/Context/UserContext.jsx index d8c8032..9f66ef0 100644 --- a/client/src/Context/UserContext.jsx +++ b/client/src/Context/UserContext.jsx @@ -1,7 +1,7 @@ import { createContext, useEffect, useState } from "react"; import axios from "axios"; import { Loader } from "../components/Loader/Loader"; -import { useNavigate } from "react-router-dom"; +import { useLocation, useNavigate } from "react-router-dom"; export const UserContext = createContext(); @@ -9,10 +9,11 @@ export const UserContextProvider = ({ children }) => { const [user, setUser] = useState(null); const navigate = useNavigate(); const [loading, setLoading] = useState(true); + const location = useLocation(); const token = localStorage.getItem("token"); - if (!token) { + if (!token && location.pathname !== "/signup") { navigate("/login"); } diff --git a/client/src/components/DocGrid/DocGrid.jsx b/client/src/components/DocGrid/DocGrid.jsx index d0e018a..6aed72f 100644 --- a/client/src/components/DocGrid/DocGrid.jsx +++ b/client/src/components/DocGrid/DocGrid.jsx @@ -40,7 +40,7 @@ const DocGrid = () => { const [searchInput, setSearchInput] = useState(""); const [activeTab, setActiveTab] = useState("All"); const { user, setUser, getUser } = useContext(UserContext); - const langKey=useSelector((store)=>store.config.lang) + const langKey = useSelector((store) => store.config.lang); console.log(user); @@ -126,12 +126,12 @@ const DocGrid = () => { if (notes.length == 0 && activeTab == "All") { return ( -
+
setSearchInput(e.target.value)} @@ -145,7 +145,7 @@ const DocGrid = () => { }} />
-

+

{lang[langKey].NoResultsFound}

@@ -164,262 +164,271 @@ const DocGrid = () => { } return ( - <> -
-
-
-
- setSearchInput(e.target.value)} - onKeyPress={(e) => { - if (e.key === "Enter") { - const searchTerm = e.target.value; - window.location.href = `?search=${encodeURIComponent( - searchTerm - )}`; - } - }} - /> - -
- - - -
-
-
{ - setActiveTab("All"); - }} - className={`flex-1 border-2 ${ - activeTab === "All" - ? "bg-indigo-600 text-white" - : "border-black" - } rounded-lg p-2 `} - > -

- {lang[langKey].AllNotes} -

-
-
{ - setActiveTab("BookMarked"); - }} - className={`flex-1 border-2 ${ - activeTab === "BookMarked" - ? "bg-indigo-600 text-white" - : "border-black" - } rounded-lg p-2 `} - > -

- {lang[langKey].BookMarkedNotes} -

-
-
- -

- {lang[langKey].FindYourNotesHere} + } + }} + /> + +

+ + + +
+
+
{ + setActiveTab("All"); + }} + className={`flex-1 border-2 ${ + activeTab === "All" + ? "bg-indigo-600 text-white" + : "border-black dark:border-white" + } rounded-lg p-2 `} + > +

+ {lang[langKey].AllNotes} +

+
+
{ + setActiveTab("BookMarked"); + }} + className={`flex-1 border-2 ${ + activeTab === "BookMarked" + ? "bg-indigo-600 text-white" + : "border-black dark:border-white" + } rounded-lg p-2 `} + > +

+ {lang[langKey].BookMarkedNotes}

+
+
-
- {notes.map((note, index) => ( -
handleNoteClick(note)} - > -
-
- -
-
-

-

{note.title}

-

-

- {note.subject.subjectName} -

-
-
- {note.likes > 0 ? ( -

- - {note.likes} -

- ) : ( -

- 0 -

- )} -
-
+

+ {lang[langKey].FindYourNotesHere} +

+ +
+ {notes.map((note, index) => ( +
handleNoteClick(note)} + > +
+
+ +
+
+

+

{note.title}

+

+

+ {note.subject.subjectName} +

+
+
+ {note.likes > 0 ? ( +

+ + {note.likes} +

+ ) : ( +

+ 0 +

+ )}
- ))} +
- - {activeTab !== "All" && notes.length === 0 ? ( -

- {lang[langKey].NoBookMarkedNotes} -

- ) : ( - "" - )} -
+ ))}
- - + + {activeTab !== "All" && notes.length === 0 ? ( +

+ {lang[langKey].NoBookMarkedNotes} +

+ ) : ( + "" + )} +
+
+ + + +
+ + +
+
-
- + +
+ -
-
- - -
- - -
-
- {note_.thumbnail} -
-
-
-

- {note_.title} -

-

- {lang[langKey].Productinformation} -

- -

- {lang[langKey].Subject}:{" "} - {note_.subject?.subjectName} -

+

+ {note_.title} +

+

+ {lang[langKey].Productinformation} +

-

- {lang[langKey].Description}:{" "} - {note_.description} -

+

+ + {lang[langKey].Subject}: + {" "} + {note_.subject?.subjectName} +

-

- {lang[langKey].Year}:{" "} - {note_.year} -

+

+ + {lang[langKey].Description}: + {" "} + {note_.description} +

-

- {lang[langKey].Course}:{" "} - {note_.course} -

+

+ + {lang[langKey].Year}: + {" "} + {note_.year} +

-

- {lang[langKey].Likes}:{" "} - {note_.likes} -

-
-
- -
-
- {user?.bookMarkedNotes?.includes(note_._id) ? ( - handleBookMark(note_._id)} - className="text-2xl cursor-pointer" - /> - ) : ( - handleBookMark(note_._id)} - className="text-2xl cursor-pointer" - /> - )} -
-
-
+

+ + {lang[langKey].Course}: + {" "} + {note_.course} +

-
-

- {lang[langKey].Productoptions} -

-

- Uploaded by {" "} - - @{note_.author?.username} - -

- - {lang[langKey].Download} - -
+

+ + {lang[langKey].Likes}: + {" "} + {note_.likes} +

+
+
+ +
+
+ {user?.bookMarkedNotes?.includes(note_._id) ? ( + handleBookMark(note_._id)} + className="text-2xl cursor-pointer" + /> + ) : ( + handleBookMark(note_._id)} + className="text-2xl cursor-pointer" + /> + )} +
-
+ + +
+

+ {lang[langKey].Productoptions} +

+

+ {lang[langKey].UploadedBy}{" "} + + @{note_.author?.username} + +

+ + {lang[langKey].Download} + +
- - -
-
-
-
- +
+ + + + + + + + + ); }; diff --git a/client/src/components/Footer/index.jsx b/client/src/components/Footer/index.jsx index eb550a3..01149a4 100644 --- a/client/src/components/Footer/index.jsx +++ b/client/src/components/Footer/index.jsx @@ -8,7 +8,7 @@ const Footer = () => { const langKey=useSelector((store)=>store.config.lang) return ( -