From 9d6903a183f04267046a2660ace88d010b14d9b5 Mon Sep 17 00:00:00 2001 From: Ani Simhadri Date: Thu, 18 Aug 2022 16:58:42 -0400 Subject: [PATCH 1/6] config --- package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 122433f..f03b82c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32178,7 +32178,7 @@ "js-cookie": "^3.0.1", "marked": "^4.0.18", "react": "^18.2.0", - "react-copy-to-clipboard": "*", + "react-copy-to-clipboard": "^5.1.0", "react-gravatar": "^2.6.3", "react-helmet": "^6.1.0", "react-markdown": "^8.0.3", From 57e52c9a14b83253d23775580e287d9ce7f7e551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cspicecat=E2=80=9D?= Date: Thu, 18 Aug 2022 17:12:00 -0400 Subject: [PATCH 2/6] accepted answer chip --- client/src/components/ListQuestion.jsx | 6 ++-- client/src/components/ListQuestionInfo.jsx | 33 ++++++++++++++++------ 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/client/src/components/ListQuestion.jsx b/client/src/components/ListQuestion.jsx index 3ae30a0..05dda16 100644 --- a/client/src/components/ListQuestion.jsx +++ b/client/src/components/ListQuestion.jsx @@ -20,7 +20,7 @@ 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 ( @@ -31,7 +31,7 @@ export default function ListQuestion({ - {sm || md ? null : } + {sm || md ? null : } {text.replace(/<[^>]*>?/gm, '')} - Accepted: {String(hasAcceptedAnswer)} - diff --git a/client/src/components/ListQuestionInfo.jsx b/client/src/components/ListQuestionInfo.jsx index 57c1a87..e61cc4e 100644 --- a/client/src/components/ListQuestionInfo.jsx +++ b/client/src/components/ListQuestionInfo.jsx @@ -1,16 +1,31 @@ -import { Typography } from "@mui/material" -export default function ListQuestionInfo({upvotes, downvotes, answers, views, inline}){ - return inline? ( +import { Chip, Typography } from '@mui/material'; +export default function ListQuestionInfo({ upvotes, downvotes, answers, hasAcceptedAnswer, views, inline }) { + return inline ? ( <> - {upvotes - downvotes} votes | - {answers} answers | - {views} views + {upvotes - downvotes} votes | + {answers} answers | + {views} views + + Accepted: + + ) : ( <> - {upvotes - downvotes} votes - {answers} answers - {views} views + {upvotes - downvotes} votes + {answers} answers + {views} views + + Accepted: + ) } \ No newline at end of file From c9680903cbfed1dc4e89d3d675d48c1549fa581d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cspicecat=E2=80=9D?= Date: Thu, 18 Aug 2022 17:17:00 -0400 Subject: [PATCH 3/6] listquestion tags --- client/src/components/ListQuestion.jsx | 4 ++-- client/src/components/ListQuestionInfo.jsx | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/client/src/components/ListQuestion.jsx b/client/src/components/ListQuestion.jsx index 05dda16..22a7008 100644 --- a/client/src/components/ListQuestion.jsx +++ b/client/src/components/ListQuestion.jsx @@ -27,11 +27,11 @@ export default function ListQuestion({ - {sm || md ? : null} + {sm || md ? : null} - {sm || md ? null : } + {sm || md ? null : } {upvotes - downvotes} votes | @@ -13,6 +13,7 @@ export default function ListQuestionInfo({ upvotes, downvotes, answers, hasAccep label={hasAcceptedAnswer ? 'yes' : 'no'} size='small' /> + Tags: {tags.join(', ')} ) : ( <> @@ -26,6 +27,7 @@ export default function ListQuestionInfo({ upvotes, downvotes, answers, hasAccep size='small' /> + Tags: {tags.join(', ')} ) } \ No newline at end of file From cc2021767743d08d918e07b195a04c861479f390 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cspicecat=E2=80=9D?= Date: Thu, 18 Aug 2022 17:20:37 -0400 Subject: [PATCH 4/6] qa tags --- .../src/components/QAComponents/Question.jsx | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/client/src/components/QAComponents/Question.jsx b/client/src/components/QAComponents/Question.jsx index 259b782..386eafe 100644 --- a/client/src/components/QAComponents/Question.jsx +++ b/client/src/components/QAComponents/Question.jsx @@ -39,6 +39,7 @@ export default function Question({ downvotes, hasAcceptedAnswer, status, + tags, title, text, upvotes, @@ -62,11 +63,11 @@ export default function Question({ const [value, setValue] = useState(75); canBounty = canBounty && !hasBounty - function handleBountyFix(){ + function handleBountyFix() { handleBounty(value) } return ( - + <> {title} @@ -92,6 +93,8 @@ export default function Question({ label={hasAcceptedAnswer ? 'yes' : 'no'} size='small' /> + Tags: {tags.join(', ')} +
- { show && - { - if (e.target.value === "") { - setValue(75); - return; + {show && + { + if (e.target.value === "") { + setValue(75); + return; + } + const value = e.target.value; + if (value > max) { + setValue(max); + } else if (value < min) { + setValue(min); + } else { + setValue(value); + } + + + }} /> } - const value = e.target.value; - if (value > max) { - setValue(max); - } else if (value < min) { - setValue(min); - } else { - setValue(value); - } - - - }}/> - }
@@ -177,7 +180,7 @@ export default function Question({ {ongoingVote.users.toString()} - voting to {ongoingVote.type} this question{' '} )} - {hasBounty && ( + {hasBounty && ( there is a {hasBounty} point bounty on this question From 45e21f21a27496ac2acdd912d6852c4b41474b21 Mon Sep 17 00:00:00 2001 From: C4 Patino Date: Thu, 18 Aug 2022 17:20:54 -0400 Subject: [PATCH 5/6] Fixed buffet sections --- client/src/containers/Buffet.jsx | 25 +++++++++---------------- server/routes/question/Search.js | 27 +++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/client/src/containers/Buffet.jsx b/client/src/containers/Buffet.jsx index e6e5a4b..4eeebb1 100644 --- a/client/src/containers/Buffet.jsx +++ b/client/src/containers/Buffet.jsx @@ -6,30 +6,23 @@ import { ListQuestion, LoadingBar } from 'components'; import { PaginatedList } from 'controllers'; import { searchQuestions } from 'services/questionsServices'; -const recent = {}; -const best = { sort: 'u' }; -const interesting = { match: JSON.stringify({ answers: 0 }), sort: 'uvc' }; -const hot = { match: JSON.stringify({ hasAcceptedAnswer: false }), sort: 'uvac' }; -const sortObjArr = [recent, best, interesting, hot]; - export default function Buffet() { - const [sort, setSort] = useState(0); + const [sort, setSort] = useState(''); const [loading, setLoading] = useState(true); const [, setSearchParams] = useSearchParams(); const getData = async ({ question_id }) => { const { questions } = await searchQuestions({ - ...sortObjArr[sort], - after: question_id, + sort, }); setLoading(() => false); return questions; }; - const handleSortChange = (_, newSort) => { - setSearchParams(sortObjArr[newSort]); - setSort(newSort); + const handleSortChange = (_, value) => { + setSearchParams({ sort: value }); + setSort(value); }; return ( @@ -60,10 +53,10 @@ export default function Buffet() { onChange={handleSortChange} style={{ display: 'block', marginTop: '1%' }} > - Recent - Best - Interesting - Hot + Recent + Best + Interesting + Hot {loading && } diff --git a/server/routes/question/Search.js b/server/routes/question/Search.js index 058f3df..eb5311a 100644 --- a/server/routes/question/Search.js +++ b/server/routes/question/Search.js @@ -3,7 +3,7 @@ const config = require('server/config.json'); const Question = require('server/db/models/Question'); async function Search(req, res) { - const { creator, title, text, tags, createdAt } = req.query; + const { creator, title, text, tags, createdAt, sort } = req.query; let searchQuery = {}; if (creator) { @@ -28,7 +28,30 @@ async function Search(req, res) { searchQuery['createdAt'] = createdAt; } - const questions = await Question.find(searchQuery).sort({ createdAt: 'asc' }); + let sortQuery = [[createdAt, 'desc']]; + switch (sort) { + case 'u': + sortQuery = [['upvotes', 'desc']]; + break; + case 'uvc': + sortQuery = [ + ['upvotes', 'desc'], + ['view', 'desc'], + ['comments', 'desc'], + ]; + break; + case 'uvac': + sortQuery = [ + ['upvotes', 'desc'], + ['view', 'desc'], + ['answers', 'desc'], + ['comments', 'desc'], + ]; + searchQuery['hasAcceptedAnswer'] = false; + break; + } + + const questions = await Question.find(searchQuery).sort(sortQuery); return res.send({ questions }); } From e742c0de50a576b7aef81295df6b44d6d875ed25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cspicecat=E2=80=9D?= Date: Thu, 18 Aug 2022 17:24:38 -0400 Subject: [PATCH 6/6] improve dashboard badges display --- client/src/components/Badges.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/components/Badges.jsx b/client/src/components/Badges.jsx index c63f077..b602bed 100644 --- a/client/src/components/Badges.jsx +++ b/client/src/components/Badges.jsx @@ -31,13 +31,13 @@ export default function Badges({ badges: { obtained, unobtained } }) { return ( <> - + Obtained Badges {badgesGrid(obtained)} - + Unobtained Badges {badgesGrid(unobtained)}