mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
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:
parent
f8cc5af61a
commit
ebe2dca11a
@ -10,7 +10,7 @@ from utils import parse_url_params
|
|||||||
from book_list.globals import get_session_data
|
from book_list.globals import get_session_data
|
||||||
|
|
||||||
load_status = {'loading':True, 'ok':False, 'error_html':None, 'current_fetch': None}
|
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():
|
def current_library_id():
|
||||||
@ -71,6 +71,7 @@ def update_library_data(data):
|
|||||||
load_status.loading = False
|
load_status.loading = False
|
||||||
load_status.ok = True
|
load_status.ok = True
|
||||||
load_status.error_html = None
|
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(' '):
|
for key in 'search_result sortable_fields field_metadata metadata virtual_libraries book_display_fields'.split(' '):
|
||||||
library_data[key] = data[key]
|
library_data[key] = data[key]
|
||||||
sr = library_data.search_result
|
sr = library_data.search_result
|
||||||
@ -82,6 +83,19 @@ def update_library_data(data):
|
|||||||
last_virtual_library_for.vl = None
|
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):
|
def on_data_loaded(end_type, xhr, ev):
|
||||||
load_status.current_fetch = None
|
load_status.current_fetch = None
|
||||||
if end_type is 'load':
|
if end_type is 'load':
|
||||||
|
@ -21,7 +21,7 @@ from book_list.item_list import create_item, create_item_list
|
|||||||
from book_list.library_data import (
|
from book_list.library_data import (
|
||||||
all_virtual_libraries, book_metadata, current_sorted_field,
|
all_virtual_libraries, book_metadata, current_sorted_field,
|
||||||
ensure_current_library_data, library_data, load_status, loaded_books_query,
|
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.router import back, home, push_state, update_window_title
|
||||||
from book_list.search import (
|
from book_list.search import (
|
||||||
@ -113,7 +113,7 @@ def render_id(book_id):
|
|||||||
|
|
||||||
|
|
||||||
def render_ids(book_ids):
|
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')
|
div = component('book_list')
|
||||||
if div:
|
if div:
|
||||||
for book_id in book_ids:
|
for book_id in book_ids:
|
||||||
@ -178,11 +178,9 @@ def got_more_books(end_type, xhr, event):
|
|||||||
if end_type is 'load':
|
if end_type is 'load':
|
||||||
try:
|
try:
|
||||||
data = JSON.parse(xhr.responseText)
|
data = JSON.parse(xhr.responseText)
|
||||||
for key in data.metadata:
|
|
||||||
library_data.metadata[key] = data.metadata[key]
|
|
||||||
if not data.search_result.book_ids:
|
if not data.search_result.book_ids:
|
||||||
raise Exception('No books ids object in search result from server')
|
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)
|
render_ids(data.search_result.book_ids)
|
||||||
except Exception:
|
except Exception:
|
||||||
error_dialog(_('Could not get more books'), _('Server returned an invalid response'), traceback.format_exc())
|
error_dialog(_('Could not get more books'), _('Server returned an invalid response'), traceback.format_exc())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user