|
1 | 1 | import { createGlobalStyle } from 'styled-components/macro' |
2 | | -import { useAppDispatch, useAppSelector } from '@/hooks' |
| 2 | +import { useAppDispatch, useAppSelector, useEffectMount } from '@/hooks' |
3 | 3 | import { useCallback, useEffect, useState } from 'react' |
4 | 4 | import { |
5 | 5 | selectOptions, |
6 | 6 | setContestProblemViewWidth, |
7 | 7 | } from '@/pages/global/optionsSlice' |
8 | 8 | import { Portal } from '@/components/Portal' |
9 | 9 | import { withPage } from '@/hoc' |
| 10 | +import { findElement } from '@/utils' |
| 11 | +import { HelpIcon } from '@/components/icons' |
10 | 12 |
|
11 | 13 | const GlobalStyle = createGlobalStyle` |
12 | 14 | body { |
@@ -109,7 +111,35 @@ const Variables = createGlobalStyle<{ |
109 | 111 | } |
110 | 112 | ` |
111 | 113 |
|
112 | | -export const OptimizedContestProblemsPage = (): JSX.Element => { |
| 114 | +const FeatureTips = () => { |
| 115 | + const [root, setRoot] = useState<HTMLElement | null>(null) |
| 116 | + |
| 117 | + useEffectMount(async state => { |
| 118 | + const languageSelectWrapper = await findElement('.language-select-wrapper') |
| 119 | + if (!state.isMount) return |
| 120 | + const root = document.createElement('div') |
| 121 | + root.style.margin = '15px 0' |
| 122 | + const control = languageSelectWrapper.parentElement?.parentElement |
| 123 | + if (control) { |
| 124 | + control.parentElement?.insertBefore(root, control) |
| 125 | + } |
| 126 | + setRoot(root) |
| 127 | + state.unmount.push(() => root.remove()) |
| 128 | + }, []) |
| 129 | + |
| 130 | + if (!root) return null |
| 131 | + |
| 132 | + return ( |
| 133 | + <Portal container={root}> |
| 134 | + <div style={{ display: 'flex', alignItems: 'center' }}> |
| 135 | + <HelpIcon width={'16px'} /> 提示:此布局由 Refined LeetCode |
| 136 | + 扩展提供,如需关闭,可以在扩展的配置选项中关闭。 |
| 137 | + </div> |
| 138 | + </Portal> |
| 139 | + ) |
| 140 | +} |
| 141 | + |
| 142 | +const OptimizedContestProblemsPage = (): JSX.Element => { |
113 | 143 | const options = useAppSelector(selectOptions) |
114 | 144 | const dispatch = useAppDispatch() |
115 | 145 |
|
@@ -196,6 +226,7 @@ export const OptimizedContestProblemsPage = (): JSX.Element => { |
196 | 226 | return ( |
197 | 227 | <> |
198 | 228 | {modifyPageLayout && <GlobalStyle />} |
| 229 | + {modifyPageLayout && <FeatureTips />} |
199 | 230 | <Variables |
200 | 231 | $layoutDirection={reverseLayout ? 'row-reverse' : 'row'} |
201 | 232 | $problemViewWidth={ |
|
0 commit comments