Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaa2a750

Browse files
committed
refactor scroll content
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent7810621 commitaa2a750

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

‎web-app/src/containers/Tutorial/components/Level.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,8 @@ type Props = {
3939
}
4040

4141
constLevel=({ level}:Props)=>{
42-
constpageTopRef=React.useRef(null)
43-
constscrollToTop=()=>{
44-
//@ts-ignore
45-
pageTopRef.current.scrollIntoView({behavior:'smooth'})
46-
}
47-
React.useEffect(scrollToTop,[level.id])
48-
4942
return(
5043
<divcss={styles.page}>
51-
<divref={pageTopRef}/>
5244
<divcss={styles.content}>
5345
<Contenttitle={level.title}content={level.content}/>
5446

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import*asReactfrom'react'
2+
3+
typeProps={
4+
item:string
5+
children:React.ReactElement
6+
}
7+
8+
constScrollContent=({ item, children}:Props)=>{
9+
constpageTopRef:React.RefObject<any>=React.useRef(null)
10+
11+
constpageBottomRef:React.RefObject<any>=React.useRef(null)
12+
13+
constscrollToTop=()=>{
14+
pageTopRef.current.scrollIntoView({behavior:'smooth'})
15+
}
16+
17+
React.useEffect(scrollToTop,[item])
18+
19+
return(
20+
<>
21+
<divref={pageTopRef}/>
22+
{children}
23+
<divref={pageBottomRef}/>
24+
</>
25+
)
26+
}
27+
28+
exportdefaultScrollContent

‎web-app/src/containers/Tutorial/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { DISPLAY_RUN_TEST_BUTTON } from '../../environment'
1313
importformatLevelsfrom'./formatLevels'
1414
importResetfrom'./components/Reset'
1515
importContinuefrom'./components/Continue'
16+
importScrollContentfrom'./components/ScrollContent'
1617

1718
conststyles={
1819
header:{
@@ -120,7 +121,11 @@ const TutorialPage = (props: PageProps) => {
120121
<spancss={styles.title}>{tutorial.summary.title}</span>
121122
</div>
122123

123-
{page==='level'&&<Levellevel={level}/>}
124+
{page==='level'&&(
125+
<ScrollContentitem={level.id}>
126+
<Levellevel={level}/>
127+
</ScrollContent>
128+
)}
124129
{page==='review'&&<ReviewPagelevels={levels}/>}
125130
{/* {page === 'settings' && <SettingsPage />} */}
126131
</div>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp