From 4a24755a7f02a0bf94b22f77ecf173bd82686c5a Mon Sep 17 00:00:00 2001 From: tejusk2 <92613406+tejusk2@users.noreply.github.com> Date: Thu, 18 Aug 2022 15:58:35 -0500 Subject: [PATCH 1/3] finished edit --- client/src/components/QAComponents/CreateAnswer.jsx | 2 +- client/src/components/QAComponents/Suggest.jsx | 13 +++++++------ .../FormControllers/EditQuestionFormController.js | 4 ++-- client/src/services/schemas.js | 6 +++++- server/routes/question/EditQuestionBody.js | 11 ++++++----- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/client/src/components/QAComponents/CreateAnswer.jsx b/client/src/components/QAComponents/CreateAnswer.jsx index fe8dc03..8479ff6 100644 --- a/client/src/components/QAComponents/CreateAnswer.jsx +++ b/client/src/components/QAComponents/CreateAnswer.jsx @@ -5,7 +5,7 @@ import { AnswerForm } from 'controllers/FormControllers'; export default function CreateAnswer({ canAnswer, show, toggleShow }) { return ( -
+
{ setCanSuggest(userData.level >= 7) - if(ongoingEdit.users.length > 0)setCanSuggest((userData.username !== ongoingEdit.users[0])) + if(!questionData.loading) setOngoingEdit({users : questionData.edit, new : questionData.editText}) },[userData, questionData, setCanSuggest]) async function toggleShow(){ - if(questionData.edit.length === 0){ + if(questionData.edit.length === 0 || userData.username !== ongoingEdit.users[0]){ setShow(!show) }else{ const { status } = await editQuestion(questionData.question_id); + window.location.reload(false); } } @@ -30,7 +31,7 @@ export default function Suggest(){ return ( -
+
0 && - - + New Title: + New Text: - {ongoingEdit.users} have voted to edit the question + {ongoingEdit.users} has voted to edit the question } diff --git a/client/src/controllers/FormControllers/EditQuestionFormController.js b/client/src/controllers/FormControllers/EditQuestionFormController.js index ca29d64..aec0831 100644 --- a/client/src/controllers/FormControllers/EditQuestionFormController.js +++ b/client/src/controllers/FormControllers/EditQuestionFormController.js @@ -2,7 +2,7 @@ import { Form } from 'controllers/FormControllers'; import { generateEditFields } from 'services/fields'; import { editQuestion } from 'services/questionsServices'; -import { questionSchema } from 'services/schemas'; +import { editSchema } from 'services/schemas'; import { useQuestion } from 'contexts'; export default function EditFormController() { @@ -22,7 +22,7 @@ export default function EditFormController() { return !questionData.loading && Form({ fields: field, onSubmit: editTheQuestion, - validationSchema: questionSchema, + validationSchema: editSchema, initialValues: {etext : text, etitle : title} }); } diff --git a/client/src/services/schemas.js b/client/src/services/schemas.js index 9f35a61..0e81f86 100644 --- a/client/src/services/schemas.js +++ b/client/src/services/schemas.js @@ -71,13 +71,16 @@ const questionSchema = Yup.object({ text: Yup.string() .max(3000, 'Body cannot be longer than 3000 characters') .required('A body is required'), +}); + +const editSchema = Yup.object({ etitle: Yup.string() .max(150, 'Title cannot be longer then 150 characters.') .required('A title is required.'), etext: Yup.string() .max(3000, 'Body cannot be longer than 3000 characters') .required('A body is required'), -}); +}) const patchSchema = Yup.object().shape( { @@ -117,4 +120,5 @@ export { registerSchema, resetSchema, searchSchema, + editSchema }; diff --git a/server/routes/question/EditQuestionBody.js b/server/routes/question/EditQuestionBody.js index 7a06cea..785df46 100644 --- a/server/routes/question/EditQuestionBody.js +++ b/server/routes/question/EditQuestionBody.js @@ -8,7 +8,7 @@ async function EditQuestionStatusClosed(req, res) { const { user } = req; const { question_id } = req.params; const { etext, etitle } = req.body; - + let eObj = [etext, etitle] // Verify user has required level if (getUserLevel(user.points) < 7) { return res.status(403).send(config.errorForbidden); @@ -25,7 +25,7 @@ async function EditQuestionStatusClosed(req, res) { } await Question.findByIdAndUpdate(question_id, { - editText: etext, + editText: eObj, $push: { edit: user.username }, }); @@ -48,13 +48,14 @@ async function EditQuestionStatusClosed(req, res) { if (question.edit.length === 2) { const question = await Question.findByIdAndUpdate(question_id, { edit: [], - etext, - etitle + eObj, + }); const { success } = await createRequest('patch', `/questions/${question_id}`, { etext, - etitle + eObj + }); return success From 0350ef8c0895bd90ea0a2b7befeb55162da03006 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cspicecat=E2=80=9D?= Date: Thu, 18 Aug 2022 17:02:02 -0400 Subject: [PATCH 2/3] fix search initalvalues --- client/src/components/ListQuestion.jsx | 6 ++++-- client/src/components/PaginatedList.jsx | 2 +- client/src/controllers/FormControllers/FormController.js | 8 ++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/client/src/components/ListQuestion.jsx b/client/src/components/ListQuestion.jsx index 9fbf637..3ae30a0 100644 --- a/client/src/components/ListQuestion.jsx +++ b/client/src/components/ListQuestion.jsx @@ -11,6 +11,7 @@ export default function ListQuestion({ creator, downvotes, status, + tags, text, title, upvotes, @@ -19,17 +20,18 @@ export default function ListQuestion({ }) { const sm = useMediaQuery((theme) => theme.breakpoints.only('sm')); const md = useMediaQuery((theme) => theme.breakpoints.only('md')); + console.log(123123, tags) return ( - {sm || md ? : null} + {sm || md ? : null} - {sm || md ? null: } + {sm || md ? null : } ))} {count > 1 && ( - + { setContent(''); - + }, [setContent]); const handleChange = (e) => { From 016f6b3ed2592fa43a80a2dc69e68bbbf53a0922 Mon Sep 17 00:00:00 2001 From: tejusk2 <92613406+tejusk2@users.noreply.github.com> Date: Thu, 18 Aug 2022 16:02:09 -0500 Subject: [PATCH 3/3] schema fix --- client/src/services/schemas.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/client/src/services/schemas.js b/client/src/services/schemas.js index d2be36a..9abbee0 100644 --- a/client/src/services/schemas.js +++ b/client/src/services/schemas.js @@ -107,6 +107,14 @@ const patchSchema = Yup.object().shape( ['password', 'password'], ] ); +const editSchema = Yup.object({ + etitle: Yup.string() + .max(150, 'Title cannot be longer then 150 characters.') + .required('A title is required.'), + etext: Yup.string() + .max(3000, 'Body cannot be longer than 3000 characters') + .required('A body is required') +}); export { answerSchema,