Skip to content

Commit

Permalink
Scroll to top on page change, fix estimate to pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Evalir committed Aug 27, 2020
1 parent 7a5993c commit 7e6d5e5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
10 changes: 1 addition & 9 deletions src/components/Main.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
import React, { useCallback, useEffect } from 'react'
import React from 'react'
import { Main } from '@aragon/ui'
import { useAppState } from '../providers/AppState'

export default function MainWrapper({ children }) {
const { appearance } = useAppState()

const scrollTop = useCallback(() => window.scrollTo(0, 0), [])

useEffect(() => {
window.addEventListener('beforeunload', scrollTop)

return () => window.removeEventListener('beforeunload', scrollTop)
}, [scrollTop])

return (
<Main assetsUrl="./aragon-ui/" layout={false} theme={appearance}>
{children}
Expand Down
2 changes: 1 addition & 1 deletion src/components/MainView.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function MainView({ children }) {
position: relative;
z-index: 100;
width: 100%;
height: 100vh;
min-height: 100vh;
background: no-repeat center/170px url(/splash_1.svg),
linear-gradient(289.78deg, #01E8F7 18.35%, #00C2FF 80.68%); !important
Expand Down
2 changes: 1 addition & 1 deletion src/components/ProposalsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import IdentityBadge from './IdentityBadge'
import { Amount } from '../screens/ProposalDetail'
import { ZERO_ADDR } from '../constants'

const PROPOSALS_PER_PAGE = 5
const PROPOSALS_PER_PAGE = 10

function ProposalsView({ proposals, requestToken }) {
const [page, setPage] = useState(0)
Expand Down
13 changes: 13 additions & 0 deletions src/components/ScrollTop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useEffect } from 'react'
import { useLocation } from 'react-router-dom'

export default function ScrollToTop() {
const { pathname } = useLocation()

useEffect(() => {
document.querySelector('body').scrollY = 0
window.scrollY = 0
}, [pathname])

return null
}
2 changes: 1 addition & 1 deletion src/hooks/useBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useWallet } from '../providers/Wallet'
import { getNetwork } from '../networks'

const NETWORK_TIMES = new Map([
['main', 13],
['mainnet', 13],
['kovan', 4],
['rinkeby', 14],
['ropsten', 11],
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as Sentry from '@sentry/browser'
import App from './App'
import Main from './components/Main'
import MainView from './components/MainView'
import ScrollTop from './components/ScrollTop'
import { WalletProvider } from './providers/Wallet'
import { AppStateProvider } from './providers/AppState'
import env from './environment'
Expand All @@ -24,6 +25,7 @@ ReactDOM.render(
<AppStateProvider>
<ViewportProvider>
<HashRouter>
<ScrollTop />
<Main>
<MainView>
<App />
Expand Down

0 comments on commit 7e6d5e5

Please sign in to comment.