@@ -3,13 +3,25 @@ import { useMissingLocationContext } from "@/contexts/MissingLocationContext";
3
3
import { IMissingLocationDatesResponse } from "@/handlers/api/asset.handler" ;
4
4
import { parseDate , formatDate } from "@/helpers/date.helper" ;
5
5
import { cn } from "@/lib/utils" ;
6
- import React , { useMemo } from "react" ;
6
+ import React , { useEffect , useMemo , useRef } from "react" ;
7
7
8
8
interface IProps {
9
9
record : IMissingLocationDatesResponse ;
10
10
onSelect : ( date : string ) => void ;
11
11
}
12
12
export default function MissingLocationDateItem ( { record, onSelect } : IProps ) {
13
+
14
+ // Effect to handle scrolling after rendering
15
+ useEffect ( ( ) => {
16
+ if ( startDate === record . date ) {
17
+ itemsRef . current ?. scrollIntoView ( {
18
+ behavior : "smooth" , // Smooth scrolling
19
+ block : "center" , // Center the item in the view
20
+ } ) ;
21
+ }
22
+ } , [ ] ) ;
23
+
24
+ const itemsRef = useRef < HTMLDivElement | null > ( null ) ;
13
25
const { startDate } = useMissingLocationContext ( )
14
26
const dateLabel = useMemo ( ( ) => {
15
27
if ( ! record . date ) return "Unknown"
@@ -22,8 +34,9 @@ export default function MissingLocationDateItem({ record, onSelect }: IProps) {
22
34
key = { record . date }
23
35
className = {
24
36
cn ( "flex gap-1 flex-col p-2 py-1 rounded-lg hover:dark:bg-zinc-800 border border-transparent hover:bg-zinc-100 px-4" ,
25
- startDate === record . date ? "bg-zinc-100 dark:bg-zinc-800 border-gray-300 dark:border-zinc-700" : "" )
37
+ startDate === record . date ? "bg-zinc-100 dark:bg-zinc-800 border-gray-300 dark:border-zinc-700" : "" )
26
38
}
39
+ ref = { itemsRef }
27
40
>
28
41
< p className = "font-mono text-sm" > { dateLabel } </ p >
29
42
< p className = "text-xs text-foreground/50" > { record . asset_count } Orphan Assets</ p >
0 commit comments