diff --git a/i18n/en_US.yaml b/i18n/en_US.yaml index e0e16aa0..079a776d 100644 --- a/i18n/en_US.yaml +++ b/i18n/en_US.yaml @@ -994,7 +994,11 @@ ui: db_failed: Database connection failed db_failed_desc: >- This either means that the database information in your <1>config.yaml file is incorrect or that contact with the database server could not be established. This could mean your host’s database server is down. - + counts: + views: views + votes: votes + answers: answers + accepted: Accepted page_404: desc: "Unfortunately, this page doesn't exist." back_home: Back to homepage diff --git a/ui/src/components/Counts/index.tsx b/ui/src/components/Counts/index.tsx new file mode 100644 index 00000000..42555bb4 --- /dev/null +++ b/ui/src/components/Counts/index.tsx @@ -0,0 +1,77 @@ +import { FC, memo } from 'react'; +import { useTranslation } from 'react-i18next'; + +import classname from 'classnames'; + +import { Icon } from '@/components'; + +interface Props { + data: { + votes: number; + answers: number; + views: number; + }; + showVotes?: boolean; + showAnswers?: boolean; + showViews?: boolean; + showAccepted?: boolean; + isAccepted?: boolean; + className?: string; +} +const Index: FC = ({ + data, + showVotes = true, + showAnswers = true, + showViews = true, + isAccepted = false, + showAccepted = false, + className = '', +}) => { + const { t } = useTranslation('translation', { keyPrefix: 'counts' }); + + return ( +
+ {showVotes && ( +
+ + + {data.votes} {t('votes')} + +
+ )} + + {showAccepted && ( +
+ + {t('accepted')} +
+ )} + + {showAnswers && ( +
+ {isAccepted ? ( + + ) : ( + + )} + + {data.answers} {t('answers')} + +
+ )} + {showViews && ( + + + + {data.views} {t('views')} + + + )} +
+ ); +}; + +export default memo(Index); diff --git a/ui/src/components/QuestionList/index.tsx b/ui/src/components/QuestionList/index.tsx index a78cef80..f40cd308 100644 --- a/ui/src/components/QuestionList/index.tsx +++ b/ui/src/components/QuestionList/index.tsx @@ -6,7 +6,6 @@ import { useTranslation } from 'react-i18next'; import { pathFactory } from '@/router/pathFactory'; import type * as Type from '@/common/interface'; import { - Icon, Tag, Pagination, FormatTime, @@ -14,6 +13,7 @@ import { BaseUserCard, QueryGroup, QuestionListLoader, + Counts, } from '@/components'; import { useQuestionList } from '@/services'; @@ -95,29 +95,15 @@ const QuestionList: FC = ({ source }) => { preFix={t(li.operation_type)} /> -
- - - {li.vote_count} - - = 1 ? 'text-success' : '' - }`}> - = 1 - ? 'check-circle-fill' - : 'chat-square-text-fill' - } - /> - {li.answer_count} - - - - {li.view_count} - -
+ = 1} + className="ms-0 ms-md-3 mt-2 mt-md-0" + />
{Array.isArray(li.tags) diff --git a/ui/src/components/index.ts b/ui/src/components/index.ts index 2a475e8b..49340cf7 100644 --- a/ui/src/components/index.ts +++ b/ui/src/components/index.ts @@ -32,6 +32,7 @@ import CustomizeTheme from './CustomizeTheme'; import PageTags from './PageTags'; import QuestionListLoader from './QuestionListLoader'; import TagsLoader from './TagsLoader'; +import Counts from './Counts'; export { Avatar, @@ -70,5 +71,6 @@ export { PageTags, QuestionListLoader, TagsLoader, + Counts, }; export type { EditorRef, JSONSchema, UISchema }; diff --git a/ui/src/pages/Search/components/SearchItem/index.tsx b/ui/src/pages/Search/components/SearchItem/index.tsx index dc63246c..1b4f786c 100644 --- a/ui/src/pages/Search/components/SearchItem/index.tsx +++ b/ui/src/pages/Search/components/SearchItem/index.tsx @@ -3,7 +3,7 @@ import { ListGroupItem } from 'react-bootstrap'; import { useTranslation } from 'react-i18next'; import { pathFactory } from '@/router/pathFactory'; -import { Icon, Tag, FormatTime, BaseUserCard } from '@/components'; +import { Tag, FormatTime, BaseUserCard, Counts } from '@/components'; import type { SearchResItem } from '@/common/interface'; import { escapeRemove } from '@/utils'; @@ -51,23 +51,17 @@ const Index: FC = ({ data }) => { className="me-3" preFix={data.object_type === 'question' ? 'asked' : 'answered'} /> -
-
- - {data.object?.vote_count} -
-
- {data.object?.accepted ? ( - - ) : ( - - )} - {data.object?.answer_count} -
-
+ +
{data.object?.excerpt && ( diff --git a/ui/src/pages/Users/Personal/components/Answers/index.tsx b/ui/src/pages/Users/Personal/components/Answers/index.tsx index 383b09df..6f4685ec 100644 --- a/ui/src/pages/Users/Personal/components/Answers/index.tsx +++ b/ui/src/pages/Users/Personal/components/Answers/index.tsx @@ -2,7 +2,7 @@ import { FC, memo } from 'react'; import { ListGroup, ListGroupItem } from 'react-bootstrap'; import { useTranslation } from 'react-i18next'; -import { Icon, FormatTime, Tag } from '@/components'; +import { FormatTime, Tag, Counts } from '@/components'; import { pathFactory } from '@/router/pathFactory'; interface Props { @@ -35,21 +35,16 @@ const Index: FC = ({ visible, data }) => {
-
- - {item?.vote_count} -
- - {item.accepted === 2 && ( -
- - {t('accepted')} -
- )} +
{item.question_info?.tags?.map((tag) => { diff --git a/ui/src/pages/Users/Personal/components/DefaultList/index.tsx b/ui/src/pages/Users/Personal/components/DefaultList/index.tsx index 5084f7ee..eeae2c9e 100644 --- a/ui/src/pages/Users/Personal/components/DefaultList/index.tsx +++ b/ui/src/pages/Users/Personal/components/DefaultList/index.tsx @@ -2,7 +2,7 @@ import { FC, memo } from 'react'; import { ListGroup, ListGroupItem } from 'react-bootstrap'; import { useTranslation } from 'react-i18next'; -import { Icon, FormatTime, Tag, BaseUserCard } from '@/components'; +import { FormatTime, Tag, BaseUserCard, Counts } from '@/components'; import { pathFactory } from '@/router/pathFactory'; interface Props { @@ -44,35 +44,23 @@ const Index: FC = ({ visible, tabName, data }) => { )} + -
- - {item.vote_count} -
- - {tabName !== 'answers' && ( -
0 ? 'text-success' : '' - }`}> - {Number(item.accepted_answer_id) > 0 ? ( - - ) : ( - - )} - {item.answer_count} -
- )} - -
- - {item.view_count} -
+ 0} + data={{ + votes: item.vote_count, + answers: item.answer_count, + views: item.view_count, + }} + />
{item.tags?.map((tag) => { diff --git a/ui/src/pages/Users/Personal/components/TopList/index.tsx b/ui/src/pages/Users/Personal/components/TopList/index.tsx index 744a3f7b..43e5159d 100644 --- a/ui/src/pages/Users/Personal/components/TopList/index.tsx +++ b/ui/src/pages/Users/Personal/components/TopList/index.tsx @@ -32,9 +32,12 @@ const Index: FC = ({ data, type }) => { }> {type === 'answer' ? item.question_info.title : item.title} +
- - {item.vote_count} + + + {item.vote_count} {t('votes', { keyPrefix: 'counts' })} +
{type === 'question' && (
= ({ data, type }) => { )} - {item.answer_count} + + {' '} + {item.answer_count} {t('answers', { keyPrefix: 'counts' })} +
)}