Skip to content

Commit

Permalink
main functionalities with imported data
Browse files Browse the repository at this point in the history
  • Loading branch information
rosewang01 committed May 22, 2024
1 parent aa61b58 commit 1f874e0
Show file tree
Hide file tree
Showing 24 changed files with 173 additions and 369 deletions.
2 changes: 1 addition & 1 deletion client/src/AdminDashboard/AdminDashboardPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Typography, Grid } from '@mui/material';
import { Typography, Grid, AppBar } from '@mui/material';
import ScreenGrid from '../components/ScreenGrid';
// import UserTable from './QuestionTable';
import QuestionTable from './QuestionTable';
Expand Down
8 changes: 2 additions & 6 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,10 @@ function App() {
path="/reset-password/:token"
element={<ResetPasswordPage />}
/>
{/* <Route element={<AdminRoutesWrapper />}> */}
{/* <Route path="/users" element={<AdminDashboardPage />} /> */}
{/* </Route> */}
<Route path="/home" element={<HomePage />} />
<Route path="/question" element={<QuestionPage />} />
</Route>
{/* Routes accessed only if user is authenticated */}
{/* <Route element={<AdminRoutesWrapper />}> */}
<Route element={<ProtectedRoutesWrapper />}>
<Route
path="/admin-dashboard"
Expand All @@ -81,9 +79,7 @@ function App() {
/>
}
/>
<Route path="/home" element={<HomePage />} />
<Route path="/about" element={<AboutThisProjectPage />} />
<Route path="/question" element={<QuestionPage />} />

{/* Route which is accessed if no other route is matched */}
<Route path="*" element={<NotFoundPage />} />
Expand Down
6 changes: 3 additions & 3 deletions client/src/Authentication/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function LoginPage() {
<FormCol>
<Grid item container justifyContent="center">
<Typography variant="h2" textAlign="center">
Log In
Administrator Log In
</Typography>
</Grid>
<Grid item width="1">
Expand Down Expand Up @@ -177,11 +177,11 @@ function LoginPage() {
Forgot password?
</Link>
</Grid>
<Grid item>
{/* <Grid item>
<Link component={RouterLink} to="/register">
Sign up
</Link>
</Grid>
</Grid> */}
</FormRow>
</FormCol>
</FormGrid>
Expand Down
14 changes: 11 additions & 3 deletions client/src/Home/AboutThisProjectPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ function AboutThisProjectPage() {
direction="row"
justifyContent="space-between"
alignItems="flex-start"
height="100%"
height="100vh"
fit-content="100%"
>
<Grid item width="100%">
<NavBar />
</Grid>

<Grid item width="100%" padding={2} justifyContent="flex-start">
<Grid item width="100%" justifyContent="flex-start">
<Typography variant="h3" fontWeight="bold" textAlign="center">
Guide to Interpersonal Resources at Penn
</Typography>
Expand Down Expand Up @@ -130,7 +130,15 @@ function AboutThisProjectPage() {
</Box>
</Grid>
</Grid>
<Grid item width="100%" alignItems="flex-end" padding={0} spacing={0}>
<Grid
item
width="100%"
alignItems="flex-end"
padding={0}
spacing={0}
position="fixed"
bottom={0}
>
<Footer />
</Grid>
</Grid>
Expand Down
32 changes: 15 additions & 17 deletions client/src/Question/QuestionPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-underscore-dangle */
import React, { useEffect, useState } from 'react';
import { Box } from '@mui/material';
import { Box, CircularProgress } from '@mui/material';
import ScreenGrid from '../components/ScreenGrid';
import QuestionComponent from './QuestionComponent';
import ResourceComponent from './ResourceComponent';
Expand All @@ -10,7 +10,6 @@ import SidebarComponent from '../components/sidebar/SidebarComponent';
import BackButton from './Components/BackButton';
import NextButton from './Components/NextButton';
import StartOverButton from './Components/StartOverButton';
import PopupWarning from '../components/PopupWarning';

/**
* This page is the source of truth for all the state driven interactions of the question system.
Expand All @@ -21,18 +20,9 @@ import PopupWarning from '../components/PopupWarning';
* It also stores an array of "allQuestions" which will be used to handle to "back" functionality
*/
function QuestionPage() {
const initialQuestion = '637ea16cf9860ef25c72e639';
const [currentQuestion, setCurrentQuestion] = useState({
_id: 'Placeholder',
text: '',
isQuestion: true,
resultantAnswers: [],
} as IQuestion);

// const allQuestions: string[] = [initialQuestion];
const [currentQuestion, setCurrentQuestion] = useState({} as IQuestion);
const [questionIndex, setQuestionIndex] = useState(0);
const [allQuestions, setAllQuestions] = useState<string[]>([initialQuestion]);
// const [allAnswers, setAllAnswers] = useState<string[]>([]);
const [allQuestions, setAllQuestions] = useState<string[]>([]);

// Helper functions
const appendQuestion = (value: string) => {
Expand Down Expand Up @@ -109,10 +99,11 @@ function QuestionPage() {
};

useEffect(() => {
if (initialQuestion != null) {
getNextFromID(initialQuestion);
if (allQuestions.length === 0) {
getNextFromID('1');
appendQuestion('1');
}
}, [initialQuestion]);
}, [allQuestions]);

let leftButton = <div />;
if (questionIndex !== 0) {
Expand All @@ -132,6 +123,14 @@ function QuestionPage() {
rightButton = <StartOverButton />;
}

if (!currentQuestion.text) {
return (
<ScreenGrid>
<CircularProgress />
</ScreenGrid>
);
}

if (currentQuestion.isQuestion) {
return (
<ScreenGrid>
Expand Down Expand Up @@ -163,7 +162,6 @@ function QuestionPage() {
{rightButton}
</ScreenGrid>
);
// }
}

export default QuestionPage;
2 changes: 2 additions & 0 deletions client/src/Question/ResourceComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ function ResourceComponent(props: ResourceComponentProps) {
</Typography>
</Grid>
{question.resultantAnswers.map((answer) => {
console.log(answer.resourceContent);
return (
<Grid item margin="auto" marginTop="1%">
<ResourceDropdown
title={answer.text}
content={answer.resourceContent}
link={answer.resourceLink}
/>
</Grid>
);
Expand Down
21 changes: 0 additions & 21 deletions client/src/Question/ResourcePage.tsx

This file was deleted.

7 changes: 4 additions & 3 deletions client/src/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Box, Button, Stack } from '@mui/material';
import ArrowForward from '@mui/icons-material/ArrowForward';

export default function Footer() {
const params = window.location.pathname;
const isAbout = params === '/about';
return (
<div>
<Stack
Expand All @@ -21,14 +23,13 @@ export default function Footer() {
alt="Penn Logo"
src="https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/Shield_of_the_University_of_Pennsylvania.svg/1200px-Shield_of_the_University_of_Pennsylvania.svg.png"
/>

<Button
color="primary"
size="medium"
endIcon={<ArrowForward />}
href="/about"
href={isAbout ? '/question' : '/about'}
>
About This Project
{isAbout ? 'Ask a Question' : 'About This Project'}
</Button>
</Stack>
</div>
Expand Down
35 changes: 26 additions & 9 deletions client/src/components/ResourceDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useState } from 'react';
import Card from '@mui/material/Card';
import CardHeader from '@mui/material/CardHeader';
import CardContent from '@mui/material/CardContent';
import Container from '@mui/material/Container';
import IconButton from '@mui/material/IconButton';
import Collapse from '@mui/material/Collapse';
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';
Expand All @@ -12,12 +11,13 @@ import { Button, Grid, Typography } from '@mui/material';

interface ResourceDropdownProps {
title: string;
content: string;
content: string | undefined;
link: string | undefined;
}

export default function ResourceDropdown(props: ResourceDropdownProps) {
const [open, setOpen] = useState(false);
const { title, content } = props;
const { title, content, link } = props;
return (
<Card
sx={{
Expand Down Expand Up @@ -45,12 +45,29 @@ export default function ResourceDropdown(props: ResourceDropdownProps) {
<div style={{ backgroundColor: 'rgba(211,211,211,0.4)' }}>
<Collapse in={open} timeout="auto" unmountOnExit>
<CardContent>
<Typography>{content}</Typography>
<Grid container justifyContent="flex-end">
<Button variant="text" size="medium">
Learn More
</Button>
</Grid>
<Typography>{content || ''}</Typography>
{link ? (
<Grid container justifyContent="flex-end">
<Button
variant="text"
size="medium"
onClick={() => {
const newWindow = window.open(
link,
'_blank',
'noopener,noreferrer',
);
if (newWindow) {
newWindow.opener = null;
}
}}
>
Learn More
</Button>
</Grid>
) : (
<div />
)}
</CardContent>
</Collapse>
</div>
Expand Down
3 changes: 3 additions & 0 deletions client/src/components/sidebar/SidebarContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export default function SidebarContent(props: SidebarProps) {
<div>
<Toolbar />
<List>
<ListItem>
<h1>Definitions</h1>
</ListItem>
{definitions.map((definition) => (
<ListItem>
<SidebarContentItem
Expand Down
5 changes: 3 additions & 2 deletions client/src/util/types/answer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
export interface IAnswer {
_id: string;
text: string;
resourceContent: string;
resultantQuestionId: string;
resourceLink: string | undefined;
resourceContent: string | undefined;
resultantQuestionId: string | undefined;
}
7 changes: 3 additions & 4 deletions server/src/controllers/admin.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import express from 'express';
import ApiError from '../util/apiError';
import StatusCode from '../util/statusCode';
import { IUser } from '../models/user.model';
import IQuestion from '../models/question.model';
import { IQuestion } from '../models/question.model';
import {
upgradeUserToAdmin,
getUserByEmail,
Expand Down Expand Up @@ -135,8 +135,7 @@ const getAllQuestions = async (
};

/**
* Upgrade a user to an admin. The email of the user is expected to be in the request body.
* Upon success, return 200 OK status code.
* Edits the text of a question in the database. The new text is expected to be in the request body.
*/
const editQuestionText = async (
req: express.Request,
Expand All @@ -149,7 +148,7 @@ const editQuestionText = async (
return;
}

const qID = Object.keys(questionVals)[0];
const qID = parseInt(Object.keys(questionVals)[0], 10);

const question: IQuestion | null = await getQuestionById(qID);
if (!question) {
Expand Down
9 changes: 6 additions & 3 deletions server/src/controllers/question.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ const getNextQuestion = async (
next: express.NextFunction,
) => {
const { answerID } = req.params;
const id = parseInt(answerID, 10);
return (
getNextQuestionFromDB(answerID)
getNextQuestionFromDB(id)
.then((nextQuestion) => {
res.status(StatusCode.OK).send(nextQuestion);
// console.log('Next question', nextQuestion);
})
// eslint-disable-next-line @typescript-eslint/no-unused-vars
.catch((e) => {
console.log(e);
next(ApiError.internal('Unable to retrieve next question'));
})
);
Expand All @@ -31,14 +32,16 @@ const getQuestionWithID = async (
next: express.NextFunction,
) => {
const { questionID } = req.params;
const id = parseInt(questionID, 10);
return (
getQuestionById(questionID)
getQuestionById(id)
.then((nextQuestion) => {
// console.log(nextQuestion);
res.status(StatusCode.OK).send(nextQuestion);
})
// eslint-disable-next-line @typescript-eslint/no-unused-vars
.catch((e) => {
console.log(e);
next(ApiError.internal('Unable to retrieve next question'));
})
);
Expand Down
24 changes: 0 additions & 24 deletions server/src/controllers/resource.controller.ts

This file was deleted.

Loading

0 comments on commit 1f874e0

Please sign in to comment.