-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new search implementation in the index root route + its conditionall …
…custom scrollrestoration component instead of remix.run's provided +fixes +edits
- Loading branch information
Showing
7 changed files
with
223 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { useLocation } from '@remix-run/react' | ||
import { useLayoutEffect, useRef, useMemo } from 'react' | ||
|
||
export function CustomScrollRestoration() { | ||
const { pathname, search } = useLocation() | ||
const scrollPositions = useRef<{ [key: string]: number }>({}) | ||
|
||
const paths = useMemo(() => ['/', '', '/?search='], []) | ||
|
||
// Only store scroll position for the specific routes | ||
useLayoutEffect(() => { | ||
if (paths.includes(pathname)) { | ||
scrollPositions.current[pathname + search] = window.scrollY | ||
} | ||
}, [pathname, search, paths]) | ||
|
||
// Only restore scroll position for the specific routes | ||
useLayoutEffect(() => { | ||
if (paths.includes(pathname)) { | ||
const storedPosition = scrollPositions.current[pathname + search] | ||
window.scrollTo(0, storedPosition || 0) | ||
} else { | ||
window.scrollTo(0, 0) // Scroll to top in other routes than "paths" | ||
} | ||
}, [pathname, search, paths]) | ||
|
||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters