-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathindex.tsx
More file actions
137 lines (134 loc) · 4.23 KB
/
index.tsx
File metadata and controls
137 lines (134 loc) · 4.23 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import { FC } from 'react';
import { ListGroup } from 'react-bootstrap';
import { NavLink, useSearchParams } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import type { QuestionOrderBy } from '@/common/interface';
import { pathFactory } from '@/router/pathFactory';
import {
Tag,
Pagination,
FormatTime,
Empty,
BaseUserCard,
QueryGroup,
QuestionListLoader,
Counts,
Icon,
} from '@/components';
import * as Type from '@/common/interface';
export const QUESTION_ORDER_KEYS: Type.QuestionOrderBy[] = [
'active',
'newest',
'frequent',
'score',
'unanswered',
];
interface Props {
source: 'questions' | 'tag';
order?: QuestionOrderBy;
data;
isLoading: boolean;
}
const QuestionList: FC<Props> = ({
source,
order,
data,
isLoading = false,
}) => {
const { t } = useTranslation('translation', { keyPrefix: 'question' });
const [urlSearchParams] = useSearchParams();
const curOrder =
order || urlSearchParams.get('order') || QUESTION_ORDER_KEYS[0];
const curPage = Number(urlSearchParams.get('page')) || 1;
const pageSize = 20;
const count = data?.count || 0;
return (
<div>
<div className="answer_questions-head mb-3 d-flex flex-wrap justify-content-between">
<h5 className="fs-5 text-nowrap mb-3 mb-md-0">
{source === 'questions'
? t('all_questions')
: t('x_questions', { count })}
</h5>
<QueryGroup
data={QUESTION_ORDER_KEYS}
currentSort={curOrder}
pathname={source === 'questions' ? '/questions' : ''}
i18nKeyPrefix="question"
/>
</div>
<ListGroup className="answer_questions-list rounded-0">
{isLoading ? (
<QuestionListLoader />
) : (
data?.list?.map((li) => {
return (
<ListGroup.Item
key={li.id}
className="bg-transparent py-3 px-0 border-start-0 border-end-0">
<h5 className="text-wrap text-break">
{li.pin === 2 && (
<Icon
name="pin-fill"
className="me-1"
title={t('pinned', { keyPrefix: 'btns' })}
/>
)}
<NavLink
to={pathFactory.questionLanding(li.id, li.url_title)}
className="link-dark">
{li.title}
{li.status === 2 ? ` [${t('closed')}]` : ''}
</NavLink>
</h5>
<div className="d-flex flex-column flex-md-row align-items-md-center small mb-2 text-secondary">
<div className="d-flex">
<BaseUserCard
data={li.operator}
showAvatar={false}
className="me-1"
/>
•
<FormatTime
time={li.operated_at}
className="text-secondary ms-1"
preFix={t(li.operation_type)}
/>
</div>
<Counts
data={{
votes: li.vote_count,
answers: li.answer_count,
views: li.view_count,
}}
isAccepted={li.accepted_answer_id >= 1}
className="ms-0 ms-md-3 mt-2 mt-md-0"
/>
</div>
<div className="question-tags m-n1">
{Array.isArray(li.tags)
? li.tags.map((tag) => {
return (
<Tag key={tag.slug_name} className="m-1" data={tag} />
);
})
: null}
</div>
</ListGroup.Item>
);
})
)}
</ListGroup>
{count <= 0 && !isLoading && <Empty />}
<div className="mt-4 mb-2 d-flex justify-content-center">
<Pagination
currentPage={curPage}
totalSize={count}
pageSize={pageSize}
pathname={source === 'questions' ? '/questions' : ''}
/>
</div>
</div>
);
};
export default QuestionList;