mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Make showing recently read for user a bit more robust
This commit is contained in:
parent
2e15b0549b
commit
dd666a8778
@ -169,8 +169,7 @@ def basic_interface_data(ctx, rd):
|
|||||||
}
|
}
|
||||||
ans['library_map'], ans['default_library_id'] = ctx.library_info(rd)
|
ans['library_map'], ans['default_library_id'] = ctx.library_info(rd)
|
||||||
if ans['username']:
|
if ans['username']:
|
||||||
lrc = last_read_cache()
|
ans['recently_read_by_user'] = tuple(x for x in last_read_cache().get_recently_read(ans['username']) if x['library_id'] in ans['library_map'])
|
||||||
ans['recently_read_by_user'] = lrc.get_recently_read(ans['username'])
|
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,6 +33,13 @@ add_extra_css(def():
|
|||||||
return ans
|
return ans
|
||||||
)
|
)
|
||||||
|
|
||||||
|
recently_read_by_user = {'updated': False}
|
||||||
|
|
||||||
|
|
||||||
|
def update_recently_read_by_user(items):
|
||||||
|
recently_read_by_user.items = items
|
||||||
|
recently_read_by_user.updated = True
|
||||||
|
|
||||||
|
|
||||||
def show_cover(blob, name, mt, book):
|
def show_cover(blob, name, mt, book):
|
||||||
img = document.getElementById(this)
|
img = document.getElementById(this)
|
||||||
@ -117,10 +124,10 @@ def prepare_recent_container(container):
|
|||||||
return cover_container
|
return cover_container
|
||||||
|
|
||||||
|
|
||||||
def show_recent_for_user(container_id, interface_data):
|
def show_recent_for_user(container_id):
|
||||||
container = document.getElementById(container_id)
|
container = document.getElementById(container_id)
|
||||||
images = prepare_recent_container(container)
|
images = prepare_recent_container(container)
|
||||||
for item in interface_data.recently_read_by_user[:3]:
|
for item in recently_read_by_user.items[:3]:
|
||||||
q = {'library_id': item.library_id}
|
q = {'library_id': item.library_id}
|
||||||
if item.cfi:
|
if item.cfi:
|
||||||
q.bookpos = item.cfi
|
q.bookpos = item.cfi
|
||||||
@ -160,6 +167,15 @@ def show_recent_stage2(books):
|
|||||||
start_sync(to_sync)
|
start_sync(to_sync)
|
||||||
|
|
||||||
|
|
||||||
|
def show_recent_for_user_if_fetched():
|
||||||
|
container = this
|
||||||
|
if not recently_read_by_user.updated:
|
||||||
|
return conditional_timeout(container.id, 5, show_recent_for_user_if_fetched)
|
||||||
|
if recently_read_by_user.items and recently_read_by_user.items.length > 0:
|
||||||
|
return show_recent_for_user(container.id)
|
||||||
|
return show_recent.call(container)
|
||||||
|
|
||||||
|
|
||||||
def show_recent():
|
def show_recent():
|
||||||
container = this
|
container = this
|
||||||
db = get_db()
|
db = get_db()
|
||||||
@ -265,8 +281,8 @@ def init(container_id):
|
|||||||
recent = E.div(style='display:none', class_='recently-read')
|
recent = E.div(style='display:none', class_='recently-read')
|
||||||
recent_container_id = ensure_id(recent)
|
recent_container_id = ensure_id(recent)
|
||||||
container.appendChild(recent)
|
container.appendChild(recent)
|
||||||
if interface_data.username and interface_data.recently_read_by_user and interface_data.recently_read_by_user.length > 0:
|
if interface_data.username:
|
||||||
show_recent_for_user(recent_container_id, interface_data)
|
conditional_timeout(recent_container_id, 5, show_recent_for_user_if_fetched)
|
||||||
else:
|
else:
|
||||||
conditional_timeout(recent_container_id, 5, show_recent)
|
conditional_timeout(recent_container_id, 5, show_recent)
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ from popups import install_event_filters
|
|||||||
from utils import safe_set_inner_html
|
from utils import safe_set_inner_html
|
||||||
|
|
||||||
from book_list.constants import book_list_container_id, read_book_container_id, INIT_ENDPOINT
|
from book_list.constants import book_list_container_id, read_book_container_id, INIT_ENDPOINT
|
||||||
|
from book_list.home import update_recently_read_by_user
|
||||||
from book_list.library_data import fetch_init_data, update_library_data, url_books_query
|
from book_list.library_data import fetch_init_data, update_library_data, url_books_query
|
||||||
from book_list.theme import get_color, get_font_family, css_for_variables
|
from book_list.theme import get_color, get_font_family, css_for_variables
|
||||||
from book_list.router import update_window_title, set_default_mode_handler, apply_url, set_mode_handler, on_pop_state
|
from book_list.router import update_window_title, set_default_mode_handler, apply_url, set_mode_handler, on_pop_state
|
||||||
@ -83,6 +84,7 @@ def init_ui():
|
|||||||
def install_data_and_init_ui(raw_data):
|
def install_data_and_init_ui(raw_data):
|
||||||
data = JSON.parse(raw_data)
|
data = JSON.parse(raw_data)
|
||||||
update_interface_data(data)
|
update_interface_data(data)
|
||||||
|
update_recently_read_by_user(data.recently_read_by_user)
|
||||||
update_library_data(data)
|
update_library_data(data)
|
||||||
interface_data = get_interface_data()
|
interface_data = get_interface_data()
|
||||||
sd = UserSessionData(interface_data.username, interface_data.user_session_data)
|
sd = UserSessionData(interface_data.username, interface_data.user_session_data)
|
||||||
@ -132,6 +134,7 @@ def do_update_interface_data():
|
|||||||
if end_type is 'load':
|
if end_type is 'load':
|
||||||
data = JSON.parse(xhr.responseText)
|
data = JSON.parse(xhr.responseText)
|
||||||
update_interface_data(data)
|
update_interface_data(data)
|
||||||
|
update_recently_read_by_user(data.recently_read_by_user)
|
||||||
if data.translations?:
|
if data.translations?:
|
||||||
get_translations(data.translations)
|
get_translations(data.translations)
|
||||||
install(data.translations)
|
install(data.translations)
|
||||||
|
@ -243,7 +243,6 @@ default_interface_data = {
|
|||||||
'custom_list_template': None,
|
'custom_list_template': None,
|
||||||
'num_per_page': 50,
|
'num_per_page': 50,
|
||||||
'lang_code_for_user_manual': '',
|
'lang_code_for_user_manual': '',
|
||||||
'recently_read_by_user': v'[]',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_interface_data():
|
def get_interface_data():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user