Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

fix: Optimize list type judgment logic

shuai44beb6d15ce0
diff --git a/i18n/zh_CN.yaml b/i18n/zh_CN.yaml
index 629ac11a..996cfa56 100644
--- a/i18n/zh_CN.yaml
+++ b/i18n/zh_CN.yaml
@@ -841,6 +841,7 @@ ui:
http_50X: HTTP 错误 500
http_403: HTTP 错误 403
logout: 退出
+ posts: 帖子
notifications:
title: 通知
inbox: 收件箱
diff --git a/ui/src/pages/Tags/Detail/index.tsx b/ui/src/pages/Tags/Detail/index.tsx
index dc475667..62ff5dd4 100644
--- a/ui/src/pages/Tags/Detail/index.tsx
+++ b/ui/src/pages/Tags/Detail/index.tsx
@@ -24,7 +24,6 @@ import {
Link,
useNavigate,
useSearchParams,
- useMatch,
} from 'react-router-dom';
import { useTranslation } from 'react-i18next';
@@ -39,7 +38,7 @@ import {
} from '@/services';
import QuestionList, { QUESTION_ORDER_KEYS } from '@/components/QuestionList';
import HotQuestions from '@/components/HotQuestions';
-import { guard } from '@/utils';
+import { guard, pageTitleType } from '@/utils';
import { pathFactory } from '@/router/pathFactory';
const Index: FC = () => {
@@ -66,8 +65,6 @@ const Index: FC = () => {
tagInfo?.tag_id,
tagInfo?.status,
);
- const matchQuestions = useMatch('/tags/:tagName/questions');
- const matchPosts = useMatch('/tags/:tagName');
const toggleFollow = () => {
if (!guard.tryNormalLogged(true)) {
return;
@@ -103,16 +100,9 @@ const Index: FC = () => {
}, [tagResp, followResp]);
let pageTitle = '';
if (tagInfo?.display_name) {
- if (matchQuestions) {
- pageTitle = `'${tagInfo.display_name}' ${t('questions', {
- keyPrefix: 'page_title',
- })}`;
- }
- if (matchPosts) {
- pageTitle = `'${tagInfo.display_name}' ${t('posts', {
- keyPrefix: 'page_title',
- })}`;
- }
+ pageTitle = `'${tagInfo.display_name}' ${t(pageTitleType(), {
+ keyPrefix: 'page_title',
+ })}`;
}
const keywords: string[] = [];
if (tagInfo?.slug_name) {
diff --git a/ui/src/utils/common.ts b/ui/src/utils/common.ts
index 996da7f6..4cc78ebe 100644
--- a/ui/src/utils/common.ts
+++ b/ui/src/utils/common.ts
@@ -292,6 +292,17 @@ function isDarkTheme() {
return htmlTag.getAttribute('data-bs-theme') === 'dark';
}
+function pageTitleType() {
+ const { pathname } = window.location;
+ if (pathname.endsWith('/articles')) {
+ return 'articles';
+ }
+ if (pathname.endsWith('/questions')) {
+ return 'questions';
+ }
+ return 'posts';
+}
+
export {
thousandthDivision,
formatCount,
@@ -310,4 +321,5 @@ export {
getUaType,
changeTheme,
isDarkTheme,
+ pageTitleType,
};