Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat-#12: Added Statistics Section on home page #236

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion client/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@ import RequestPage from "./components/RequestPage/RequestPage";
import VerifyOtp from "./components/OtpVerificationPage/verifyOtp";
import LeaderBoard from "./components/Leaderboard/LeaderBoard";
import Notifcation from "./components/NotifcationPage/Notifcation";
import Footer from "./components/Footer";
import Settings from "./components/Settings/Setting";
import Statistics from "./components/Statistics/Statistics";
import QuestionPage from "./components/QuestionPage/QuestionPage";
import QuestionNotifcation from "./components/QuestionPage/QuestionNotification";
import AnswerPage from "./components/QuestionPage/AnswerPage";
import MasterPage from "./MasterPage";


function App() {
return (
<UserContextProvider>
<Routes>
<Route path="/login" element={<Login />} />
<Route path="/signup" element={<Signup />} />
<Route path="/verifyOtp" element={<VerifyOtp />} />

<Route path="/statistics" element={<Statistics />} />
<Route path="/" element={<MasterPage/>}>
<Route index element={<Dashboard />}/>
<Route path="/notifications" element={<Notifcation />} />
Expand Down
9 changes: 8 additions & 1 deletion client/src/components/Navbar/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import axios from "axios";
import { useLocation, useNavigate } from "react-router";
import Login from "../Login/Login.jsx";
import { Link } from "react-router-dom";

import { IoIosStats } from "react-icons/io";
function classNames(...classes) {
return classes.filter(Boolean).join(" ");
}
Expand All @@ -19,13 +19,15 @@ const Navbar = () => {
const [requestNav, setRequestNav] = useState(false);
const [questionNav, setQuestionNav] = useState(false);
const [leaderBoardNav, setleaderBoardNav] = useState(false);
const [statisticsNav, setStatisticsNav] = useState(false);
const [searchInput, setSearchInput] = useState("");

const navigation = [
{ name: "Upload Notes", href: "/upload", current: uploadNav },
{ name: "Request Notes", href: "/request", current: requestNav },
{ name: "Ask a Question", href: "/question", current: questionNav },
{ name: "Leaderboard", href: "/leaderboard", current: leaderBoardNav },
{name : "Statistics", href: "/statistics", current:statisticsNav}
];
const navigate = useNavigate();

Expand Down Expand Up @@ -86,6 +88,11 @@ const Navbar = () => {
setRequestNav(false);
setUploadNav(false);
}
else if (loc === "/statistics"){
setStatisticsNav(true);
setRequestNav(false);
setUploadNav(false);
}
}, []);

return (
Expand Down
247 changes: 247 additions & 0 deletions client/src/components/Statistics/Statistics.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
Statistics.jsx

import React, { useContext, useState, useEffect, Fragment } from 'react'
import Navbar from '../Navbar/Navbar'
import { useNavigate } from "react-router";
import { UserContext } from "../../Context/UserContext";
import storage from "../../firebase/firebase";
import { Loader } from "../Loader/Loader";
import axios from "axios";

const Statistics = () => {
const { user, setUser } = useContext(UserContext);
const [subjects, setSubjects] = useState([]);
const [notes, setNotes] = useState([]);
const [users, setUsers] = useState([]);
const [loading, setLoading] = useState(true);
const [isSmallScreen, setIsSmallScreen] = useState(false);

useEffect(() => {
const handleResize = () => {
setIsSmallScreen(window.innerWidth < 768);
};

handleResize();

window.addEventListener("resize", handleResize);

return () => {
window.removeEventListener("resize", handleResize);
};
}, []);
useEffect(() => {
const fetchAllData = async () => {
try {
const fetchSubjects = async () => {
const token = localStorage.getItem("token");
const config = {
headers: {
Authorization: `Bearer ${token}`,
},
withCredentials: true,
};
const res = await axios.get(`${import.meta.env.VITE_BASE_URL}/subject`, config);
setSubjects(res.data);
};

const fetchNotes = async () => {
const token = localStorage.getItem("token");
const config = {
headers: {
Authorization: `Bearer ${token}`,
},
withCredentials: true,
};
const res = await axios.get(`${import.meta.env.VITE_BASE_URL}/note`, config);
setNotes(res.data);
};

const fetchUsers = async () => {
const response = await axios.get(`${import.meta.env.VITE_BASE_URL}/user/leaderboard`);
if (response.status === 200) {
setUsers(response.data);
console.log(response.data);
}
};

await Promise.all([fetchSubjects(), fetchNotes(), fetchUsers()]);
setLoading(false);
} catch (error) {
console.error("Error fetching data", error);
setLoading(false);
}
};

fetchAllData();
}, []);

return (
<div>
{loading ? (
<p><Loader/></p>
) : (
<div>
<Navbar />
<div style={{ ...styles.cardBox, ...(isSmallScreen ? smallScreenStyles.cardBox : {}) }}>
<div style= {styles.subject}>
<div style= {styles.card} >
<div style= {styles.rectangle} className="rectangle">
<img
src="https://icons.iconarchive.com/icons/jozef89/services-flat/512/design-icon.png"
alt="Avatar"
style= {styles.avatar}
className="avatar"
/>
<div style= {styles.pseudo} className="pseudo">
<b>Subjects</b>
<br />
<br />
<div style= {styles.cardExcerpt} className="card-excerpt">
<p>{subjects.length}</p>
</div>
</div>
</div>
</div>
</div>
<br />
<div style= {styles.student} className="student">
<div style= {styles.card} className="card">
<div style= {styles.rectangle} className="rectangle">
<img
src="https://cdn-icons-png.flaticon.com/512/3829/3829933.png"
alt="Avatar"
style= {styles.avatar}
className="avatar"
/>
<div style= {styles.pseudo} className="pseudo">
<b>Students</b>
<br />
<br/>
<div style= {styles.cardExcerpt} className="card-excerpt">
<p>{users.length}</p>
</div>
</div>
</div>
</div>
</div>
<br />
<div styles = {styles.notes} className="notes">
<div style= {styles.card} className="card">
<div style= {styles.rectangle} className="rectangle">
<img
src=" https://cdn-icons-png.flaticon.com/512/752/752326.png "
alt="Avatar"
style= {styles.avatar}
className="avatar"
/>
<div style= {styles.pseudo} className="pseudo">
<b>Notes</b>
<br />
<br />
<div style={styles.cardExcerpt} className="card-excerpt">
<p>{notes.length}</p>
</div>
</div>
</div>
</div>
</div>
</div>

</div>
)}

</div>
)
}

const smallScreenStyles = {
uidesign: {
flexDirection: "column",
},
};
const styles = {
cardBox: {
display: "flex",
flexWrap: "wrap",
justifyContent: "center",
},
subject: {
"> div": {
background: "#f5f7cd"
}
},

student: {
"> div": {
background: "#F0F4FF"
}
},
notes: {
"> div": {
background: "#EFF8FF"
}
},
card: {
flex: "1 1 300px",
boxShadow: "0 4px 8px 4px rgba(0, 0, 0, 0.4)",
borderRadius: "15px",
maxWidth: "300px",
margin: "20px 10px"
},
minicard: {
position: "relative",
bottom: "30px",
boxShadow: "0 4px 8px 0 rgba(0, 0, 0, 0.4)",
borderRadius: "15px",
paddingTop: "10px",
paddingRight: "20px",
paddingBottom: "10px",
paddingLeft: "20px",
maxWidth: "170px",
backgroundColor: "white",
margin: "auto",
textAlign: "center",
font: '17px "Fira Sans", sans-serif',
color: "grey"
},
rectangle: {
position: "relative",
width: "300px",
height: "350px",
background: "white"
},
rectangle2: {
display: "block",
textAlign: "center",
position: "relative",
width: "50px",
height: "50px",
background: "black"
},
avatar: {
position: "relative",
top: "30px",
borderRadius: "50%",
width: "120px",
height: "120px",
display: "block",
marginLeft: "auto",
marginRight: "auto",
marginBottom: "50px",
boxShadow: "0 4px 8px 0 rgba(0, 0, 0, 0.2)"
},
pseudo: {
position: "relative",
top: "10px",
textAlign: "center",
color: "#100B51",
fontSize: "25px",
fontFamily: '"Helvetica Neue", Roboto, "Segoe UI", Calibri, sans-serif'
},
cardExcerpt: {
font: '30px "Fira Sans", sans-serif',
color: "grey"
}
};

export default Statistics
22 changes: 21 additions & 1 deletion server/controllers/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,26 @@ const getLeaderBoard = async (req, res) => {
error: error.message,
});
}
};
}

const getUsers=async(req,res)=>{
try {
const users=await User.find().select('-password')
if(!users){
return res.status(404).json({
message:"No users found"
})
}
res.status(200).json(users)
} catch (error) {
res.status(500).json({
message:"Internal server error",
error:error.message
})
}
}



///forget password then verify password otp then update password
//user/forget-password
Expand Down Expand Up @@ -339,6 +358,7 @@ module.exports = {
verifyOtp,
getLeaderBoard,
sendOTPcon,
getUsers,
forgetPassword,
updatePassword,
vefifyPasswordOtp,
Expand Down