Merge pull request #382 from answerdev/feat/1.1.0/ui

fix(QuestionList): Make the Tag details page remember how to sort the…
This commit is contained in:
haitao.jarvis 2023-05-31 20:48:42 +08:00 committed by GitHub
commit b2294bddc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 16 deletions

View File

@ -17,8 +17,6 @@ import {
Icon, Icon,
} from '@/components'; } from '@/components';
import * as Type from '@/common/interface'; 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[] = [ export const QUESTION_ORDER_KEYS: Type.QuestionOrderBy[] = [
'active', 'active',
@ -42,17 +40,8 @@ const QuestionList: FC<Props> = ({
}) => { }) => {
const { t } = useTranslation('translation', { keyPrefix: 'question' }); const { t } = useTranslation('translation', { keyPrefix: 'question' });
const [urlSearchParams] = useSearchParams(); const [urlSearchParams] = useSearchParams();
const storageOrder = Storage.get(QUESTIONS_ORDER_STORAGE_KEY);
const curOrder = const curOrder =
order || order || urlSearchParams.get('order') || QUESTION_ORDER_KEYS[0];
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 curPage = Number(urlSearchParams.get('page')) || 1;
const pageSize = 20; const pageSize = 20;
const count = data?.count || 0; const count = data?.count || 0;

View File

@ -17,10 +17,11 @@ import {
useQuerySynonymsTags, useQuerySynonymsTags,
useQuestionList, useQuestionList,
} from '@/services'; } from '@/services';
import QuestionList from '@/components/QuestionList'; import QuestionList, { QUESTION_ORDER_KEYS } from '@/components/QuestionList';
import HotQuestions from '@/components/HotQuestions'; import HotQuestions from '@/components/HotQuestions';
import { escapeRemove, guard } from '@/utils'; import { escapeRemove, guard, Storage } from '@/utils';
import { pathFactory } from '@/router/pathFactory'; import { pathFactory } from '@/router/pathFactory';
import { QUESTIONS_ORDER_STORAGE_KEY } from '@/common/constants';
const Index: FC = () => { const Index: FC = () => {
const { t } = useTranslation('translation', { keyPrefix: 'tags' }); const { t } = useTranslation('translation', { keyPrefix: 'tags' });
@ -28,7 +29,12 @@ const Index: FC = () => {
const routeParams = useParams(); const routeParams = useParams();
const curTagName = routeParams.tagName || ''; const curTagName = routeParams.tagName || '';
const [urlSearchParams] = useSearchParams(); 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 curPage = Number(urlSearchParams.get('page')) || 1;
const reqParams: Type.QueryQuestionsReq = { const reqParams: Type.QueryQuestionsReq = {
page_size: 20, page_size: 20,
@ -148,7 +154,12 @@ const Index: FC = () => {
</div> </div>
</div> </div>
)} )}
<QuestionList source="tag" data={listData} isLoading={listLoading} /> <QuestionList
source="tag"
data={listData}
order={curOrder}
isLoading={listLoading}
/>
</Col> </Col>
<Col className="page-right-side mt-4 mt-xl-0"> <Col className="page-right-side mt-4 mt-xl-0">
<CustomSidebar /> <CustomSidebar />