Don't scroll to top on search change except on home

This commit is contained in:
James Grugett 2022-08-18 11:23:16 -05:00
parent d216b298ba
commit 097000c9da
2 changed files with 4 additions and 1 deletions

View File

@ -91,6 +91,7 @@ export function ContractSearch(props: {
headerClassName?: string headerClassName?: string
useQuerySortLocalStorage?: boolean useQuerySortLocalStorage?: boolean
useQuerySortUrlParams?: boolean useQuerySortUrlParams?: boolean
isWholePage?: boolean
}) { }) {
const { const {
user, user,
@ -105,6 +106,7 @@ export function ContractSearch(props: {
headerClassName, headerClassName,
useQuerySortLocalStorage, useQuerySortLocalStorage,
useQuerySortUrlParams, useQuerySortUrlParams,
isWholePage,
} = props } = props
const [numPages, setNumPages] = useState(1) const [numPages, setNumPages] = useState(1)
@ -139,7 +141,7 @@ export function ContractSearch(props: {
setNumPages(results.nbPages) setNumPages(results.nbPages)
if (freshQuery) { if (freshQuery) {
setPages([newPage]) setPages([newPage])
window.scrollTo(0, 0) if (isWholePage) window.scrollTo(0, 0)
} else { } else {
setPages((pages) => [...pages, newPage]) setPages((pages) => [...pages, newPage])
} }

View File

@ -45,6 +45,7 @@ const Home = (props: { auth: { user: User } | null }) => {
// Update the url without switching pages in Nextjs. // Update the url without switching pages in Nextjs.
history.pushState(null, '', `/${c.creatorUsername}/${c.slug}`) history.pushState(null, '', `/${c.creatorUsername}/${c.slug}`)
}} }}
isWholePage
/> />
</Col> </Col>
<button <button