diff --git a/src/pyj/read_book/annotations.pyj b/src/pyj/read_book/annotations.pyj index eff359b194..6b6a442d27 100644 --- a/src/pyj/read_book/annotations.pyj +++ b/src/pyj/read_book/annotations.pyj @@ -106,6 +106,15 @@ class AnnotationsManager: # {{{ self.set_highlights() self.set_bookmarks() + def sync_annots_to_server(self, which): + if ui_operations.annots_changed: + amap = {} + if not which or which is 'bookmarks': + amap.bookmark = self.bookmarks.as_array() + if not which or which is 'highlights': + amap.highlight = Object.values(self.highlights) + ui_operations.annots_changed(amap) + def set_bookmarks(self, bookmarks): bookmarks = bookmarks or v'[]' self.bookmarks = list(bookmarks) @@ -125,8 +134,7 @@ class AnnotationsManager: # {{{ 'title': title, }) sort_annot_list(self.bookmarks, bookmark_get_cfi) - if ui_operations.bookmarks_changed: - ui_operations.bookmarks_changed(self.bookmarks.as_array()) + self.sync_annots_to_server('bookmarks') def remove_bookmark(self, title): changed = False @@ -135,8 +143,8 @@ class AnnotationsManager: # {{{ b.removed = True b.timestamp = Date().toISOString() changed = True - if changed and ui_operations.bookmarks_changed: - ui_operations.bookmarks_changed(self.bookmarks.as_array()) + if changed: + self.sync_annots_to_server('bookmarks') return changed def default_bookmark_title(self): @@ -180,8 +188,7 @@ class AnnotationsManager: # {{{ def delete_highlight(self, uuid): if self.remove_highlight(uuid): - if ui_operations.highlights_changed: - ui_operations.highlights_changed(Object.values(self.highlights)) + self.sync_annots_to_server('highlights') def notes_for_highlight(self, uuid): h = self.highlights[uuid] if uuid else None @@ -195,8 +202,7 @@ class AnnotationsManager: # {{{ h.notes = notes else: v'delete h.notes' - if ui_operations.highlights_changed: - ui_operations.highlights_changed(Object.values(self.highlights)) + self.sync_annots_to_server('highlights') return True return False @@ -244,8 +250,7 @@ class AnnotationsManager: # {{{ } if notes: annot.notes = notes - if ui_operations.highlights_changed: - ui_operations.highlights_changed(Object.values(self.highlights)) + self.sync_annots_to_server('highlights') def highlights_for_currently_showing(self): name = self.view.currently_showing.name diff --git a/src/pyj/read_book/overlay.pyj b/src/pyj/read_book/overlay.pyj index 9f2534fe96..444b2c6767 100644 --- a/src/pyj/read_book/overlay.pyj +++ b/src/pyj/read_book/overlay.pyj @@ -135,6 +135,7 @@ class SyncBook: # {{{ set_css(container, background_color=get_color('window-background')) book = self.overlay.view.book to_sync = v'[[book.key, new Date(0)]]' + self.overlay.view.annotations_manager.sync_annots_to_server() sync_library_books(book.key[0], to_sync, self.sync_data_received) container.appendChild(E.div( style='display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100%', diff --git a/src/pyj/read_book/ui.pyj b/src/pyj/read_book/ui.pyj index 131916deb7..c6802d8ee0 100644 --- a/src/pyj/read_book/ui.pyj +++ b/src/pyj/read_book/ui.pyj @@ -75,8 +75,7 @@ class ReadUI: ui_operations.focus_iframe = self.focus_iframe.bind(self) ui_operations.toggle_toc = self.toggle_toc.bind(self) ui_operations.toggle_full_screen = self.toggle_full_screen.bind(self) - ui_operations.highlights_changed = self.highlights_changed.bind(self) - ui_operations.bookmarks_changed = self.bookmarks_changed.bind(self) + ui_operations.annots_changed = self.annots_changed.bind(self) ui_operations.annotations_synced = self.annotations_synced.bind(self) ui_operations.wait_for_messages_from = self.wait_for_messages_from.bind(self) ui_operations.stop_waiting_for_messages_from = self.stop_waiting_for_messages_from.bind(self) @@ -217,12 +216,6 @@ class ReadUI: self.db.update_annotations_data_from_key(library_id, book_id, fmt, {'annotations_map': amap}) ajax_send(f'book-update-annotations/{library_id}/{book_id}/{fmt}', amap, def (): pass;) - def highlights_changed(self, highlights): - self.annots_changed({'highlight': highlights}) - - def bookmarks_changed(self, bookmarks): - self.annots_changed({'bookmark': bookmarks}) - def annotations_synced(self, amap): library_id = self.base_url_data.library_id book_id = self.base_url_data.book_id diff --git a/src/pyj/viewer-main.pyj b/src/pyj/viewer-main.pyj index 82835aff25..b8d9606cb1 100644 --- a/src/pyj/viewer-main.pyj +++ b/src/pyj/viewer-main.pyj @@ -394,8 +394,9 @@ if window is window.top: to_python.scrollbar_context_menu(x, y, frac) ui_operations.close_prep_finished = def(cfi): to_python.close_prep_finished(cfi) - ui_operations.highlights_changed = def(highlights): - to_python.highlights_changed(highlights) + ui_operations.annots_changed = def(amap): + if amap.highlight: + to_python.highlights_changed(amap.highlight) document.body.appendChild(E.div(id='view')) window.onerror = onerror