Merge branch 'dev' of https://github.com/spicecat/qOverflow into dev
This commit is contained in:
commit
9e4a0ffa8a
8 changed files with 34 additions and 21 deletions
|
|
@ -11,6 +11,7 @@ export default function ListQuestion({
|
||||||
creator,
|
creator,
|
||||||
downvotes,
|
downvotes,
|
||||||
status,
|
status,
|
||||||
|
tags,
|
||||||
text,
|
text,
|
||||||
title,
|
title,
|
||||||
upvotes,
|
upvotes,
|
||||||
|
|
@ -19,17 +20,18 @@ export default function ListQuestion({
|
||||||
}) {
|
}) {
|
||||||
const sm = useMediaQuery((theme) => theme.breakpoints.only('sm'));
|
const sm = useMediaQuery((theme) => theme.breakpoints.only('sm'));
|
||||||
const md = useMediaQuery((theme) => theme.breakpoints.only('md'));
|
const md = useMediaQuery((theme) => theme.breakpoints.only('md'));
|
||||||
|
console.log(123123, tags)
|
||||||
return (
|
return (
|
||||||
<span key={question_id}>
|
<span key={question_id}>
|
||||||
<ListItem disablePadding>
|
<ListItem disablePadding>
|
||||||
<Grid container>
|
<Grid container>
|
||||||
<Grid item xs={2}>
|
<Grid item xs={2}>
|
||||||
<Stack justifyContent='center' sx={{ height: '100%' }}>
|
<Stack justifyContent='center' sx={{ height: '100%' }}>
|
||||||
{sm || md ? <ListQuestionInfo {...{upvotes, downvotes, answers, views, inline: false}}/> : null}
|
{sm || md ? <ListQuestionInfo {...{ upvotes, downvotes, answers, views, inline: false }} /> : null}
|
||||||
</Stack>
|
</Stack>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item xs={10}>
|
<Grid item xs={10}>
|
||||||
{sm || md ? null: <ListQuestionInfo {...{upvotes, downvotes, answers, views, inline: true}}/>}
|
{sm || md ? null : <ListQuestionInfo {...{ upvotes, downvotes, answers, views, inline: true }} />}
|
||||||
<CreationInfoTag {...{ createdAt, creator }} />
|
<CreationInfoTag {...{ createdAt, creator }} />
|
||||||
<Typography
|
<Typography
|
||||||
variant='h6'
|
variant='h6'
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ export default function PaginatedList({ count, Component, data, handleChangePage
|
||||||
<Component {...item} key={index} />
|
<Component {...item} key={index} />
|
||||||
))}
|
))}
|
||||||
{count > 1 && (
|
{count > 1 && (
|
||||||
<Box fullWidth display='flex' justifyContent='center' sx={{ margin: '1vh 0' }}>
|
<Box display='flex' justifyContent='center' sx={{ margin: '1vh 0' }}>
|
||||||
<Pagination
|
<Pagination
|
||||||
count={count}
|
count={count}
|
||||||
onChange={handleChangePage}
|
onChange={handleChangePage}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import { AnswerForm } from 'controllers/FormControllers';
|
||||||
|
|
||||||
export default function CreateAnswer({ canAnswer, show, toggleShow }) {
|
export default function CreateAnswer({ canAnswer, show, toggleShow }) {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div style = {{display : 'inline'}}>
|
||||||
<Tooltip
|
<Tooltip
|
||||||
title={
|
title={
|
||||||
canAnswer
|
canAnswer
|
||||||
|
|
|
||||||
|
|
@ -14,15 +14,16 @@ export default function Suggest(){
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
setCanSuggest(userData.level >= 7)
|
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})
|
if(!questionData.loading) setOngoingEdit({users : questionData.edit, new : questionData.editText})
|
||||||
},[userData, questionData, setCanSuggest])
|
},[userData, questionData, setCanSuggest])
|
||||||
|
|
||||||
async function toggleShow(){
|
async function toggleShow(){
|
||||||
if(questionData.edit.length === 0){
|
if(questionData.edit.length === 0 || userData.username !== ongoingEdit.users[0]){
|
||||||
setShow(!show)
|
setShow(!show)
|
||||||
}else{
|
}else{
|
||||||
const { status } = await editQuestion(questionData.question_id);
|
const { status } = await editQuestion(questionData.question_id);
|
||||||
|
window.location.reload(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -30,7 +31,7 @@ export default function Suggest(){
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div style = {{display : 'inline', marginLeft : '10px'}}>
|
||||||
<Tooltip
|
<Tooltip
|
||||||
title= {
|
title= {
|
||||||
canSuggest
|
canSuggest
|
||||||
|
|
@ -53,10 +54,10 @@ export default function Suggest(){
|
||||||
{ongoingEdit.users.length > 0 &&
|
{ongoingEdit.users.length > 0 &&
|
||||||
<Card>
|
<Card>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<Markdown {...{content: ongoingEdit.new[0]}}/>
|
New Title: <Markdown {...{content: ongoingEdit.new[1]}}/>
|
||||||
<Markdown {...{content: ongoingEdit.new[1]}}/>
|
New Text: <Markdown {...{content: ongoingEdit.new[0]}}/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
<Typography> {ongoingEdit.users} have voted to edit the question </Typography>
|
<Typography> {ongoingEdit.users} has voted to edit the question </Typography>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
import { Form } from 'controllers/FormControllers';
|
import { Form } from 'controllers/FormControllers';
|
||||||
import { generateEditFields } from 'services/fields';
|
import { generateEditFields } from 'services/fields';
|
||||||
import { editQuestion } from 'services/questionsServices';
|
import { editQuestion } from 'services/questionsServices';
|
||||||
import { questionSchema } from 'services/schemas';
|
import { editSchema } from 'services/schemas';
|
||||||
import { useQuestion } from 'contexts';
|
import { useQuestion } from 'contexts';
|
||||||
|
|
||||||
export default function EditFormController() {
|
export default function EditFormController() {
|
||||||
|
|
@ -22,7 +22,7 @@ export default function EditFormController() {
|
||||||
return !questionData.loading && Form({
|
return !questionData.loading && Form({
|
||||||
fields: field,
|
fields: field,
|
||||||
onSubmit: editTheQuestion,
|
onSubmit: editTheQuestion,
|
||||||
validationSchema: questionSchema,
|
validationSchema: editSchema,
|
||||||
initialValues: {etext : text, etitle : title}
|
initialValues: {etext : text, etitle : title}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,15 +10,15 @@ export default function FormController({
|
||||||
validate,
|
validate,
|
||||||
validationSchema,
|
validationSchema,
|
||||||
children,
|
children,
|
||||||
initialValues
|
initialValues = {}
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
|
|
||||||
const { setContent } = useForm();
|
const { setContent } = useForm();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setContent('');
|
setContent('');
|
||||||
|
|
||||||
}, [setContent]);
|
}, [setContent]);
|
||||||
|
|
||||||
const handleChange = (e) => {
|
const handleChange = (e) => {
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,14 @@ const patchSchema = Yup.object().shape(
|
||||||
['password', 'password'],
|
['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 {
|
export {
|
||||||
answerSchema,
|
answerSchema,
|
||||||
|
|
@ -119,4 +127,5 @@ export {
|
||||||
registerSchema,
|
registerSchema,
|
||||||
resetSchema,
|
resetSchema,
|
||||||
searchSchema,
|
searchSchema,
|
||||||
|
editSchema
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ async function EditQuestionStatusClosed(req, res) {
|
||||||
const { user } = req;
|
const { user } = req;
|
||||||
const { question_id } = req.params;
|
const { question_id } = req.params;
|
||||||
const { etext, etitle } = req.body;
|
const { etext, etitle } = req.body;
|
||||||
|
let eObj = [etext, etitle]
|
||||||
// Verify user has required level
|
// Verify user has required level
|
||||||
if (getUserLevel(user.points) < 7) {
|
if (getUserLevel(user.points) < 7) {
|
||||||
return res.status(403).send(config.errorForbidden);
|
return res.status(403).send(config.errorForbidden);
|
||||||
|
|
@ -25,7 +25,7 @@ async function EditQuestionStatusClosed(req, res) {
|
||||||
}
|
}
|
||||||
|
|
||||||
await Question.findByIdAndUpdate(question_id, {
|
await Question.findByIdAndUpdate(question_id, {
|
||||||
editText: etext,
|
editText: eObj,
|
||||||
$push: { edit: user.username },
|
$push: { edit: user.username },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -48,13 +48,14 @@ async function EditQuestionStatusClosed(req, res) {
|
||||||
if (question.edit.length === 2) {
|
if (question.edit.length === 2) {
|
||||||
const question = await Question.findByIdAndUpdate(question_id, {
|
const question = await Question.findByIdAndUpdate(question_id, {
|
||||||
edit: [],
|
edit: [],
|
||||||
etext,
|
eObj,
|
||||||
etitle
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const { success } = await createRequest('patch', `/questions/${question_id}`, {
|
const { success } = await createRequest('patch', `/questions/${question_id}`, {
|
||||||
etext,
|
etext,
|
||||||
etitle
|
eObj
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return success
|
return success
|
||||||
|
|
|
||||||
Reference in a new issue