Skip to content

Commit

Permalink
fix(problem-list): 题单页带custom参数的url刷新后不需要等待重定向
Browse files Browse the repository at this point in the history
  • Loading branch information
XYShaoKang committed Feb 14, 2023
1 parent df90b01 commit 044f62e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/content/pages/problemset/Title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import TitleBase from './TitleBase'
import { Portal } from '@/components/Portal'
import { routerTo } from '@/utils'
import { selectIsPremium } from '../global/globalSlice'
import { selectCurrentPage, selectIsPremium } from '../global/globalSlice'

interface RankTitleProps {
otherRoots: { [key in OrderBy]?: HTMLElement }
Expand All @@ -24,6 +24,7 @@ interface RankTitleProps {
const RankTitle: FC<RankTitleProps> = ({ otherRoots }) => {
const [params, setParams] = useState(parseParams())
const isPremium = useAppSelector(selectIsPremium)
const currentPage = useAppSelector(selectCurrentPage)

useEffect(() => {
SORT_KEY.forEach(({ key }) => {
Expand All @@ -47,9 +48,16 @@ const RankTitle: FC<RankTitleProps> = ({ otherRoots }) => {
// 如果第一次访问的 url 中,包含 customSort,则需要进行特殊的处理。
void (async function () {
if (params.custom) {
// 如果包含 customSort,那么一定是包含 id 的 sroting,则一定会重定向一次。
await once('routeChangeComplete')

/**
* 在题库页中,如果包含 custom,那么一定是包含 id 的 sroting,
* 则一定会重定向到 sroting 等于 `ASCENDING`,
* 需要等待重定向完成后,再通过路由跳转到到包含自定义参数的 url
*
* 而在题单页中,则不会进行重定向,就不用去等待
*/
if (currentPage === 'problemsetPage') {
await once('routeChangeComplete')
}
handleCustomSort()()
}
})()
Expand Down

0 comments on commit 044f62e

Please sign in to comment.