Skip to content

Commit 9fe7b5b

Browse files
committed
pr review
1 parent caee27e commit 9fe7b5b

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/components/SplitViewer/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ function SplitViewer({
9898
)
9999

100100
const safeIndex = carouselItems.length === 0
101-
? 0
101+
? -1
102102
: (memoryIndex >= carouselItems.length ? carouselItems.length - 1 : memoryIndex)
103103

104104
// Dynamic centroid (always reflects current selected item)
105-
const dynamicCentroid = items[safeIndex] || items[0] || null
105+
const dynamicCentroid = (safeIndex === -1 || items.length === 0) ? null : items[safeIndex]
106106

107107
// Locked centroid used while map filter is ON (prevents panning / zooming with next/prev)
108108
const [lockedCentroid, setLockedCentroid] = useState<typeof dynamicCentroid>(dynamicCentroid)

src/hooks/useMemory.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ const useMemory = (
1717
refImageGallery: RefObject<ReactImageGallery | null>,
1818
options: MemoryOptions = { autoInitialView: true },
1919
) => {
20-
// Persist across map/keyword filter changes (no reset)
20+
const { autoInitialView = true } = options // destructure to stabilize dependency
2121
const [viewedList, setViewedList] = useState<Set<string>>(new Set())
2222
const [details, setDetails] = useState<Item | null>(filtered[0] ?? null)
2323

2424
const setViewed: Viewed = (index: number) => {
2525
const item = filtered[index] ?? null
2626
setDetails(item)
27-
if (!item || !item.id) return
27+
if (!item?.id) return
2828
setViewedList(prev => {
2929
if (prev.has(item.id)) return prev
3030
const next = new Set(prev)
@@ -34,8 +34,7 @@ const useMemory = (
3434
}
3535

3636
useEffect(() => {
37-
// Suppress automatic viewed marking if requested (during map filter enable reset)
38-
if (!options.autoInitialView) return
37+
if (!autoInitialView) return
3938
if (refImageGallery.current && filtered.length > 0) {
4039
const current = refImageGallery.current.getCurrentIndex()
4140
if (current >= 0) {
@@ -48,7 +47,7 @@ const useMemory = (
4847
} else {
4948
setDetails(null)
5049
}
51-
}, [filtered, refImageGallery, options.autoInitialView])
50+
}, [filtered, refImageGallery, autoInitialView])
5251

5352
const memoryHtml = details ? (
5453
<>

0 commit comments

Comments
 (0)