Spaces:
Sleeping
Sleeping
Commit ·
d3a8b2a
1
Parent(s): a5c4b2c
fix: clamp restored pageIdx to valid range on doc change
Browse files- app/page.js +6 -0
app/page.js
CHANGED
|
@@ -95,6 +95,12 @@ export default function Home() {
|
|
| 95 |
const doc = documents.find(d => d.index === selectedDocIndex);
|
| 96 |
setCurrentDoc(doc);
|
| 97 |
sessionStorage.setItem('selectedDocIndex', selectedDocIndex);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
}
|
| 99 |
}, [selectedDocIndex, documents]);
|
| 100 |
|
|
|
|
| 95 |
const doc = documents.find(d => d.index === selectedDocIndex);
|
| 96 |
setCurrentDoc(doc);
|
| 97 |
sessionStorage.setItem('selectedDocIndex', selectedDocIndex);
|
| 98 |
+
|
| 99 |
+
// Clamp pageIdx to valid range for this document
|
| 100 |
+
if (doc) {
|
| 101 |
+
const maxPage = (doc.annotatable_pages?.length ?? 1) - 1;
|
| 102 |
+
setPageIdx(prev => Math.min(prev, Math.max(0, maxPage)));
|
| 103 |
+
}
|
| 104 |
}
|
| 105 |
}, [selectedDocIndex, documents]);
|
| 106 |
|