fix(LOY-53): scroll to top of current rewards on page change
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { useState } from "react"
|
import { useRef,useState } from "react"
|
||||||
|
|
||||||
import Image from "@/components/Image"
|
import Image from "@/components/Image"
|
||||||
import Pagination from "@/components/MyPages/Pagination"
|
import Pagination from "@/components/MyPages/Pagination"
|
||||||
@@ -18,6 +18,7 @@ export default function ClientCurrentRewards({
|
|||||||
pageSize,
|
pageSize,
|
||||||
showRedeem,
|
showRedeem,
|
||||||
}: CurrentRewardsClientProps) {
|
}: CurrentRewardsClientProps) {
|
||||||
|
const containerRef = useRef<HTMLDivElement>(null)
|
||||||
const [currentPage, setCurrentPage] = useState(1)
|
const [currentPage, setCurrentPage] = useState(1)
|
||||||
|
|
||||||
const totalPages = Math.ceil(rewards.length / pageSize)
|
const totalPages = Math.ceil(rewards.length / pageSize)
|
||||||
@@ -25,8 +26,19 @@ export default function ClientCurrentRewards({
|
|||||||
const endIndex = startIndex + pageSize
|
const endIndex = startIndex + pageSize
|
||||||
const currentRewards = rewards.slice(startIndex, endIndex)
|
const currentRewards = rewards.slice(startIndex, endIndex)
|
||||||
|
|
||||||
|
function handlePageChange(page: number) {
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
setCurrentPage(page)
|
||||||
|
containerRef.current?.scrollIntoView({
|
||||||
|
behavior: "smooth",
|
||||||
|
block: "start",
|
||||||
|
inline: "nearest",
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.container}>
|
<div ref={containerRef} className={styles.container}>
|
||||||
<Grids.Stackable>
|
<Grids.Stackable>
|
||||||
{currentRewards.map((reward, idx) => (
|
{currentRewards.map((reward, idx) => (
|
||||||
<article className={styles.card} key={`${reward.reward_id}-${idx}`}>
|
<article className={styles.card} key={`${reward.reward_id}-${idx}`}>
|
||||||
@@ -58,7 +70,7 @@ export default function ClientCurrentRewards({
|
|||||||
<Pagination
|
<Pagination
|
||||||
pageCount={totalPages}
|
pageCount={totalPages}
|
||||||
currentPage={currentPage}
|
currentPage={currentPage}
|
||||||
handlePageChange={setCurrentPage}
|
handlePageChange={handlePageChange}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -128,4 +128,6 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: var(--Spacing-x4);
|
gap: var(--Spacing-x4);
|
||||||
|
position: relative;
|
||||||
|
scroll-margin-top: calc(var(--current-mobile-site-header-height) * 2);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user