@@ -1,6 +1,6 @@ |
| 1 | 1 | 'use client'; |
| 2 | 2 | |
| 3 | | -import { useState, useEffect } from 'react'; |
| 3 | +import { useState, useEffect, useRef } from 'react'; |
| 4 | 4 | import Link from 'next/link'; |
| 5 | 5 | import { useParams } from 'next/navigation'; |
| 6 | 6 | import { getConflicts, getPeopleByConflict, Conflict, PersonDetail } from '@/lib/api'; |
@@ -19,6 +19,9 @@ export default function ConflictPage() { |
| 19 | 19 | const [currentPage, setCurrentPage] = useState(1); |
| 20 | 20 | const [itemsPerPage, setItemsPerPage] = useState(30); |
| 21 | 21 | |
| 22 | + // Ref for scrolling to top of results list |
| 23 | + const resultsRef = useRef<HTMLDivElement>(null); |
| 24 | + |
| 22 | 25 | useEffect(() => { |
| 23 | 26 | async function fetchData() { |
| 24 | 27 | try { |
@@ -52,8 +55,8 @@ useEffect(() => { |
| 52 | 55 | // Handlers for pagination |
| 53 | 56 | const handlePageChange = (page: number) => { |
| 54 | 57 | 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' }); |
| 57 | 60 | }; |
| 58 | 61 | |
| 59 | 62 | const handleItemsPerPageChange = (newItemsPerPage: number) => { |
@@ -114,7 +117,7 @@ useEffect(() => { |
| 114 | 117 | </div> |
| 115 | 118 | |
| 116 | 119 | {/* 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"> |
| 118 | 121 | <h2 className="text-3xl font-bold mb-8 text-center text-vmi-red"> |
| 119 | 122 | Honor Roll |
| 120 | 123 | </h2> |