Добавление событий, рефакторинг
This commit is contained in:
@@ -127,7 +127,6 @@ class HistoryPage extends Vue {
|
|||||||
|
|
||||||
init() {
|
init() {
|
||||||
this.updateTableData();
|
this.updateTableData();
|
||||||
this.mostRecentBook = bookManager.mostRecentBook();
|
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.$refs.input.focus();
|
this.$refs.input.focus();
|
||||||
});
|
});
|
||||||
@@ -239,13 +238,7 @@ class HistoryPage extends Vue {
|
|||||||
await bookManager.delRecentBook({key});
|
await bookManager.delRecentBook({key});
|
||||||
this.updateTableData();
|
this.updateTableData();
|
||||||
|
|
||||||
const newRecent = bookManager.mostRecentBook();
|
if (!bookManager.mostRecentBook())
|
||||||
|
|
||||||
if (!(this.mostRecentBook && newRecent && this.mostRecentBook.key == newRecent.key))
|
|
||||||
this.$emit('load-book', newRecent);
|
|
||||||
|
|
||||||
this.mostRecentBook = newRecent;
|
|
||||||
if (!this.mostRecentBook)
|
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -207,6 +207,7 @@ class Reader extends Vue {
|
|||||||
mounted() {
|
mounted() {
|
||||||
(async() => {
|
(async() => {
|
||||||
await bookManager.init(this.settings);
|
await bookManager.init(this.settings);
|
||||||
|
bookManager.addEventListener(this.bookManagerEvent);
|
||||||
await this.$refs.serverStorage.init();
|
await this.$refs.serverStorage.init();
|
||||||
|
|
||||||
if (this.$root.rootRoute == '/reader') {
|
if (this.$root.rootRoute == '/reader') {
|
||||||
@@ -288,6 +289,17 @@ class Reader extends Vue {
|
|||||||
this.debouncedUpdateRoute();
|
this.debouncedUpdateRoute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bookManagerEvent(eventName) {
|
||||||
|
if (eventName == 'recent-changed') {
|
||||||
|
const oldBook = this.mostRecentBookReactive;
|
||||||
|
const newBook = bookManager.mostRecentBook();
|
||||||
|
|
||||||
|
if (oldBook && newBook && oldBook.key != newBook.key) {
|
||||||
|
this.loadBook(newBook);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
get toolBarActive() {
|
get toolBarActive() {
|
||||||
return this.reader.toolBarActive;
|
return this.reader.toolBarActive;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -255,16 +255,20 @@ class BookManager {
|
|||||||
await bmRecentStore.setItem(result.key, result);
|
await bmRecentStore.setItem(result.key, result);
|
||||||
|
|
||||||
//кэшируем, аккуратно
|
//кэшируем, аккуратно
|
||||||
|
let saveRecent = false;
|
||||||
if (!(this.recentLast && this.recentLast.key == result.key)) {
|
if (!(this.recentLast && this.recentLast.key == result.key)) {
|
||||||
await bmCacheStore.setItem('recent', this.recent);
|
await bmCacheStore.setItem('recent', this.recent);
|
||||||
this.emit('recent-changed');
|
saveRecent = true;
|
||||||
}
|
}
|
||||||
this.recentLast = result;
|
this.recentLast = result;
|
||||||
await bmCacheStore.setItem('recent-last', this.recentLast);
|
await bmCacheStore.setItem('recent-last', this.recentLast);
|
||||||
this.emit('recent-last-changed');
|
|
||||||
|
|
||||||
this.mostRecentCached = result;
|
this.mostRecentCached = result;
|
||||||
this.recentChanged2 = true;
|
this.recentChanged2 = true;
|
||||||
|
|
||||||
|
if (saveRecent)
|
||||||
|
this.emit('save-recent');
|
||||||
|
this.emit('recent-changed');
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,10 +285,11 @@ class BookManager {
|
|||||||
this.recent[value.key].deleted = 1;
|
this.recent[value.key].deleted = 1;
|
||||||
await bmRecentStore.setItem(value.key, this.recent[value.key].deleted);
|
await bmRecentStore.setItem(value.key, this.recent[value.key].deleted);
|
||||||
await bmCacheStore.setItem('recent', this.recent);
|
await bmCacheStore.setItem('recent', this.recent);
|
||||||
this.emit('recent-changed');
|
|
||||||
|
|
||||||
this.mostRecentCached = null;
|
this.mostRecentCached = null;
|
||||||
this.recentChanged2 = true;
|
this.recentChanged2 = true;
|
||||||
|
|
||||||
|
this.emit('recent-changed');
|
||||||
}
|
}
|
||||||
|
|
||||||
async cleanRecentBooks() {
|
async cleanRecentBooks() {
|
||||||
|
|||||||
Reference in New Issue
Block a user