Validate input index before flipping page

This commit is contained in:
Alex Ling 2021-01-09 15:49:34 +00:00
parent 4a7439a1ea
commit f51d27860a

View File

@ -101,8 +101,9 @@ const readerComponent = () => {
*/ */
flipPage(isNext) { flipPage(isNext) {
const idx = parseInt(this.curItem.id); const idx = parseInt(this.curItem.id);
const delta = isNext ? 1 : -1; const newIdx = idx + (isNext ? 1 : -1);
const newIdx = idx + delta;
if (newIdx <= 0 || newIdx > this.items.length) return;
this.toPage(newIdx); this.toPage(newIdx);