Make sub-panels also URL addressable

This commit is contained in:
Kovid Goyal 2017-02-06 13:58:45 +05:30
parent 421c99e2f7
commit d402de3045
3 changed files with 18 additions and 25 deletions

View File

@ -76,4 +76,10 @@ def back():
if history_count > 0: if history_count > 0:
window.history.back() window.history.back()
else: else:
push_state({}, replace=True) cq = get_current_query()
handler = mode_handlers[cq.mode] or default_mode_handler
if handler.back_from_current:
q = handler.back_from_current(cq)
else:
q = {}
push_state(q, replace=True)

View File

@ -7,7 +7,7 @@ from elementmaker import E
from book_list.constants import book_list_container_id from book_list.constants import book_list_container_id
from book_list.globals import get_current_query from book_list.globals import get_current_query
from book_list.router import push_state, back as router_back from book_list.router import push_state
from book_list.library_data import current_library_id from book_list.library_data import current_library_id
@ -44,10 +44,6 @@ def currently_showing_panel():
c = document.getElementById(book_list_container_id) c = document.getElementById(book_list_container_id)
return c.dataset.panel return c.dataset.panel
def number_of_subpanels():
c = document.getElementById(book_list_container_id)
return c.lastChild.childNodes.length
def show_panel(panel, query_data, replace=False): def show_panel(panel, query_data, replace=False):
query = {k:query_data[k] for k in query_data} query = {k:query_data[k] for k in query_data}
@ -59,29 +55,19 @@ def show_panel(panel, query_data, replace=False):
push_state(query, replace=replace) push_state(query, replace=replace)
def close_subpanel():
c = document.getElementById(book_list_container_id).lastChild
panel_to_remove = c.lastChild
if panel_to_remove:
c.remove(panel_to_remove)
if c.lastChild:
c.lastChild.style.display = 'block'
else:
c.style.display = 'none'
def back():
if number_of_subpanels() > 0:
return close_subpanel()
router_back()
def apply_url_state(state): def apply_url_state(state):
panel = state.panel or 'home' panel = state.panel or 'home'
c = document.getElementById(book_list_container_id) c = document.getElementById(book_list_container_id)
clear(c) clear(c)
c.appendChild(E.div()) c.appendChild(E.div())
c.appendChild(E.div(style='display:none'))
c.dataset.panel = panel c.dataset.panel = panel
handler = panel_handlers[panel] or default_panel_handler handler = panel_handlers[panel] or default_panel_handler
handler(ensure_id(c.firstChild, 'panel')) handler(ensure_id(c.firstChild, 'panel'))
apply_url_state.back_from_current = def back_from_current(current_query):
q = current_query
if q.panel and '^' in q.panel:
q = {k:q[k] for k in q}
q.panel = q.panel.rpartition('^')[0]
return q

View File

@ -11,7 +11,8 @@ from session import get_interface_data
from book_list.globals import get_session_data from book_list.globals import get_session_data
from book_list.cover_grid import cover_grid_css, create_item as create_cover_grid_item, init as init_cover_grid, append_item as cover_grid_append_item from book_list.cover_grid import cover_grid_css, create_item as create_cover_grid_item, init as init_cover_grid, append_item as cover_grid_append_item
from book_list.top_bar import create_top_bar from book_list.top_bar import create_top_bar
from book_list.ui import back, set_panel_handler from book_list.router import back
from book_list.ui import set_panel_handler
from book_list.library_data import current_library_id, load_status, ensure_current_library_data, library_data from book_list.library_data import current_library_id, load_status, ensure_current_library_data, library_data
ALLOWED_MODES = {'cover_grid'} ALLOWED_MODES = {'cover_grid'}