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.yamlindex 629ac11a..996cfa56 100644--- a/i18n/zh_CN.yaml+++ b/i18n/zh_CN.yaml@@ -841,6 +841,7 @@ ui:http_50X: HTTP 错误 500http_403: HTTP 错误 403logout: 退出+ posts: 帖子notifications:title: 通知inbox: 收件箱diff --git a/ui/src/pages/Tags/Detail/index.tsx b/ui/src/pages/Tags/Detail/index.tsxindex 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.tsindex 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,};