Skip to content

Commit

Permalink
Content server: Add Next/Previous buttons to the book details page
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed Jan 30, 2019
1 parent 768774a commit 6fc6abc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
17 changes: 16 additions & 1 deletion src/pyj/book_list/book_details.pyj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ from book_list.delete_book import refresh_after_delete, start_delete_book
from book_list.globals import get_session_data
from book_list.item_list import create_item, create_item_list
from book_list.library_data import (
all_libraries, book_metadata, cover_url, current_library_id,
all_libraries, book_after, book_metadata, cover_url, current_library_id,
current_virtual_library, download_url, library_data, load_status,
set_book_metadata
)
Expand Down Expand Up @@ -465,6 +465,21 @@ def render_book(container_id, book_id):
table = E.table(class_='metadata')
container.appendChild(md)
md.appendChild(table)

def next_book(delta):
next_book_id = book_after(book_id, delta)
if next_book_id:
q = parse_url_params()
q.book_id = next_book_id + ''
show_panel('book_details', query=q)

md.appendChild(E.div(
style='margin-top: 1.5ex',
create_button(_('Previous'), 'arrow-left', next_book.bind(None, -1)),
'\xa0\xa0\xa0',
create_button(_('Next'), 'arrow-right', next_book.bind(None, 1)),
))

render_metadata(metadata, table, book_id)


Expand Down
10 changes: 5 additions & 5 deletions src/pyj/book_list/library_data.pyj
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ def current_book_ids():
return library_data.previous_book_ids.concat(library_data.search_result.book_ids)


def book_after(book_id):
def book_after(book_id, delta):
if not delta:
delta = 1
ids = current_book_ids()
idx = ids.indexOf(int(book_id))
if idx > -1:
if idx < ids.length - 1:
return ids[idx + 1]
if idx > 0: # wrap around
return ids[0]
new_idx = (idx + ids.length + delta) % ids.length
return ids[new_idx]


def on_data_loaded(end_type, xhr, ev):
Expand Down

0 comments on commit 6fc6abc

Please sign in to comment.