Last played books saving added
Last played books saving added
This commit is contained in:
parent
67dff194d2
commit
7efae6315c
103
src/App.vue
103
src/App.vue
@ -49,9 +49,12 @@
|
|||||||
@bookSelected="loadBook"
|
@bookSelected="loadBook"
|
||||||
@loadChapter="loadChapter"
|
@loadChapter="loadChapter"
|
||||||
>
|
>
|
||||||
<transition name="fade">
|
<!--
|
||||||
|
<transition name="scroll-x-transition">
|
||||||
<component :is="Component"/>
|
<component :is="Component"/>
|
||||||
</transition>
|
</transition>
|
||||||
|
-->
|
||||||
|
<component :is="Component"/>
|
||||||
</router-view>
|
</router-view>
|
||||||
<v-alert
|
<v-alert
|
||||||
prominent
|
prominent
|
||||||
@ -224,6 +227,13 @@
|
|||||||
alertType: "info",
|
alertType: "info",
|
||||||
alertMessage: "",
|
alertMessage: "",
|
||||||
|
|
||||||
|
loading: {
|
||||||
|
authors: false,
|
||||||
|
books: false,
|
||||||
|
book: false,
|
||||||
|
wiki: false,
|
||||||
|
},
|
||||||
|
|
||||||
authors: [],
|
authors: [],
|
||||||
|
|
||||||
audioElement: null,
|
audioElement: null,
|
||||||
@ -254,6 +264,10 @@
|
|||||||
localStorage.autoBookmark = val;
|
localStorage.autoBookmark = val;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"$store.getters.autoLoadBooks" (val) {
|
||||||
|
localStorage.autoLoadBooks = val;
|
||||||
|
},
|
||||||
|
|
||||||
"$store.getters.darkTheme" (val) {
|
"$store.getters.darkTheme" (val) {
|
||||||
this.setTheme(val == true ? "dark" : "light");
|
this.setTheme(val == true ? "dark" : "light");
|
||||||
localStorage.darkTheme = val;
|
localStorage.darkTheme = val;
|
||||||
@ -313,7 +327,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
showProgress () {
|
showProgress () {
|
||||||
return false;
|
return this.loading.authors || this.loading.books || this.loading.book || this.loading.wiki;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -321,6 +335,9 @@
|
|||||||
let autoBookmark = localStorage.autoBookmark ? JSON.parse(localStorage.autoBookmark) : false;
|
let autoBookmark = localStorage.autoBookmark ? JSON.parse(localStorage.autoBookmark) : false;
|
||||||
this.$store.commit("setAutoBookmark", autoBookmark);
|
this.$store.commit("setAutoBookmark", autoBookmark);
|
||||||
|
|
||||||
|
let autoLoadBooks = localStorage.autoLoadBooks ? JSON.parse(localStorage.autoLoadBooks) : false;
|
||||||
|
this.$store.commit("setAutoLoadBooks", autoLoadBooks);
|
||||||
|
|
||||||
let darkTheme = localStorage.darkTheme ? JSON.parse(localStorage.darkTheme) : false;
|
let darkTheme = localStorage.darkTheme ? JSON.parse(localStorage.darkTheme) : false;
|
||||||
this.$store.commit("setDarkTheme", darkTheme);
|
this.$store.commit("setDarkTheme", darkTheme);
|
||||||
|
|
||||||
@ -351,6 +368,8 @@
|
|||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
fillWikiInfo (searchText, fillAuthorInfo = true) {
|
fillWikiInfo (searchText, fillAuthorInfo = true) {
|
||||||
|
this.loading.wiki = true;
|
||||||
|
|
||||||
this.axios.get(`https://${this.$i18n.locale}.wikipedia.org/w/api.php`, {
|
this.axios.get(`https://${this.$i18n.locale}.wikipedia.org/w/api.php`, {
|
||||||
params: {
|
params: {
|
||||||
format: "json",
|
format: "json",
|
||||||
@ -388,9 +407,11 @@
|
|||||||
this.$store.commit("setBook", bookInfo);
|
this.$store.commit("setBook", bookInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.loading.wiki = false;
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
this.isLoading = false;
|
this.loading.wiki = false;
|
||||||
|
|
||||||
if (fillAuthorInfo) {
|
if (fillAuthorInfo) {
|
||||||
let authorInfo = this.$store.getters.author;
|
let authorInfo = this.$store.getters.author;
|
||||||
@ -414,14 +435,38 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
loadAuthors () {
|
loadAuthors () {
|
||||||
|
this.loading.authors = true;
|
||||||
|
|
||||||
this.axios.get(`lib/authors.json?r=${Math.random()}`)
|
this.axios.get(`lib/authors.json?r=${Math.random()}`)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
this.$store.commit("setAuthors", response.data);
|
let lastAuthorHash = localStorage.lastAuthor ? localStorage.lastAuthor : null;
|
||||||
this.isLoading = false;
|
let authors = [];
|
||||||
|
let authorToLoad = null;
|
||||||
|
|
||||||
|
response.data.forEach(author => {
|
||||||
|
let authorExt = author;
|
||||||
|
authorExt.hash = this.getHash(JSON.stringify({
|
||||||
|
author: authorExt.author,
|
||||||
|
books: authorExt.books
|
||||||
|
}));
|
||||||
|
authors.push(authorExt);
|
||||||
|
if (lastAuthorHash !== null && lastAuthorHash == authorExt.hash) {
|
||||||
|
authorToLoad = { ...authorExt };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.$store.commit("setAuthors", authors);
|
||||||
|
|
||||||
|
if (authorToLoad !== null && this.$store.getters.autoLoadBooks) {
|
||||||
|
this.loadBooks(authorToLoad);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.loading.authors = false;
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
this.showMessage(this.$t("error"), error);
|
this.showMessage(this.$t("error"), error);
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
this.loading.authors = false;
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -429,8 +474,9 @@
|
|||||||
* Load book data
|
* Load book data
|
||||||
*
|
*
|
||||||
* @param {object} bookData Book data
|
* @param {object} bookData Book data
|
||||||
|
* @param {boolean} switchToTab Switch to Book tab after data loading
|
||||||
*/
|
*/
|
||||||
loadBook (bookData) {
|
loadBook (bookData, switchToTab = false) {
|
||||||
if (this.audioElement !== null && this.$store.getters.autoBookmark) {
|
if (this.audioElement !== null && this.$store.getters.autoBookmark) {
|
||||||
this.setBookmark();
|
this.setBookmark();
|
||||||
}
|
}
|
||||||
@ -448,10 +494,11 @@
|
|||||||
reader: bookData.reader !== undefined && bookData.reader.trim() !== ""
|
reader: bookData.reader !== undefined && bookData.reader.trim() !== ""
|
||||||
? bookData.reader
|
? bookData.reader
|
||||||
: "",
|
: "",
|
||||||
|
hash: bookData.hash,
|
||||||
wiki: ""
|
wiki: ""
|
||||||
});
|
});
|
||||||
|
|
||||||
this.isLoading = true;
|
this.loading.book = true;
|
||||||
|
|
||||||
this.axios.get(`${bookData.book}?r=${Math.random()}`)
|
this.axios.get(`${bookData.book}?r=${Math.random()}`)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
@ -473,11 +520,15 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.backgroundImage = bookData.image;
|
this.backgroundImage = bookData.image;
|
||||||
|
|
||||||
|
if (switchToTab) {
|
||||||
this.$router.push({ path: "/book" });
|
this.$router.push({ path: "/book" });
|
||||||
this.isLoading = false;
|
}
|
||||||
|
|
||||||
|
this.loading.book = false;
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
this.isLoading = false;
|
this.loading.book = false;
|
||||||
this.showMessage(this.$t("error"), error);
|
this.showMessage(this.$t("error"), error);
|
||||||
|
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@ -488,13 +539,15 @@
|
|||||||
* Load books data
|
* Load books data
|
||||||
*
|
*
|
||||||
* @param {object} authorData Author data
|
* @param {object} authorData Author data
|
||||||
|
* @param {boolean} switchToTab Switch to Books tab after data loading
|
||||||
*/
|
*/
|
||||||
loadBooks (authorData) {
|
loadBooks (authorData, switchToTab = false) {
|
||||||
this.isLoading = true;
|
this.loading.books = true;
|
||||||
|
|
||||||
this.axios.get(`${authorData.books}?r=${Math.random()}`)
|
this.axios.get(`${authorData.books}?r=${Math.random()}`)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
let books = {};
|
let books = {};
|
||||||
|
let bookToLoad = null;
|
||||||
|
|
||||||
response.data.forEach((book) => {
|
response.data.forEach((book) => {
|
||||||
let cycle = book.cycle !== undefined ? book.cycle : "no_cycle";
|
let cycle = book.cycle !== undefined ? book.cycle : "no_cycle";
|
||||||
@ -503,12 +556,22 @@
|
|||||||
books[cycle] = [];
|
books[cycle] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
books[cycle].push(book);
|
let bookExt = { ...book };
|
||||||
|
bookExt.hash = this.getHash(JSON.stringify({
|
||||||
|
book: bookExt.book,
|
||||||
|
}));
|
||||||
|
|
||||||
|
books[cycle].push(bookExt);
|
||||||
|
|
||||||
|
if (localStorage[authorData.hash] && localStorage[authorData.hash] == bookExt.hash) {
|
||||||
|
bookToLoad = { ...bookExt };
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$store.commit("setAuthor", {
|
this.$store.commit("setAuthor", {
|
||||||
name: authorData.author || "",
|
name: authorData.author || "",
|
||||||
image: authorData.image || "",
|
image: authorData.image || "",
|
||||||
|
hash: authorData.hash || "",
|
||||||
wiki: ""
|
wiki: ""
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -516,12 +579,18 @@
|
|||||||
|
|
||||||
if (this.useWikipedia) { this.fillWikiInfo(authorData.author); }
|
if (this.useWikipedia) { this.fillWikiInfo(authorData.author); }
|
||||||
|
|
||||||
this.$router.push({ path: "/books" });
|
if (bookToLoad !== null && this.$store.getters.autoLoadBooks) {
|
||||||
|
this.loadBook(bookToLoad);
|
||||||
|
}
|
||||||
|
|
||||||
this.isLoading = false;
|
if (switchToTab) {
|
||||||
|
this.$router.push({ path: "/books" });
|
||||||
|
}
|
||||||
|
|
||||||
|
this.loading.books = false;
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
this.isLoading = false;
|
this.loading.books = false;
|
||||||
this.showMessage(this.$t("error"), error);
|
this.showMessage(this.$t("error"), error);
|
||||||
|
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@ -562,7 +631,7 @@
|
|||||||
component.audioElement.removeEventListener("canplay", _listener, true);
|
component.audioElement.removeEventListener("canplay", _listener, true);
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
if (autoplay) this.play();
|
if (autoplay) { this.play(); }
|
||||||
},
|
},
|
||||||
|
|
||||||
loadNextChapter (autoplay = true) {
|
loadNextChapter (autoplay = true) {
|
||||||
@ -593,6 +662,8 @@
|
|||||||
play () {
|
play () {
|
||||||
this.status = this.statuses.playing;
|
this.status = this.statuses.playing;
|
||||||
this.audioElement.play();
|
this.audioElement.play();
|
||||||
|
localStorage.lastAuthor = this.$store.getters.author.hash;
|
||||||
|
localStorage[this.$store.getters.author.hash] = this.$store.getters.book.hash;
|
||||||
},
|
},
|
||||||
|
|
||||||
prevChapter () {
|
prevChapter () {
|
||||||
|
|||||||
@ -17,6 +17,7 @@
|
|||||||
>
|
>
|
||||||
<v-card
|
<v-card
|
||||||
hover
|
hover
|
||||||
|
ripple
|
||||||
outlined
|
outlined
|
||||||
tile
|
tile
|
||||||
height="127"
|
height="127"
|
||||||
@ -66,7 +67,7 @@
|
|||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
authorClick (author) {
|
authorClick (author) {
|
||||||
this.$emit("authorSelected", author);
|
this.$emit("authorSelected", author, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -155,7 +155,7 @@
|
|||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
bookClick (book) {
|
bookClick (book) {
|
||||||
this.$emit("bookSelected", book);
|
this.$emit("bookSelected", book, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,11 +21,19 @@
|
|||||||
v-model="darkTheme"
|
v-model="darkTheme"
|
||||||
color="blue"
|
color="blue"
|
||||||
:label="$t('darkTheme')"
|
:label="$t('darkTheme')"
|
||||||
|
class="ml-3"
|
||||||
></v-switch>
|
></v-switch>
|
||||||
<v-switch
|
<v-switch
|
||||||
v-model="autoBookmark"
|
v-model="autoBookmark"
|
||||||
color="blue"
|
color="blue"
|
||||||
:label="$t('autoBookmarks')"
|
:label="$t('autoBookmarks')"
|
||||||
|
class="ml-3"
|
||||||
|
></v-switch>
|
||||||
|
<v-switch
|
||||||
|
v-model="autoLoadBooks"
|
||||||
|
color="blue"
|
||||||
|
:label="$t('autoLoadBooks')"
|
||||||
|
class="ml-3"
|
||||||
></v-switch>
|
></v-switch>
|
||||||
<div class="mb-7 text-caption">{{ $t("playbackRate") }}</div>
|
<div class="mb-7 text-caption">{{ $t("playbackRate") }}</div>
|
||||||
<v-slider
|
<v-slider
|
||||||
@ -59,7 +67,7 @@
|
|||||||
</v-card-text>
|
</v-card-text>
|
||||||
<v-card-actions>
|
<v-card-actions>
|
||||||
<v-spacer></v-spacer>
|
<v-spacer></v-spacer>
|
||||||
<v-btn color="primary" flat @click="dialog = false">Ok</v-btn>
|
<v-btn flat variant="outlined" color="info" @click="dialog = false">Ok</v-btn>
|
||||||
</v-card-actions>
|
</v-card-actions>
|
||||||
</v-card>
|
</v-card>
|
||||||
</v-dialog>
|
</v-dialog>
|
||||||
@ -73,6 +81,7 @@
|
|||||||
dialog: false,
|
dialog: false,
|
||||||
activeTab: 0,
|
activeTab: 0,
|
||||||
autoBookmark: false,
|
autoBookmark: false,
|
||||||
|
autoLoadBooks: false,
|
||||||
darkTheme: false,
|
darkTheme: false,
|
||||||
locale: "en",
|
locale: "en",
|
||||||
playbackRate: 1,
|
playbackRate: 1,
|
||||||
@ -83,6 +92,7 @@
|
|||||||
dialog (val) {
|
dialog (val) {
|
||||||
if (val) {
|
if (val) {
|
||||||
this.autoBookmark = this.$store.getters.autoBookmark;
|
this.autoBookmark = this.$store.getters.autoBookmark;
|
||||||
|
this.autoLoadBooks = this.$store.getters.autoLoadBooks;
|
||||||
this.darkTheme = this.$store.getters.darkTheme;
|
this.darkTheme = this.$store.getters.darkTheme;
|
||||||
this.playbackRate = this.$store.getters.playbackRate;
|
this.playbackRate = this.$store.getters.playbackRate;
|
||||||
|
|
||||||
@ -96,6 +106,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
autoBookmark (val) { this.$store.commit("setAutoBookmark", val); },
|
autoBookmark (val) { this.$store.commit("setAutoBookmark", val); },
|
||||||
|
autoLoadBooks (val) { this.$store.commit("setAutoLoadBooks", val); },
|
||||||
darkTheme (val) { this.$store.commit("setDarkTheme", val); },
|
darkTheme (val) { this.$store.commit("setDarkTheme", val); },
|
||||||
playbackRate (val) { this.$store.commit("setPlaybackRate", val); }
|
playbackRate (val) { this.$store.commit("setPlaybackRate", val); }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ const messages = {
|
|||||||
about: "About",
|
about: "About",
|
||||||
authors: "Authors",
|
authors: "Authors",
|
||||||
autoBookmarks: "Auto-bookmarks",
|
autoBookmarks: "Auto-bookmarks",
|
||||||
|
autoLoadBooks: "Auto-load last opened books",
|
||||||
book: "Books",
|
book: "Books",
|
||||||
bookmarkSaved: "Bookmark saved",
|
bookmarkSaved: "Bookmark saved",
|
||||||
books: "Book",
|
books: "Book",
|
||||||
|
|||||||
@ -3,6 +3,7 @@ const messages = {
|
|||||||
about: "О программе",
|
about: "О программе",
|
||||||
authors: "Авторы",
|
authors: "Авторы",
|
||||||
autoBookmarks: "Автозакладки",
|
autoBookmarks: "Автозакладки",
|
||||||
|
autoLoadBooks: "Автоматически загружать последние открытые книги",
|
||||||
book: "Книга",
|
book: "Книга",
|
||||||
bookmarkSaved: "Закладка сохранена",
|
bookmarkSaved: "Закладка сохранена",
|
||||||
books: "Книги",
|
books: "Книги",
|
||||||
|
|||||||
@ -11,6 +11,7 @@ const store = createStore({
|
|||||||
},
|
},
|
||||||
authors: [],
|
authors: [],
|
||||||
autoBookmark: false,
|
autoBookmark: false,
|
||||||
|
autoLoadBooks: false,
|
||||||
book: {
|
book: {
|
||||||
author: "",
|
author: "",
|
||||||
photo: "",
|
photo: "",
|
||||||
@ -30,6 +31,7 @@ const store = createStore({
|
|||||||
author: state => { return state.author; },
|
author: state => { return state.author; },
|
||||||
authors: state => { return state.authors; },
|
authors: state => { return state.authors; },
|
||||||
autoBookmark: state => { return state.autoBookmark; },
|
autoBookmark: state => { return state.autoBookmark; },
|
||||||
|
autoLoadBooks: state => { return state.autoLoadBooks; },
|
||||||
book: state => { return state.book; },
|
book: state => { return state.book; },
|
||||||
books: state => { return state.books; },
|
books: state => { return state.books; },
|
||||||
chapters: state => { return state.chapters },
|
chapters: state => { return state.chapters },
|
||||||
@ -42,6 +44,7 @@ const store = createStore({
|
|||||||
setAuthor (state, payload) { state.author = payload; },
|
setAuthor (state, payload) { state.author = payload; },
|
||||||
setAuthors (state, payload) { state.authors = payload; },
|
setAuthors (state, payload) { state.authors = payload; },
|
||||||
setAutoBookmark (state, payload) { state.autoBookmark = payload; },
|
setAutoBookmark (state, payload) { state.autoBookmark = payload; },
|
||||||
|
setAutoLoadBooks (state, payload) { state.autoLoadBooks = payload; },
|
||||||
setBook (state, payload) { state.book = payload; },
|
setBook (state, payload) { state.book = payload; },
|
||||||
setBooks (state, payload) { state.books = payload; },
|
setBooks (state, payload) { state.books = payload; },
|
||||||
setChapters (state, payload) { state.chapters = payload; },
|
setChapters (state, payload) { state.chapters = payload; },
|
||||||
|
|||||||
12
yarn.lock
12
yarn.lock
@ -5191,9 +5191,9 @@ sass-loader@^10.0.0:
|
|||||||
semver "^7.3.2"
|
semver "^7.3.2"
|
||||||
|
|
||||||
sass@^1.50.0:
|
sass@^1.50.0:
|
||||||
version "1.50.0"
|
version "1.50.1"
|
||||||
resolved "https://registry.yarnpkg.com/sass/-/sass-1.50.0.tgz#3e407e2ebc53b12f1e35ce45efb226ea6063c7c8"
|
resolved "https://registry.yarnpkg.com/sass/-/sass-1.50.1.tgz#e9b078a1748863013c4712d2466ce8ca4e4ed292"
|
||||||
integrity sha512-cLsD6MEZ5URXHStxApajEh7gW189kkjn4Rc8DQweMyF+o5HF5nfEz8QYLMlPsTOD88DknatTmBWkOcw5/LnJLQ==
|
integrity sha512-noTnY41KnlW2A9P8sdwESpDmo+KBNkukI1i8+hOK3footBUcohNHtdOJbckp46XO95nuvcHDDZ+4tmOnpK3hjw==
|
||||||
dependencies:
|
dependencies:
|
||||||
chokidar ">=3.0.0 <4.0.0"
|
chokidar ">=3.0.0 <4.0.0"
|
||||||
immutable "^4.0.0"
|
immutable "^4.0.0"
|
||||||
@ -5942,9 +5942,9 @@ vuetify-loader@^2.0.0-alpha.0:
|
|||||||
upath "^2.0.1"
|
upath "^2.0.1"
|
||||||
|
|
||||||
"vuetify@npm:@vuetify/nightly@next":
|
"vuetify@npm:@vuetify/nightly@next":
|
||||||
version "3.0.0-next-20220416.0"
|
version "3.0.0-next-20220419.0"
|
||||||
resolved "https://registry.yarnpkg.com/@vuetify/nightly/-/nightly-3.0.0-next-20220416.0.tgz#d3be97e6130900647b51ca924ae60b0812a9b5d2"
|
resolved "https://registry.yarnpkg.com/@vuetify/nightly/-/nightly-3.0.0-next-20220419.0.tgz#4ad519eb61721f89b734a4c334a45b40b665ebbb"
|
||||||
integrity sha512-3jgtwcZXmrCeR1gcLyL2jvUnZftc9RyaXHdQpXQhmlFazYEtSymsRoD8RAEv2P2GeVGKVKkR7KfBrVhUBEgaSg==
|
integrity sha512-BqgKBxmgtOyA4LByRIQIpSfYyM5GQq2I3+hjkrP2NbZ0n1rSDlov4YRmauqLzII9ys0Lxi0HXwu7dXLEHJkHBQ==
|
||||||
|
|
||||||
vuex@^4.0.2:
|
vuex@^4.0.2:
|
||||||
version "4.0.2"
|
version "4.0.2"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user