mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Auto-refresh book list after adding books
This commit is contained in:
parent
8a793eb063
commit
72deb18b6f
@ -6,7 +6,7 @@ from elementmaker import E
|
||||
from gettext import gettext as _
|
||||
|
||||
from ajax import ajax_send_file
|
||||
from book_list.library_data import loaded_books_query
|
||||
from book_list.library_data import force_refresh_on_next_load, loaded_books_query
|
||||
from book_list.router import back
|
||||
from book_list.top_bar import create_top_bar
|
||||
from book_list.ui import query_as_href, show_panel
|
||||
@ -94,6 +94,7 @@ def on_complete(container_id, job_id, end_type, xhr, ev):
|
||||
data = JSON.parse(xhr.responseText)
|
||||
if data.book_id:
|
||||
list_added_book(container, data)
|
||||
force_refresh_on_next_load()
|
||||
else:
|
||||
list_duplicate_book(container, container_id, job_id, data, this)
|
||||
elif end_type is 'abort':
|
||||
|
@ -11,7 +11,7 @@ from session import get_interface_data
|
||||
from utils import parse_url_params
|
||||
|
||||
load_status = {'loading':True, 'ok':False, 'error_html':None, 'current_fetch': None}
|
||||
library_data = {'metadata':{}, 'previous_book_ids': v'[]'}
|
||||
library_data = {'metadata':{}, 'previous_book_ids': v'[]', 'force_refresh': False}
|
||||
|
||||
|
||||
def current_library_id():
|
||||
@ -156,20 +156,31 @@ def set_book_metadata(book_id, value):
|
||||
library_data.metadata[book_id] = value
|
||||
|
||||
|
||||
def force_refresh_on_next_load():
|
||||
library_data.force_refresh = True
|
||||
|
||||
|
||||
def ensure_current_library_data():
|
||||
q = url_books_query()
|
||||
loaded = loaded_books_query()
|
||||
matches = True
|
||||
fr = library_data.force_refresh
|
||||
library_data.force_refresh = False
|
||||
|
||||
def is_same(a, b):
|
||||
if not a and not b:
|
||||
return True
|
||||
return a is b
|
||||
|
||||
for key in q:
|
||||
if not is_same(q[key], loaded[key]):
|
||||
matches = False
|
||||
break
|
||||
|
||||
if fr:
|
||||
matches = False
|
||||
else:
|
||||
q = url_books_query()
|
||||
loaded = loaded_books_query()
|
||||
matches = True
|
||||
|
||||
for key in q:
|
||||
if not is_same(q[key], loaded[key]):
|
||||
matches = False
|
||||
break
|
||||
if not matches:
|
||||
fetch_init_data()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user