Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit fa2535d

Browse files
committed
chore: move waypoint load to client
1 parent e1c8fa6 commit fa2535d

File tree

10 files changed

+37
-24
lines changed

10 files changed

+37
-24
lines changed

src/components/CustomScroller/HorizontalScroller.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
import { FC, useState, useRef, useCallback, memo } from 'react'
88
import { useTheme } from 'styled-components'
9-
import { Waypoint } from 'react-waypoint'
109
import type { TThemeMap } from '@/spec'
1110

1211
import { buildLog } from '@/utils'
13-
import { SIZE } from '@/constant'
1412
import { useCustomScroll } from '@/hooks'
13+
import ViewportTracker from '@/components/ViewportTracker'
14+
import { SIZE } from '@/constant'
1515

1616
import type { TProps as TScrollProps } from './index'
1717

@@ -80,13 +80,13 @@ const HorizontalScroller: FC<TProps> = ({
8080

8181
<ScrollWrapper ref={ref}>
8282
<InnerWrapper innerHeight={innerHeight}>
83-
<Waypoint
83+
<ViewportTracker
8484
horizontal
8585
onEnter={handleHideLeftShadow}
8686
onLeave={handleShowLeftShadow}
8787
/>
8888
{children}
89-
<Waypoint
89+
<ViewportTracker
9090
horizontal
9191
onEnter={handleHideRightShadow}
9292
onLeave={handleShowRightShadow}

src/components/CustomScroller/VerticalScroller.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66

77
import { FC, useState, useRef, useCallback, memo } from 'react'
88
import { useTheme } from 'styled-components'
9-
import { Waypoint } from 'react-waypoint'
9+
1010
import type { TThemeMap } from '@/spec'
1111

1212
import { buildLog, debounce } from '@/utils'
1313
import { SIZE } from '@/constant'
1414
import { useCustomScroll } from '@/hooks'
15+
import ViewportTracker from '@/components/ViewportTracker'
1516

1617
import type { TProps as TScrollProps } from './index'
1718

@@ -137,9 +138,12 @@ const VerticalScroller: FC<TProps> = ({
137138
)}
138139

139140
<ScrollWrapper ref={ref}>
140-
<Waypoint onEnter={handleHideTopShadow} onLeave={handleShowTopShadow} />
141+
<ViewportTracker
142+
onEnter={handleHideTopShadow}
143+
onLeave={handleShowTopShadow}
144+
/>
141145
{children}
142-
<Waypoint
146+
<ViewportTracker
143147
onEnter={handleHideBottomShadow}
144148
onLeave={handleShowBottomShadow}
145149
/>

src/components/Modal/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
import { FC, ReactNode, useEffect, useState, useCallback, memo } from 'react'
88
import usePortal from 'react-useportal'
9-
import { Waypoint } from 'react-waypoint'
109

1110
import { ICON_CMD } from '@/config'
1211
import { buildLog, toggleGlobalBlur } from '@/utils'
1312
import { useShortcut } from '@/hooks'
1413

14+
import ViewportTracker from '@/components/ViewportTracker'
1515
import Belt from './Belt'
1616

1717
import { Mask, Wrapper, CloseBtn, EscHint, ChildrenWrapper } from './styles'
@@ -71,7 +71,7 @@ const Modal: FC<TProps> = ({
7171
background={background}
7272
offsetTop={offsetTop}
7373
>
74-
<Waypoint onEnter={() => setVisibleOnPage(true)} />
74+
<ViewportTracker onEnter={() => setVisibleOnPage(true)} />
7575
<CloseBtn
7676
mode={mode}
7777
src={`${ICON_CMD}/closeBtn.svg`}

src/components/ViewportTracker/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@ import { FC } from 'react'
44
import dynamic from 'next/dynamic'
55

66
type TProps = {
7+
/**
8+
* Function called when waypoint enters viewport
9+
*/
710
onEnter: () => void
811
/**
912
* Function called when waypoint leaves viewport
1013
*/
11-
onLeave: () => void
14+
onLeave?: () => void
15+
/**
16+
* Whether to activate on horizontal scrolling instead of vertical
17+
*/
18+
horizontal?: boolean
1219
}
1320

1421
const Waypoint = dynamic(

src/containers/content/ArticleContent/MobileView/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
import { FC } from 'react'
8-
import { Waypoint } from 'react-waypoint'
98

109
import { pluggedIn, buildLog } from '@/utils'
1110

@@ -14,6 +13,7 @@ import ArticleFooter from '@/containers/unit/ArticleFooter'
1413

1514
import Maybe from '@/components/Maybe'
1615
import MarkDownRender from '@/components/MarkDownRender'
16+
import ViewportTracker from '@/components/ViewportTracker'
1717

1818
import type { TStore } from '../store'
1919

@@ -50,7 +50,10 @@ const PostContentContainer: FC<TProps> = ({
5050
<ArticleWrapper>
5151
<MarkDownRender body={viewingArticle.body} />
5252
</ArticleWrapper>
53-
<Waypoint onEnter={articleInAnchor} onLeave={articleOutAnchor} />
53+
<ViewportTracker
54+
onEnter={articleInAnchor}
55+
onLeave={articleOutAnchor}
56+
/>
5457
<ArticleFooter />
5558
<CommentsWrapper>
5659
{/* @ts-ignore */}

src/containers/content/SponsorContent/Banner.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
*/
88

99
import React, { useState } from 'react'
10-
import { Waypoint } from 'react-waypoint'
1110

1211
import { buildLog } from '@/utils'
12+
import ViewportTracker from '@/components/ViewportTracker'
1313

1414
import {
1515
SmileWrapper,
@@ -42,14 +42,14 @@ const Banner = () => {
4242
return (
4343
<React.Fragment>
4444
<AnchorH>
45-
<Waypoint
45+
<ViewportTracker
4646
onEnter={() => setAnchorHEnter(true)}
4747
onLeave={() => setAnchorHEnter(false)}
4848
/>
4949
</AnchorH>
5050

5151
<AnchorM>
52-
<Waypoint
52+
<ViewportTracker
5353
onEnter={() => {
5454
setAnchorMEnter(true)
5555
toggleBannerVisiable(true)
@@ -62,7 +62,7 @@ const Banner = () => {
6262
</AnchorM>
6363

6464
<AnchorL>
65-
<Waypoint
65+
<ViewportTracker
6666
onEnter={() => setAnchorLEnter(true)}
6767
onLeave={() => setAnchorLEnter(false)}
6868
/>

src/containers/content/TrendingContent/styles/news_board.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export const Wrapper = styled.div`
77
width: 100%;
88
position: relative;
99
`
10-
// Waypoint hack
1110
export const ShadowBarHolder = styled.div`
1211
width: 1px;
1312
height: 100%;

src/containers/digest/ArticleDigest/MobileView/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66

77
import { FC } from 'react'
88
import { isNil } from 'ramda'
9-
import { Waypoint } from 'react-waypoint'
109

1110
import type { TScrollDirection } from '@/spec'
1211
import { useScroll } from '@/hooks'
1312
import { pluggedIn, buildLog } from '@/utils'
1413

1514
import ArticleBaseStats from '@/components/ArticleBaseStats'
15+
import ViewportTracker from '@/components/ViewportTracker'
16+
1617
import PublishDate from '../DesktopView/PostLayout/PublishDate'
1718

1819
import type { TStore } from '../store'
@@ -51,7 +52,7 @@ const ArticleDigestContainer: FC<TProps> = ({ articleDigest: store }) => {
5152
</Brief>
5253
</BannerContent>
5354
</InnerWrapper>
54-
<Waypoint onEnter={inAnchor} onLeave={outAnchor} />
55+
<ViewportTracker onEnter={inAnchor} onLeave={outAnchor} />
5556
</Wrapper>
5657
)
5758
}

src/containers/thread/ArticlesThread/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@
77
*/
88

99
import { FC } from 'react'
10-
import { Waypoint } from 'react-waypoint'
1110
import dynamic from 'next/dynamic'
1211

1312
import type { TResState } from '@/spec'
1413
import { C11N } from '@/constant'
1514
import { pluggedIn, buildLog } from '@/utils'
1615

1716
import PagedArticles from '@/components/PagedArticles'
17+
import ViewportTracker from '@/components/ViewportTracker'
1818
// import ArticlesFilter from '@/components/ArticlesFilter'
1919
import ThreadSidebar from '@/containers/thread/ThreadSidebar'
20-
import { LavaLampLoading } from '@/components/Loading'
2120

2221
import type { TStore } from './store'
2322

@@ -55,7 +54,7 @@ const ArticlesThreadContainer: FC<TProps> = ({ articlesThread: store }) => {
5554
return (
5655
<Wrapper>
5756
<MainWrapper>
58-
<Waypoint onEnter={inAnchor} onLeave={outAnchor} />
57+
<ViewportTracker onEnter={inAnchor} onLeave={outAnchor} />
5958
{showFilters && (
6059
<FilterWrapper>
6160
<ArticlesFilter

src/containers/thread/ReposThread/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
import React from 'react'
8-
import { Waypoint } from 'react-waypoint'
98

109
import { ICON_CMD } from '@/config'
1110
import { THREAD } from '@/constant'
@@ -18,6 +17,7 @@ import { PublishButton } from '@/components/Buttons'
1817
import PagedArticles from '@/components/PagedArticles'
1918
import ArticlesFilter from '@/components/ArticlesFilter'
2019
import Maybe from '@/components/Maybe'
20+
import ViewportTracker from '@/components/ViewportTracker'
2121

2222
import {
2323
Wrapper,
@@ -61,7 +61,7 @@ const ReposThreadContainer = ({ reposThread: store }) => {
6161
return (
6262
<Wrapper>
6363
<LeftPart>
64-
<Waypoint onEnter={inAnchor} onLeave={outAnchor} />
64+
<ViewportTracker onEnter={inAnchor} onLeave={outAnchor} />
6565
<Maybe test={showFilterBar}>
6666
<FilterWrapper>
6767
<ArticlesFilter

0 commit comments

Comments
 (0)