Skip to content

Commit 9b06126

Browse files
committed
scroll date from querystring into view
1 parent b365e7d commit 9b06126

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/components/assets/missing-location/MissingLocationDateItem.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,25 @@ import { useMissingLocationContext } from "@/contexts/MissingLocationContext";
33
import { IMissingLocationDatesResponse } from "@/handlers/api/asset.handler";
44
import { parseDate, formatDate } from "@/helpers/date.helper";
55
import { cn } from "@/lib/utils";
6-
import React, { useMemo } from "react";
6+
import React, { useEffect, useMemo, useRef } from "react";
77

88
interface IProps {
99
record: IMissingLocationDatesResponse;
1010
onSelect: (date: string) => void;
1111
}
1212
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);
1325
const { startDate } = useMissingLocationContext()
1426
const dateLabel = useMemo(() => {
1527
if (!record.date) return "Unknown"
@@ -22,8 +34,9 @@ export default function MissingLocationDateItem({ record, onSelect }: IProps) {
2234
key={record.date}
2335
className={
2436
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" : "")
2638
}
39+
ref={itemsRef}
2740
>
2841
<p className="font-mono text-sm">{dateLabel}</p>
2942
<p className="text-xs text-foreground/50">{record.asset_count} Orphan Assets</p>

0 commit comments

Comments
 (0)