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(QuestionList): Make the Tag details page remember how to sort the list of questions too
haitaoob191b9e471f8
diff --git a/ui/src/components/QuestionList/index.tsx b/ui/src/components/QuestionList/index.tsxindex bbf07612..0911a945 100644--- a/ui/src/components/QuestionList/index.tsx+++ b/ui/src/components/QuestionList/index.tsx@@ -17,8 +17,6 @@ import {Icon,} from '@/components';import * as Type from '@/common/interface';-import { Storage } from '@/utils';-import { QUESTIONS_ORDER_STORAGE_KEY } from '@/common/constants';export const QUESTION_ORDER_KEYS: Type.QuestionOrderBy[] = ['active',@@ -42,17 +40,8 @@ const QuestionList: FC<Props> = ({}) => {const { t } = useTranslation('translation', { keyPrefix: 'question' });const [urlSearchParams] = useSearchParams();-- const storageOrder = Storage.get(QUESTIONS_ORDER_STORAGE_KEY);const curOrder =- order ||- urlSearchParams.get('order') ||- storageOrder ||- QUESTION_ORDER_KEYS[0];- if (curOrder !== storageOrder) {- Storage.set(QUESTIONS_ORDER_STORAGE_KEY, curOrder);- }-+ order || urlSearchParams.get('order') || QUESTION_ORDER_KEYS[0];const curPage = Number(urlSearchParams.get('page')) || 1;const pageSize = 20;const count = data?.count || 0;diff --git a/ui/src/pages/Tags/Detail/index.tsx b/ui/src/pages/Tags/Detail/index.tsxindex ffd5341e..5932f5c5 100644--- a/ui/src/pages/Tags/Detail/index.tsx+++ b/ui/src/pages/Tags/Detail/index.tsx@@ -17,10 +17,11 @@ import {useQuerySynonymsTags,useQuestionList,} from '@/services';-import QuestionList from '@/components/QuestionList';+import QuestionList, { QUESTION_ORDER_KEYS } from '@/components/QuestionList';import HotQuestions from '@/components/HotQuestions';-import { escapeRemove, guard } from '@/utils';+import { escapeRemove, guard, Storage } from '@/utils';import { pathFactory } from '@/router/pathFactory';+import { QUESTIONS_ORDER_STORAGE_KEY } from '@/common/constants';const Index: FC = () => {const { t } = useTranslation('translation', { keyPrefix: 'tags' });@@ -28,7 +29,12 @@ const Index: FC = () => {const routeParams = useParams();const curTagName = routeParams.tagName || '';const [urlSearchParams] = useSearchParams();- const curOrder = urlSearchParams.get('order') || 'active';+ const storageOrder = Storage.get(QUESTIONS_ORDER_STORAGE_KEY);+ const curOrder =+ urlSearchParams.get('order') || storageOrder || QUESTION_ORDER_KEYS[0];+ if (curOrder !== storageOrder) {+ Storage.set(QUESTIONS_ORDER_STORAGE_KEY, curOrder);+ }const curPage = Number(urlSearchParams.get('page')) || 1;const reqParams: Type.QueryQuestionsReq = {page_size: 20,@@ -148,7 +154,12 @@ const Index: FC = () => {</div></div>)}- <QuestionList source="tag" data={listData} isLoading={listLoading} />+ <QuestionList+ source="tag"+ data={listData}+ order={curOrder}+ isLoading={listLoading}+ /></Col><Col className="page-right-side mt-4 mt-xl-0"><CustomSidebar />