This is an automated email from the ASF dual-hosted git repository.

shuai pushed a commit to branch test
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git


The following commit(s) were added to refs/heads/test by this push:
     new 81fbea17 fix: linked page list add order params
81fbea17 is described below

commit 81fbea171b16cff2da5d84e1fc0dcb49e93be818
Author: shuai <[email protected]>
AuthorDate: Fri Oct 18 14:59:04 2024 +0800

    fix: linked page list add order params
---
 .../Detail/components/LinkedQuestions/index.tsx    |  4 +--
 ui/src/pages/Questions/Linked/index.tsx            | 32 +++++++++++-----------
 ui/src/pages/Tags/Detail/index.tsx                 |  2 +-
 ui/src/services/common.ts                          |  3 +-
 4 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/ui/src/pages/Questions/Detail/components/LinkedQuestions/index.tsx 
b/ui/src/pages/Questions/Detail/components/LinkedQuestions/index.tsx
index c5d92cbe..0706cc4b 100644
--- a/ui/src/pages/Questions/Detail/components/LinkedQuestions/index.tsx
+++ b/ui/src/pages/Questions/Detail/components/LinkedQuestions/index.tsx
@@ -25,7 +25,7 @@ import { useTranslation } from 'react-i18next';
 import { isEmpty } from 'lodash';
 
 import { Icon } from '@/components';
-import { questionLink } from '@/services';
+import { useQuestionLink } from '@/services';
 import { pathFactory } from '@/router/pathFactory';
 
 interface Props {
@@ -39,7 +39,7 @@ const Index: FC<Props> = ({ id }) => {
     keyPrefix: 'related_question',
   });
 
-  const { data } = questionLink({
+  const { data } = useQuestionLink({
     question_id: id,
     page: 1,
     page_size: 5,
diff --git a/ui/src/pages/Questions/Linked/index.tsx 
b/ui/src/pages/Questions/Linked/index.tsx
index 981e8c4e..9a08af52 100644
--- a/ui/src/pages/Questions/Linked/index.tsx
+++ b/ui/src/pages/Questions/Linked/index.tsx
@@ -17,13 +17,13 @@
  * under the License.
  */
 
-import { FC, useState } from 'react';
+import { FC, useEffect, useState } from 'react';
 import { Row, Col } from 'react-bootstrap';
 import { useParams, useSearchParams, Link } from 'react-router-dom';
 import { useTranslation } from 'react-i18next';
 
 import { usePageTags } from '@/hooks';
-import { questionLink, questionDetail } from '@/services';
+import { useQuestionLink, questionDetail } from '@/services';
 import * as Type from '@/common/interface';
 import {
   QuestionList,
@@ -50,21 +50,25 @@ const LinkedQuestions: FC = () => {
     QUESTION_ORDER_KEYS[0]) as Type.QuestionOrderBy;
   const pageSize = 10;
   const { siteInfo } = siteInfoStore();
-  const { data: listData, isLoading: listLoading } = questionLink({
+  const { data: listData, isLoading: listLoading } = useQuestionLink({
     question_id: qid || '',
     page: curPage,
     page_size: pageSize,
+    order: curOrder,
   });
   const { login: loginSetting } = loginSettingStore();
   const [questionTitle, setQuestionTitle] = useState('');
-  questionDetail(qid || '')
-    .then((res) => {
-      setQuestionTitle(res.title);
-    })
-    .catch((err) => {
-      console.error('get question detail failed:', err);
-      setQuestionTitle(`#${qid}`);
-    });
+
+  useEffect(() => {
+    questionDetail(qid || '')
+      .then((res) => {
+        setQuestionTitle(res.title);
+      })
+      .catch((err) => {
+        console.error('get question detail failed:', err);
+        setQuestionTitle(`#${qid}`);
+      });
+  }, []);
   usePageTags({
     title: t('title'),
   });
@@ -81,11 +85,7 @@ const LinkedQuestions: FC = () => {
           source="linked"
           data={listData}
           order={curOrder}
-          orderList={
-            loggedUser.username
-              ? QUESTION_ORDER_KEYS
-              : QUESTION_ORDER_KEYS.filter((key) => key !== 'recommend')
-          }
+          orderList={QUESTION_ORDER_KEYS.slice(0, 5)}
           isLoading={listLoading}
         />
       </Col>
diff --git a/ui/src/pages/Tags/Detail/index.tsx 
b/ui/src/pages/Tags/Detail/index.tsx
index ac2fa937..33f65414 100644
--- a/ui/src/pages/Tags/Detail/index.tsx
+++ b/ui/src/pages/Tags/Detail/index.tsx
@@ -176,7 +176,7 @@ const Index: FC = () => {
           source="tag"
           data={listData}
           order={curOrder}
-          orderList={QUESTION_ORDER_KEYS.slice(0, 4)}
+          orderList={QUESTION_ORDER_KEYS.slice(0, 5)}
           isLoading={listLoading}
         />
       </Col>
diff --git a/ui/src/services/common.ts b/ui/src/services/common.ts
index ad0d99e0..724f8eca 100644
--- a/ui/src/services/common.ts
+++ b/ui/src/services/common.ts
@@ -199,10 +199,11 @@ export const questionDetail = (id: string) => {
   );
 };
 
-export const questionLink = (params: {
+export const useQuestionLink = (params: {
   question_id: string;
   page: number;
   page_size: number;
+  order?: string;
 }) => {
   const apiUrl = `/answer/api/v1/question/link?${qs.stringify(params)}`;
   const { data, error } = useSWR<Type.ListResult, Error>(

Reply via email to