fix answerslist not logged in

This commit is contained in:
“spicecat” 2022-08-02 11:24:57 -05:00
commit 986b303576
2 changed files with 45 additions and 49 deletions

View file

@ -21,48 +21,46 @@ export default function Answer({
text,
upvotes,
}) {
const { userData } = useUser();
const { userData: { level, username } } = useUser();
const getVote = () => getAnswerVote(question_id, answer_id);
const updateVote = (data) => updateAnswerVote(question_id, answer_id, data);
var canComment =
userData.level >= 3 || creator === userData.username ? true : false;
const canComment = level >= 3 || creator === username;
if (userData.username)
return (
<span key={answer_id}>
<ListItem disablePadding>
<ButtonGroup orientation='vertical'>
<VoteControl
{...{
downvotes,
getVote,
orientation: 'vertical',
updateVote,
upvotes,
}}
/>
{accepted && (
<div style={{ textAlign: 'center' }}>
<Tooltip
title='Accepted Answer'
placement='right'
>
<CheckIcon color='success' />
</Tooltip>
</div>
)}
</ButtonGroup>
<ListItemText>
<CreationInfoTag
{...{ createdAt, creator, text: 'answered' }}
/>
<ReactMarkdown>{text}</ReactMarkdown>
<CommentControl {...{ canComment }} />
</ListItemText>
</ListItem>
<ListItem sx={{ pl: 8 }}>
<AnswerCommentsList {...{ answer_id, comments }} />
</ListItem>
</span>
);
return (
<span key={answer_id}>
<ListItem disablePadding>
<ButtonGroup orientation='vertical'>
<VoteControl
{...{
downvotes,
getVote,
orientation: 'vertical',
updateVote,
upvotes,
}}
/>
{accepted && (
<div style={{ textAlign: 'center' }}>
<Tooltip
title='Accepted Answer'
placement='right'
>
<CheckIcon color='success' />
</Tooltip>
</div>
)}
</ButtonGroup>
<ListItemText>
<CreationInfoTag
{...{ createdAt, creator, text: 'answered' }}
/>
<ReactMarkdown>{text}</ReactMarkdown>
<CommentControl {...{ canComment }} />
</ListItemText>
</ListItem>
<ListItem sx={{ pl: 8 }}>
<AnswerCommentsList {...{ answer_id, comments }} />
</ListItem>
</span>
);
}

View file

@ -15,31 +15,29 @@ export function AnswerCommentsList({ answer_id, comments: count }) {
}
export function AnswersList() {
const { questionData: { answers: count, question_id } } = useQuestion();
const { questionData: { answers: count, loading, question_id } } = useQuestion();
const sortByPoints = answers => answers.sort((a, b) => b.upvotes - b.downvotes - a.upvotes + a.downvotes);
console.log(question_id)
const getData = ({ answer_id }) =>
getAnswers(question_id, { after: answer_id })
.then(({ answers }) => sortByPoints(answers).map(answer => ({ ...answer, question_id })))
.catch(() => []);
return (
question_id && <PaginatedList {...{ count, Component: Answer, getData, noData: false }} />
!loading && <PaginatedList {...{ count, Component: Answer, getData, noData: false }} />
);
}
export function CommentsList() {
const { questionData: { comments: count, question_id } } = useQuestion();
const getData = ({comment_id}) =>
getQuestionComments(question_id, {after: comment_id})
const getData = ({ comment_id }) =>
getQuestionComments(question_id, { after: comment_id })
.then(({ comments }) => comments.map(comment => ({ ...comment, question_id })))
.catch(() => []);
return (
question_id && <PaginatedList {...{ count, Component: Comment, getData, noData: false }} />
<PaginatedList {...{ count, Component: Comment, getData, noData: false }} />
);
}