Skip to content

Commit 5232065

Browse files
authored
Merge pull request #31 from hack4impact-upenn/edit-resource
Edit resource
2 parents 1f874e0 + 135b072 commit 5232065

23 files changed

+16855
-57654
lines changed

.vscode/settings.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

client/package-lock.json

Lines changed: 107 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"@mui/system": "^5.5.2",
3838
"@reduxjs/toolkit": "^1.8.1",
3939
"axios": "^1.1.2",
40+
"html-to-text": "^9.0.0",
4041
"jodit": "^3.23.1",
4142
"jodit-react": "^1.3.31",
4243
"prop-types": "^15.8.1",
@@ -55,6 +56,7 @@
5556
"@testing-library/jest-dom": "^5.14.1",
5657
"@testing-library/react": "^13.4.0",
5758
"@testing-library/user-event": "^14.4.3",
59+
"@types/html-to-text": "^8.1.1",
5860
"@types/jest": "^29.1.2",
5961
"@types/node": "^18.8.3",
6062
"@types/react": "^18.0.21",

client/src/AdminDashboard/DeleteQuestionButton.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { Navigate, useNavigate } from 'react-router-dom';
44
import { deleteQuestion } from './api'; // change to deleteQuestion
55
import LoadingButton from '../components/buttons/LoadingButton';
66
import ConfirmationModal from '../components/ConfirmationModal';
7+
import { IQuestion } from '../util/types/question';
78

89
interface DeleteQuestionButtonProps {
9-
isQuestion: boolean;
10-
text: string;
11-
removeRow: (question: string) => void;
10+
question: IQuestion;
11+
removeRow: (question: IQuestion) => void;
1212
}
1313

1414
/**
@@ -20,28 +20,27 @@ interface DeleteQuestionButtonProps {
2020
* function is called upon successfully deletion of user from the database.
2121
*/
2222
function DeleteQuestionButton({
23-
isQuestion,
24-
text,
23+
question,
2524
removeRow,
2625
}: DeleteQuestionButtonProps) {
2726
const navigate = useNavigate();
2827

2928
const [isLoading, setLoading] = useState(false);
3029
async function handleDelete() {
3130
setLoading(true);
32-
if (true) {
33-
// (await deleteQuestion(text)) {//if you comment this out it'll go to the login page but rn this never returns true bc theres no user created that it can delete
34-
removeRow(text);
31+
if (await deleteQuestion(question)) {
32+
// if you comment this out it'll go to the login page but rn this never returns true bc theres no user created that it can delete
33+
removeRow(question);
3534
// go to new page just to check button functionality
36-
navigate('/login');
35+
// navigate('/login');
3736
} else {
3837
setLoading(false);
3938
}
4039
}
4140
if (isLoading) {
4241
return <LoadingButton />;
4342
}
44-
if (isQuestion) {
43+
if (question.isQuestion) {
4544
// valid question
4645
return (
4746
<ConfirmationModal

client/src/AdminDashboard/EditQuestionButton.tsx

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import React, { useState } from 'react';
22
import Button from '@mui/material/Button';
3-
import { Navigate, useNavigate } from 'react-router-dom';
3+
import { Navigate, useNavigate, Link } from 'react-router-dom';
44
import { editQuestion } from './api';
55
import LoadingButton from '../components/buttons/LoadingButton';
66
import ConfirmationModal from '../components/ConfirmationModal';
7+
import { IQuestion } from '../util/types/question';
8+
import EditResource from '../components/EditResource';
9+
import EditQuestion from '../components/EditQuestion';
10+
import { IAnswer } from '../util/types/answer';
711

812
interface EditQuestionButtonProps {
913
qID: string;
1014
isQuestion: boolean;
1115
text: string;
16+
question: IQuestion;
1217
editRow: (qID: string, question: string, newText: string) => void;
1318
}
1419

@@ -24,28 +29,41 @@ function EditQuestionButton({
2429
qID,
2530
isQuestion,
2631
text,
32+
question,
2733
editRow,
2834
}: EditQuestionButtonProps) {
2935
const navigate = useNavigate();
3036

31-
const questionVals = {
32-
'63699fdbe0cca0b76f26576a': 'updated question text',
37+
const tempAnswer1: IAnswer = {
38+
_id: '6369a05ce0cca0b76f26576c',
39+
text: '2x edited answer text 1',
40+
resultantQuestionId: '63751d7cc26b48cf7f1d9724',
41+
resourceContent: '',
42+
resourceLink: '',
3343
};
34-
const answerVals = {
35-
'6369a04ee0cca0b76f26576b': 'lalalala',
36-
'6369a05ce0cca0b76f26576c': 'hehehehehe',
44+
const tempAnswer2: IAnswer = {
45+
_id: '6369a04ee0cca0b76f26576b',
46+
text: '2x edited answer text 2',
47+
resultantQuestionId: '63751d7cc26b48cf7f1d9724',
48+
resourceContent: '',
49+
resourceLink: '',
50+
};
51+
const tempQuestion: IQuestion = {
52+
_id: '63699fdbe0cca0b76f26576a',
53+
text: '2x edited question text',
54+
isQuestion: true,
55+
resultantAnswers: [tempAnswer1, tempAnswer2],
3756
};
3857

3958
const [isLoading, setLoading] = useState(false);
4059
async function handleEdit() {
4160
setLoading(true);
42-
// edit question needs to take in new text that user has typed in
43-
if (await editQuestion(questionVals, answerVals)) {
61+
// tempQuestion should be replaced with question prop. Question needs to have all correct edited values. Shouldn't this happen in EditorGUI?
62+
if (await editQuestion(tempQuestion)) {
4463
// navigate('/newquestion'); // go to create new question page
4564
// const newtext = newquestionpage.getData(); //this isnt real, but //click save in newquestion page; should return new text data
4665
// editRow(text, newtext); //basically just deletes the row for now
4766
// overwrite current row text
48-
console.log('hi');
4967
} else {
5068
setLoading(false);
5169
}
@@ -56,18 +74,28 @@ function EditQuestionButton({
5674
if (isQuestion) {
5775
// valid question
5876
return (
59-
<ConfirmationModal
60-
buttonText="Edit Question"
61-
title="Are you sure you want to edit this question?"
62-
body="This action is permanent. Question information will not be able to be recovered."
63-
onConfirm={() => handleEdit()}
64-
/>
77+
<div>
78+
<Link
79+
to="/editQuestion"
80+
state={{ question }}
81+
style={{ textDecoration: 'none' }}
82+
>
83+
<Button variant="outlined">Edit Question</Button>
84+
</Link>
85+
</div>
6586
);
6687
}
88+
6789
return (
68-
<Button variant="outlined" disabled>
69-
Question is Invalid
70-
</Button>
90+
<div>
91+
<Link
92+
to="/editResource"
93+
state={{ question }}
94+
style={{ textDecoration: 'none' }}
95+
>
96+
<Button variant="outlined">Edit Resource</Button>
97+
</Link>
98+
</div>
7199
);
72100
}
73101

0 commit comments

Comments
 (0)