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

Sophia/158 fixes #161

Open
wants to merge 4 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: 5 additions & 0 deletions server/mongodb/actions/Chapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import { ObjectId, PipelineStage, Promise } from "mongoose";
import Chapter from "../models/Chapter";
import User from "../models/User";

export const getChapters = async (): Promise<IChapter[] | null> => {
const chapters = await Chapter.find<IChapter>();
return chapters;
};

export const getChapterByName = async (
name: string,
): Promise<IChapter | null> => {
Expand Down
14 changes: 14 additions & 0 deletions src/app/api/chapter/get-chapters/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { getChapters } from "@server/mongodb/actions/Chapter";
import APIWrapper from "@server/utils/APIWrapper";

export const GET = APIWrapper({
config: {
requireToken: true,
requireAdmin: true,
},
handler: async () => {
const chapters = await getChapters();

return chapters;
},
});
38 changes: 34 additions & 4 deletions src/app/auth/information/page.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
"use client";

import React, { FormEvent, MouseEvent, useState } from "react";
import React, {
FormEvent,
MouseEvent,
useState,
useEffect,
useCallback,
} from "react";
import { Error as ErrorIcon } from "@mui/icons-material";
import ErrorOutlineIcon from "@mui/icons-material/ErrorOutline";
import { Country, State, City } from "country-state-city";
import { useRouter } from "next/navigation";
import LoadingBox from "@src/components/LoadingBox/LoadingBox";
import Modal from "@src/components/Modal/Modal";

import { IUser, HttpMethod, Role } from "@/common_utils/types";
import { IUser, HttpMethod, Role, IChapter } from "@/common_utils/types";

import InputField from "@src/components/InputField/InputField";
import { internalRequest } from "@src/utils/requests";
import AuthDropdown from "@src/components/Dropdown/AuthDropdown/AuthDropdown";
import { formatPhoneNumber } from "@src/utils/utils";

import CHAPTERS from "@src/utils/chapters";
import { DropdownOption } from "@src/components/Dropdown/Dropdown";
import styles from "./page.module.css";

export default function Page() {
Expand All @@ -38,6 +44,8 @@ export default function Page() {
const [chapterError, setChapterError] = useState("");
const [showGeneralError, setShowGeneralError] = useState(false);

const [chapters, setChapters] = useState<DropdownOption<string>[]>([]);

const [loading, setLoading] = useState(false);

const router = useRouter();
Expand Down Expand Up @@ -155,6 +163,28 @@ export default function Page() {
}
};

const loadChapters = useCallback(() => {
setLoading(true);
internalRequest<IChapter[] | null>({
url: "/api/chapter/get-chapters",
method: HttpMethod.GET,
body: {},
}).then((res) => {
const chapterDropdown = res
? res.map((chapterVal) => ({
value: chapterVal.name,
displayValue: chapterVal.name,
}))
: [];
setChapters(chapterDropdown);
setLoading(false);
});
}, []);

useEffect(() => {
loadChapters();
}, [loadChapters]);

return (
<div>
<title>Personal Information | Brain Exercise Initiative</title>
Expand Down Expand Up @@ -285,7 +315,7 @@ export default function Page() {
title="Chapter"
required={true}
placeholder="Select Your Chaper"
options={CHAPTERS}
options={chapters}
value={chapter}
onChange={(e) => {
setChapter(e.target.value);
Expand Down
10 changes: 5 additions & 5 deletions src/components/Dashboard/MathScreen/MathScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const MathScreen = ({
title="Average Math Accuracy"
hoverable={true}
percentageChange={true}
info="Vidushi"
info="Number correct on first attempt divided by total"
data={accuracyData}
fullWidth
yLabel=""
Expand All @@ -76,23 +76,23 @@ const MathScreen = ({
title="Average Math Difficulty"
hoverable={true}
percentageChange={true}
info="Vidushi"
info=""
data={difficultyData}
fullWidth
gridLines
/>
<BarChart
width={325}
height={175}
title="Average Questions Answered per Session sdsdsdsdshdajsdhj asj djas dhj "
title="Average Questions Answered per Session"
data={numQuestionData}
hoverable
percentageChange
yLabel=""
// yLabel="Questions"
fullWidth
gridLines
info="test"
info=""
/>
<BarChart
width={325}
Expand All @@ -103,7 +103,7 @@ const MathScreen = ({
percentageChange
fullWidth
gridLines
info="Test"
info="In seconds"
/>
</div>
<div className={styles.textStatsWithHeader}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
font-size: 29.705px;
font-style: normal;
}

.infoBox {
font-family: var(--font-poppins);
font-size: 12px;
font-style: normal;
}
}

.bottomContainer {
Expand Down
49 changes: 47 additions & 2 deletions src/components/Dashboard/OverallDashboard/OverallDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import {
QuestionIcon as QI,
BarChartIcon,
} from "@src/app/icons";
import { CSSProperties } from "react";
import { CSSProperties, useState, useRef, useEffect } from "react";
import { DateRangeEnum, Days } from "@/common_utils/types";
import { D3Data } from "@src/utils/types";
import Chip from "@src/components/Chip/Chip";
import ActiveIndicatorBox from "@src/components/ActiveIndicatorBox/ActiveIndicatorBox";
import DateSelector from "@src/components/DateSelector/DateSelector";
import PopupModal from "@src/components/Graphs/PopupModal/PopupModal";
import { BarChart, SmallDataBox, WeeklyProgress } from "../../Graphs";
import styles from "./OverallDashboard.module.scss";

Expand Down Expand Up @@ -54,6 +55,26 @@ function formatDate(date: Date) {
}

export default function OverallDashboard(params: Params) {
const [infoPopup, setInfoPopup] = useState(false);
const infoButtonRef = useRef(null);
const [popupX, setPopupX] = useState<number | null>(null);
const [popupY, setPopupY] = useState<number | null>(null);

useEffect(() => {
const onScroll = () => setInfoPopup(false);
// clean up code
window.removeEventListener("scroll", onScroll);
window.addEventListener("scroll", onScroll, { passive: true });

if (infoButtonRef.current) {
const rect: Element = infoButtonRef.current;
const newTop = rect.getBoundingClientRect().y + 30;
setPopupY(newTop);
const left = rect.getBoundingClientRect().x;
setPopupX(left);
}
}, [setPopupX, setPopupY, setInfoPopup]);

return (
<div className={styles.OverallDashboard} style={params.style}>
<div className={styles.titleRow}>
Expand All @@ -74,7 +95,31 @@ export default function OverallDashboard(params: Params) {
active={params.active}
style={{ marginLeft: "17px", marginRight: "10px" }}
/>
<IGI />
<div
className={styles.infoBox}
onMouseEnter={() => {
setInfoPopup(true);
}}
onMouseLeave={() => {
setInfoPopup(false);
}}
ref={infoButtonRef}
style={{ position: "relative" }}
>
<IGI />
<PopupModal
show={infoPopup}
info={
"Active means a user has completed at least two sessions each week for the past two weeks."
}
style={{
position: "fixed",
top: `${popupY}px`,
zIndex: 500,
left: `${popupX}px`,
}}
/>
</div>
<div className={styles.dateSelector}>
<DateSelector
selectedValue={params.menuState[0]}
Expand Down
6 changes: 3 additions & 3 deletions src/components/Dashboard/ReadingScreen/ReadingScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ export default function ReadingScreen({
<LineChart
width={325}
height={185}
title="Average Reading Rate (Words/Min)"
title="Average Reading Rate"
hoverable={true}
percentageChange={true}
info="Vidushi"
info="Words/Min"
data={readingRate}
fullWidth
gridLines
Expand All @@ -113,7 +113,7 @@ export default function ReadingScreen({
percentageChange
fullWidth
gridLines
info="Hey this is just some info I thought you will find interesting."
info="In seconds"
/>
</div>
<div className={styles.textStats}>
Expand Down
3 changes: 2 additions & 1 deletion src/components/Dashboard/TriviaScreen/TriviaScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default function TriviaScreen({
title="Average Trivia Accuracy"
hoverable={true}
percentageChange={true}
info="Vidushi"
info="Number of self-reported correct answers"
data={accuracyData}
fullWidth
gridLines
Expand All @@ -80,6 +80,7 @@ export default function TriviaScreen({
width={325}
height={175}
title="Average Time Spent per Question"
info="In seconds"
data={timeData}
hoverable
percentageChange
Expand Down
4 changes: 1 addition & 3 deletions src/components/Dashboard/WritingScreen/WritingScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export default function WritingScreen({
// { text: "sessions completed without writing", color: "#FF9FB3" },
// { text: "sessions completed with writing", color: "#008AFC" },
// ]}
info="Some really extremely interesting information about stacked bar chart."
hoverable
percentageChange
fullWidth
Expand All @@ -76,14 +75,13 @@ export default function WritingScreen({
percentageChange
fullWidth
gridLines
info="Some info for testing purposes in bar chart"
/>
<BarChart
width={325}
height={185}
title="Average Time Spent Per Prompt"
data={avgTime}
info="Some info for testing purposes in bar chart"
info="In seconds"
hoverable
percentageChange
fullWidth
Expand Down
2 changes: 2 additions & 0 deletions src/components/DateSelector/DateSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function DateSelector({
border: "none",
width: "130px",
textAlign: "center",
backgroundColor: "white",
}}
sx={{
"&.MuiOutlinedInput-root": {
Expand All @@ -48,6 +49,7 @@ function DateSelector({
fontSize: "12px",
fontFamily: poppins500.style.fontFamily,
}}
defaultBackgroundColor="#ffffff"
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const GroupMathScreen = ({
title="Average Math Accuracy"
hoverable={true}
percentageChange={true}
info="Vidushi"
info="Number correct on first attempt divided by total"
data={accuracyData}
fullWidth
gridLines
Expand All @@ -76,7 +76,7 @@ const GroupMathScreen = ({
title="Average Math Difficulty"
hoverable={true}
percentageChange={true}
info="Vidushi"
info=""
data={difficultyData}
fullWidth
gridLines
Expand All @@ -96,6 +96,7 @@ const GroupMathScreen = ({
width={325}
height={175}
title="Average Time Spent per Question"
info="In seconds"
data={timeData}
hoverable
percentageChange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ export default function GroupReadingScreen({
<LineChart
width={325}
height={185}
title="Average Reading Rate (Words/Min)"
title="Average Reading Rate"
hoverable={true}
percentageChange={true}
info="Vidushi"
info="Words/Min"
data={readingRate}
fullWidth
gridLines
Expand All @@ -97,7 +97,7 @@ export default function GroupReadingScreen({
percentageChange
fullWidth
gridLines
info="Hey this is just some info I thought you will find interesting."
info="In seconds"
/>
</div>
<div className={styles.textStats}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default function GroupTriviaScreen({
title="Average Trivia Accuracy"
hoverable={true}
percentageChange={true}
info="Vidushi"
info="Number of self-reported correct answers"
data={accuracyData}
fullWidth
gridLines
Expand All @@ -81,6 +81,7 @@ export default function GroupTriviaScreen({
width={325}
height={175}
title="Average Time Spent per Question"
info="In seconds"
data={timeData}
hoverable
percentageChange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,13 @@ export default function GroupWritingScreen({
percentageChange
fullWidth
gridLines
info="Some info for testing purposes in bar chart"
/>
<BarChart
width={325}
height={185}
title="Average Time Spent Per Prompt"
data={avgTimeData}
info="Some info for testing purposes in bar chart"
info="In seconds"
hoverable
percentageChange
fullWidth
Expand Down
Loading
Loading