-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathindex.tsx
More file actions
68 lines (61 loc) · 1.81 KB
/
index.tsx
File metadata and controls
68 lines (61 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { memo, FC } from 'react';
import { Card, ListGroup } from 'react-bootstrap';
import { Link } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { Icon } from '@/components';
import { useSimilarQuestion } from '@/services';
import { pathFactory } from '@/router/pathFactory';
interface Props {
id: string;
}
const Index: FC<Props> = ({ id }) => {
const { t } = useTranslation('translation', {
keyPrefix: 'related_question',
});
const { data, isLoading } = useSimilarQuestion({
question_id: id,
page_size: 5,
});
if (isLoading) {
return null;
}
return (
<Card className="answer_related-questions">
<Card.Header>{t('title')}</Card.Header>
<ListGroup variant="flush">
{data?.list?.map((item) => {
return (
<ListGroup.Item
action
key={item.id}
as={Link}
to={pathFactory.questionLanding(item.id, item.url_title)}>
<div className="link-dark">{item.title}</div>
{item.answer_count > 0 && (
<div
className={`mt-1 small me-2 ${
item.accepted_answer_id > 0
? 'link-success'
: 'link-secondary'
}`}>
<Icon
name={
item.accepted_answer_id > 0
? 'check-circle-fill'
: 'chat-square-text-fill'
}
className="me-1"
/>
<span>
{item.answer_count} {t('answers')}
</span>
</div>
)}
</ListGroup.Item>
);
})}
</ListGroup>
</Card>
);
};
export default memo(Index);