Server: Fix using "Show more books" button and then changing list mode setting causing resulting book list to be incomplete

This commit is contained in:
Kovid Goyal 2017-07-03 10:12:40 +05:30
parent f8cc5af61a
commit ebe2dca11a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 18 additions and 6 deletions

View File

@ -10,7 +10,7 @@ from utils import parse_url_params
from book_list.globals import get_session_data
load_status = {'loading':True, 'ok':False, 'error_html':None, 'current_fetch': None}
library_data = {'metadata':{}}
library_data = {'metadata':{}, 'previous_book_ids': v'[]'}
def current_library_id():
@ -71,6 +71,7 @@ def update_library_data(data):
load_status.loading = False
load_status.ok = True
load_status.error_html = None
library_data.previous_book_ids = v'[]'
for key in 'search_result sortable_fields field_metadata metadata virtual_libraries book_display_fields'.split(' '):
library_data[key] = data[key]
sr = library_data.search_result
@ -82,6 +83,19 @@ def update_library_data(data):
last_virtual_library_for.vl = None
def add_more_books(data):
for key in data.metadata:
library_data.metadata[key] = data.metadata[key]
sr = library_data.search_result
if sr and sr.book_ids and sr.book_ids.length > 0:
library_data.previous_book_ids = library_data.previous_book_ids.concat(sr.book_ids)
library_data.search_result = data.search_result
def current_book_ids():
return library_data.previous_book_ids.concat(library_data.search_result.book_ids)
def on_data_loaded(end_type, xhr, ev):
load_status.current_fetch = None
if end_type is 'load':

View File

@ -21,7 +21,7 @@ from book_list.item_list import create_item, create_item_list
from book_list.library_data import (
all_virtual_libraries, book_metadata, current_sorted_field,
ensure_current_library_data, library_data, load_status, loaded_books_query,
thumbnail_cache, url_books_query
thumbnail_cache, url_books_query, add_more_books, current_book_ids
)
from book_list.router import back, home, push_state, update_window_title
from book_list.search import (
@ -113,7 +113,7 @@ def render_id(book_id):
def render_ids(book_ids):
book_ids = book_ids or library_data.search_result.book_ids
book_ids = book_ids or current_book_ids()
div = component('book_list')
if div:
for book_id in book_ids:
@ -178,11 +178,9 @@ def got_more_books(end_type, xhr, event):
if end_type is 'load':
try:
data = JSON.parse(xhr.responseText)
for key in data.metadata:
library_data.metadata[key] = data.metadata[key]
if not data.search_result.book_ids:
raise Exception('No books ids object in search result from server')
library_data.search_result = data.search_result
add_more_books(data)
render_ids(data.search_result.book_ids)
except Exception:
error_dialog(_('Could not get more books'), _('Server returned an invalid response'), traceback.format_exc())