Skip to content

Commit

Permalink
Merge branch 'master' of github.com:codedread/kthoom
Browse files Browse the repository at this point in the history
  • Loading branch information
codedread committed Jul 24, 2023
2 parents 7662240 + 0f18fb1 commit 899bf17
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
7 changes: 6 additions & 1 deletion code/kthoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -1314,10 +1314,15 @@ export class KthoomApp {
}

/**
* @param {Book} book
* @param {Book} book If null, kthoom closes all books and resets state.
* @private
*/
handleCurrentBookChanged_(book) {
if (!book) {
this.closeAll_();
return;
}

if (book !== this.currentBook_) {
this.bookViewer_.closeBook();
// Download menu option is not available until the book is fully downloaded.
Expand Down
23 changes: 19 additions & 4 deletions code/reading-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,13 @@ export class ReadingStack {

/** @param {number} i */
removeBook(i) {
// Cannot remove the very last book.
if (this.books_.length > 1 && i < this.books_.length) {
// If removing the last book, signal that kthoom should close and reset state.
if (this.books_.length === 1) {
this.changeToBook_(-1);
return;
}

if (i < this.books_.length) {
this.books_[i].removeEventListener(BookEventType.LOADING_STARTED, this);
this.books_.splice(i, 1);

Expand All @@ -148,7 +153,9 @@ export class ReadingStack {
i = this.books_.length - 1;
}

this.currentBookNum_ = -1;
this.changeToBook_(i);
this.renderStack_();
} else {
// Might have to update the current book number if the book removed
// was above the current one.
Expand Down Expand Up @@ -195,10 +202,18 @@ export class ReadingStack {
}

/**
* @param {number} i
* @param {number} i If -1, then it signals kthoom to close all books and reset state.
* @private
*/
changeToBook_(i) {
if (i === -1) {
this.currentBookNum_ = i;
for (const callback of this.currentBookChangedCallbacks_) {
callback(null);
}
return;
}

if (i >= 0 && i < this.books_.length && this.currentBookNum_ != i) {
this.currentBookNum_ = i;
const book = this.books_[i];
Expand All @@ -218,7 +233,7 @@ export class ReadingStack {
}
}

// Instead of completely re-rendering, just update the currently selectded book, if we
// Instead of completely re-rendering, just update the currently selected book, if we
// already have a DOM.
const contents = getElem('readingStackContents');
const currentlySelectedBookDiv = contents.querySelector('div.readingStackBook.current');
Expand Down

0 comments on commit 899bf17

Please sign in to comment.