Skip to content

Commit

Permalink
Fixes for viewer paginator
Browse files Browse the repository at this point in the history
  • Loading branch information
allanlasser committed Feb 22, 2024
1 parent 33c864f commit c4d0890
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
27 changes: 9 additions & 18 deletions src/common/Paginator.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@
const dispatch = createEventDispatcher();
let input: HTMLInputElement;
let inputValue: number = page;
$: inputWidth = String(inputValue ?? 0).length;
$: invalidValue = inputValue > totalPages || !inputValue;
$: {
inputValue = page;
}
$: inputWidth = String(page ?? 0).length;
$: invalidValue = page > totalPages || !page;
export function previous() {
dispatch("previous");
Expand All @@ -36,13 +32,11 @@
dispatch("goTo", page);
}
function handleChange() {
if (invalidValue || inputValue === page) {
inputValue = page;
return;
}
console.log(inputValue);
goTo(inputValue);
function handleChange(event: Event) {
if (invalidValue) return;
console.debug("Paginator: Page changed to ", page);
const { value } = event.target as HTMLInputElement;
goTo(parseInt(value));
}
function handleKeyup({ key }: KeyboardEvent) {
Expand All @@ -53,10 +47,7 @@
input.blur();
break;
// case "Enter":
// if (invalidValue) {
// inputValue = page;
// } else if (inputValue !== page) {
// goTo(inputValue);
// goTo(page);
// }
// input.blur();
// break;
Expand Down Expand Up @@ -104,7 +95,7 @@
min="1"
max={totalPages}
bind:this={input}
bind:value={inputValue}
bind:value={page}
on:change={handleChange}
on:keyup={handleKeyup}
style={`width: ${inputWidth}ch`}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/viewer/controls/Paginator.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{#if $viewer.loaded && $doc.mode !== "search" && $doc.mode !== "notes" && $doc.mode !== "thumbnail"}
<Paginator
page={$doc.visiblePageNumber}
pageTotal={$viewer.document.pageCount}
totalPages={$viewer.document.pageCount}
on:previous={decrement}
on:next={increment}
on:goTo={gotoPage}
Expand Down

0 comments on commit c4d0890

Please sign in to comment.