Skip to content

Commit

Permalink
fix: minor fixes here and there
Browse files Browse the repository at this point in the history
  • Loading branch information
drodil committed Nov 1, 2024
1 parent 3e7f4b0 commit 1dc5fc8
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 14 deletions.
3 changes: 2 additions & 1 deletion plugins/qeta-backend/src/database/DatabaseQetaStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2385,14 +2385,15 @@ export class DatabaseQetaStore implements QetaStore {
addPost?: boolean,
): Promise<Answer> {
const additionalInfo = await Promise.all([
addVotes ? this.getAnswerVotes(val.id) : undefined,
addVotes !== false ? this.getAnswerVotes(val.id) : undefined,
addComments ? this.getAnswerComments(val.id) : undefined,
addPost ? this.getPost(user_ref, val.postId, false) : undefined,
this.db('attachments').select('id').where('answerId', val.id),
]);
return {
id: val.id,
postId: val.postId,
own: val.author === user_ref,
author:
val.anonymous && val.author !== user_ref ? 'anonymous' : val.author,
content: val.content,
Expand Down
13 changes: 12 additions & 1 deletion plugins/qeta-backend/src/service/routes/answers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ export const answersRoutes = (router: Router, options: RouteOptions) => {
const filter: PermissionCriteria<QetaFilters> = transformConditions(
decision.conditions,
);
await database.getAnswers(username, request.query, filter);
const answers = await database.getAnswers(
username,
request.query,
filter,
);
response.json(answers);
} else {
response.json(await database.getAnswers(username, request.query));
}
Expand Down Expand Up @@ -448,6 +453,12 @@ export const answersRoutes = (router: Router, options: RouteOptions) => {

await authorize(request, qetaReadPostPermission, options, post);
await authorize(request, qetaReadAnswerPermission, options, answer);
if (answer.own) {
response
.status(400)
.send({ errors: 'Cannot vote on own answer', type: 'body' });
return;
}

// Act
const voted = await database.voteAnswer(username, answerId, score);
Expand Down
6 changes: 6 additions & 0 deletions plugins/qeta-backend/src/service/routes/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,12 @@ export const postsRoutes = (router: Router, options: RouteOptions) => {
}

await authorize(request, qetaReadPostPermission, options, post);
if (post.own) {
response
.status(400)
.send({ errors: 'You cannot vote your own post', type: 'body' });
return;
}

const voted = await database.votePost(username, postId, score);

Expand Down
27 changes: 17 additions & 10 deletions plugins/qeta-react/src/components/AnswerCard/AnswerCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,19 @@ export const AnswerCard = (props: {
}`}
>
<CardContent>
<Grid container spacing={0} justifyContent="flex-start">
<Grid container item xs={1} justifyContent="center">
<Grid
container
spacing={0}
justifyContent="flex-start"
style={{ flexWrap: 'nowrap' }}
>
<Grid item justifyContent="center">
<div className={styles.questionCardVote}>
<VoteButtons entity={answerEntity} post={question} />
<LinkButton entity={answerEntity} />
</div>
</Grid>
<Grid item xs={11} className={styles.answerCardContent}>
<Grid item className={styles.answerCardContent}>
{editMode ? (
<AnswerForm
post={question}
Expand All @@ -75,12 +80,14 @@ export const AnswerCard = (props: {
/>
) : (
<>
<Typography variant="body1" gutterBottom>
<MarkdownRenderer
className="qetaAndwerCardAnswerContent"
content={answerEntity.content}
/>
</Typography>
<Grid item>
<Typography variant="body1" gutterBottom>
<MarkdownRenderer
className="qetaAndwerCardAnswerContent"
content={answerEntity.content}
/>
</Typography>
</Grid>
<Grid
container
item
Expand All @@ -89,7 +96,7 @@ export const AnswerCard = (props: {
alignItems="flex-end"
className={styles.questionCardMetadata}
>
<Grid item xs={9} style={{ alignSelf: 'flex-end' }}>
<Grid item style={{ alignSelf: 'flex-end' }}>
{(answerEntity.own ||
answerEntity.canDelete ||
answerEntity.canEdit) && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export type PostFilters = Filters & {
export type AnswerFilters = Filters & {
orderBy?: 'created' | 'score' | 'updated';
noVotes?: 'true' | 'false';
noCorrectAnswer?: 'true' | 'false';
};

export type CollectionFilters = Filters & {
Expand Down Expand Up @@ -221,7 +222,7 @@ export const FilterPanel = <T extends Filters>(props: FilterPanelProps<T>) => {
label={t('filterPanel.noAnswers.label')}
/>
)}
{postFilters && type !== 'article' && (
{(postFilters || answerFilters) && type !== 'article' && (
<FormControlLabel
control={
<Checkbox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const PostsGridContent = (props: {
>
{response.posts.map(p => {
return (
<Grid item xs={12} xl={6} key={p.id}>
<Grid item xs={12} key={p.id}>
<PostsGridItem
post={p}
type={type}
Expand Down

0 comments on commit 1dc5fc8

Please sign in to comment.