diff --git a/public/js/reader.js b/public/js/reader.js index c6a00b5..1aa1bd1 100644 --- a/public/js/reader.js +++ b/public/js/reader.js @@ -9,6 +9,7 @@ const readerComponent = () => { flipAnimation: null, longPages: false, lastSavedPage: page, + selectedIndex: 0, // 0: not selected; 1: the first page /** * Initialize the component by fetching the page dimensions @@ -221,10 +222,7 @@ const readerComponent = () => { */ showControl(event) { const idx = event.currentTarget.id; - const pageCount = this.items.length; - const progressText = `Progress: ${idx}/${pageCount} (${(idx/pageCount * 100).toFixed(1)}%)`; - $('#progress-label').text(progressText); - $('#page-select').val(idx); + this.selectedIndex = idx; UIkit.modal($('#modal-sections')).show(); }, /** @@ -263,19 +261,22 @@ const readerComponent = () => { }); }, /** - * Exits the reader, and optionally sets the reading progress tp 100% + * Exits the reader, and sets the reading progress tp 100% * * @param {string} exitUrl - The Exit URL - * @param {boolean} [markCompleted] - Whether we should mark the - * reading progress to 100% */ - exitReader(exitUrl, markCompleted = false) { - if (!markCompleted) { - return this.redirect(exitUrl); - } + exitReader(exitUrl) { this.saveProgress(this.items.length, () => { this.redirect(exitUrl); }); + }, + + /** + * Handles the `change` event for the entry selector + */ + entryChanged() { + const id = $('#entry-select').val(); + this.redirect(`${base_url}reader/${tid}/${id}`); } }; } diff --git a/src/library/entry.cr b/src/library/entry.cr index 7a4e753..cb45895 100644 --- a/src/library/entry.cr +++ b/src/library/entry.cr @@ -134,10 +134,11 @@ class Entry entries[idx + 1] end - def previous_entry - idx = @book.entries.index self + def previous_entry(username) + entries = @book.sorted_entries username + idx = entries.index self return nil if idx.nil? || idx == 0 - @book.entries[idx - 1] + entries[idx - 1] end def date_added diff --git a/src/library/library.cr b/src/library/library.cr index 83c0b0a..7e97e85 100644 --- a/src/library/library.cr +++ b/src/library/library.cr @@ -121,7 +121,7 @@ class Library # Get the last read time of the entry. If it hasn't been started, get # the last read time of the previous entry last_read = e.load_last_read username - pe = e.previous_entry + pe = e.previous_entry username if last_read.nil? && pe last_read = pe.load_last_read username end diff --git a/src/routes/reader.cr b/src/routes/reader.cr index e61b9a0..40b86aa 100644 --- a/src/routes/reader.cr +++ b/src/routes/reader.cr @@ -30,6 +30,11 @@ struct ReaderRouter title = (Library.default.get_title env.params.url["title"]).not_nil! entry = (title.get_entry env.params.url["entry"]).not_nil! + + sort_opt = SortOptions.from_info_json title.dir, username + get_sort_opt + entries = title.sorted_entries username, sort_opt + page_idx = env.params.url["page"].to_i if page_idx > entry.pages || page_idx <= 0 raise "Page #{page_idx} not found." @@ -37,10 +42,12 @@ struct ReaderRouter exit_url = "#{base_url}book/#{title.id}" - next_entry_url = nil - next_entry = entry.next_entry username - unless next_entry.nil? - next_entry_url = "#{base_url}reader/#{title.id}/#{next_entry.id}" + next_entry_url = entry.next_entry(username).try do |e| + "#{base_url}reader/#{title.id}/#{e.id}" + end + + previous_entry_url = entry.previous_entry(username).try do |e| + "#{base_url}reader/#{title.id}/#{e.id}" end render "src/views/reader.html.ecr" diff --git a/src/views/reader.html.ecr b/src/views/reader.html.ecr index 90cc78a..0b4ee4d 100644 --- a/src/views/reader.html.ecr +++ b/src/views/reader.html.ecr @@ -36,7 +36,7 @@ <%- if next_entry_url -%> <%- else -%> - + <%- end -%> @@ -68,12 +68,12 @@