Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fea4829

Browse files
committed
fix(problems): 添加提示
1 parent cbe1d23 commit fea4829

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

src/content/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import ShortcutKeyOption from './pages/problems/ShortcutKeyOption'
88
import Problemset from './pages/problemset/App'
99
import ProblemList from './pages/problem-list/App'
1010
import { customEventDispatch } from './utils'
11-
import { OptimizedContestProblemsPage } from '@/pages/problems/OptimizedContestProblemsPage'
11+
import OptimizedContestProblemsPage from '@/pages/problems/OptimizedContestProblemsPage'
1212

1313
const App: FC = () => {
1414
customEventDispatch('refinedLeetcodeGetOptions')

src/content/pages/problems/OptimizedContestProblemsPage.tsx

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { createGlobalStyle } from 'styled-components/macro'
2-
import { useAppDispatch, useAppSelector } from '@/hooks'
2+
import { useAppDispatch, useAppSelector, useEffectMount } from '@/hooks'
33
import { useCallback, useEffect, useState } from 'react'
44
import {
55
selectOptions,
66
setContestProblemViewWidth,
77
} from '@/pages/global/optionsSlice'
88
import { Portal } from '@/components/Portal'
99
import { withPage } from '@/hoc'
10+
import { findElement } from '@/utils'
11+
import { HelpIcon } from '@/components/icons'
1012

1113
const GlobalStyle = createGlobalStyle`
1214
body {
@@ -109,7 +111,35 @@ const Variables = createGlobalStyle<{
109111
}
110112
`
111113

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 => {
113143
const options = useAppSelector(selectOptions)
114144
const dispatch = useAppDispatch()
115145

@@ -196,6 +226,7 @@ export const OptimizedContestProblemsPage = (): JSX.Element => {
196226
return (
197227
<>
198228
{modifyPageLayout && <GlobalStyle />}
229+
{modifyPageLayout && <FeatureTips />}
199230
<Variables
200231
$layoutDirection={reverseLayout ? 'row-reverse' : 'row'}
201232
$problemViewWidth={

0 commit comments

Comments
 (0)