11import { useRouter } from 'next/router'
22import { useState , useRef , useEffect , useCallback , useMemo } from 'react'
33import styles from './pull-to-refresh.module.css'
4+ import NProgress from 'nprogress'
45
56const REFRESH_THRESHOLD = 150
67
@@ -41,7 +42,7 @@ export default function PullToRefresh ({ children, className }) {
4142 clearPullDistance ( )
4243 return
4344 }
44-
45+ e . preventDefault ( )
4546 touchEndY . current = e . touches [ 0 ] . clientY
4647 const distance = touchEndY . current - touchStartY . current
4748 setPullDistance ( distance )
@@ -51,16 +52,17 @@ export default function PullToRefresh ({ children, className }) {
5152 const handleTouchEnd = useCallback ( ( ) => {
5253 if ( touchStartY . current === 0 || touchEndY . current === 0 ) return
5354 if ( touchEndY . current - touchStartY . current > REFRESH_THRESHOLD ) {
54- router . push ( router . asPath )
55+ NProgress . done ( )
56+ router . replace ( router . asPath )
5557 }
5658 clearPullDistance ( )
5759 } , [ router ] )
5860
5961 useEffect ( ( ) => {
6062 if ( ! isPWA ) return
6163 document . body . style . overscrollBehaviorY = 'contain'
62- document . addEventListener ( 'touchstart' , handleTouchStart )
63- document . addEventListener ( 'touchmove' , handleTouchMove )
64+ document . addEventListener ( 'touchstart' , handleTouchStart , { passive : false } )
65+ document . addEventListener ( 'touchmove' , handleTouchMove , { passive : false } )
6466 document . addEventListener ( 'touchend' , handleTouchEnd )
6567 return ( ) => {
6668 document . body . style . overscrollBehaviorY = ''
0 commit comments