vmi-virtual-memorial/vmi-wd-frontend / 1512361

Browse files

fix scroll on paginate change

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
15123612ba78ff1fc3c9ae4d9e3cf96de31a74b6
Parents
c2064dd
Tree
c31f5ce

1 changed file

StatusFile+-
M app/memorial/conflict/[id]/page.tsx 7 4
app/memorial/conflict/[id]/page.tsxmodified
@@ -1,6 +1,6 @@
11
 'use client';
22
 
3
-import { useState, useEffect } from 'react';
3
+import { useState, useEffect, useRef } from 'react';
44
 import Link from 'next/link';
55
 import { useParams } from 'next/navigation';
66
 import { getConflicts, getPeopleByConflict, Conflict, PersonDetail } from '@/lib/api';
@@ -19,6 +19,9 @@ export default function ConflictPage() {
1919
   const [currentPage, setCurrentPage] = useState(1);
2020
   const [itemsPerPage, setItemsPerPage] = useState(30);
2121
 
22
+  // Ref for scrolling to top of results list
23
+  const resultsRef = useRef<HTMLDivElement>(null);
24
+
2225
 useEffect(() => {
2326
     async function fetchData() {
2427
       try {
@@ -52,8 +55,8 @@ useEffect(() => {
5255
   // Handlers for pagination
5356
   const handlePageChange = (page: number) => {
5457
     setCurrentPage(page);
55
-    // Scroll to top of results
56
-    window.scrollTo({ top: 0, behavior: 'smooth' });
58
+    // Scroll to top of results list
59
+    resultsRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' });
5760
   };
5861
 
5962
   const handleItemsPerPageChange = (newItemsPerPage: number) => {
@@ -114,7 +117,7 @@ useEffect(() => {
114117
         </div>
115118
 
116119
         {/* People List */}
117
-        <div className="bg-white border-2 border-gray-300 rounded-lg p-8 shadow-xl">
120
+        <div ref={resultsRef} className="bg-white border-2 border-gray-300 rounded-lg p-8 shadow-xl">
118121
           <h2 className="text-3xl font-bold mb-8 text-center text-vmi-red">
119122
             Honor Roll
120123
           </h2>