Commit 2fddafb5 authored by Duhoux Pierre-Louis's avatar Duhoux Pierre-Louis

Import export bookmarks

parent ae713776
......@@ -788,10 +788,6 @@
"message": "Small",
"description": "Size of the bookmarks in list : small"
},
"bookmarks_no_mangas": {
"message": "No mangas have bookmarks",
"description": "Label when no mangas have bookmarks"
},
"bookmarks_no_bookmarks": {
"message": "No bookmarks yet. To bookmark a scan, double click on the scan while reading. Bookmarked scans have a grey border. <br /> To bookmark a chapter, click on the star in the top bar while reading.",
"description": "Label when no bookmarks. Help about how to bookmark a scan and chapter"
......
......@@ -7,7 +7,7 @@
app
>
<v-card flat>
<v-list two-line v-if="mangas">
<v-list two-line>
<v-list-tile @click="switchAllStates()" avatar ripple>
<v-list-tile-content>
<v-list-tile-title>
......@@ -62,7 +62,6 @@
></v-divider>
</template>
</v-list>
<v-card-text v-else>{{i18n("bookmarks_no_mangas")}}</v-card-text>
</v-card>
</v-navigation-drawer>
<v-toolbar
......@@ -124,7 +123,7 @@
<!-- Once loaded -->
<Bookmarks :bookmark-list="displayedBookmarks" :size="size.value" v-if="nbBookmarks > 0 && displayedBookmarks.length > 0"/>
<h2 v-else align-center>
<span v-if="displayedBookmarks.length==0" v-html="i18n('bookmarks_no_bookmarks_filter')"></span>
<span v-if="nbBookmarks > 0" v-html="i18n('bookmarks_no_bookmarks_filter')"></span>
<span v-else v-html="i18n('bookmarks_no_bookmarks')"></span>
</h2>
</v-layout>
......
......@@ -191,11 +191,46 @@ export default {
};
}
});
let exp = { mangas: mgs };
//TODO add bookmarks
//add bookmarks
if (this.bookmarks) {
let bms = this.$store.state.bookmarks.all;
if (this.viewable) {
bms = bms.filter(bm => {
let mgbm = this.$store.state.mangas.all.find(mg => mg.key === mgutils.mangaKey(bm.url)); // find manga associated with bookmark
if (mgbm !== undefined) {
return mgutils.displayFilterCats( // check if manga is viewable
mgbm,
self.$store.state.options.categoriesStates
)
} else { // do not export bookmarks from deleted mangas in viewable mode
return false;
}
}
);
}
bms = bms.map(bm => {
let res = {
m: bm.mirror,
n: bm.name,
u: bm.url,
c: bm.chapUrl,
h: bm.chapName,
o: bm.note,
t: bm.type
}
if (bm.type === "scan") {
res.s = bm.scanUrl;
res.a = bm.scanName;
}
return res;
});
exp.bookmarks = bms;
}
// create a file containing export and download it
let exp = { mangas: mgs /*, bookmarks: bms */ };
var blob = new Blob([JSON.stringify(exp, null, 2)], {
type: "text/json"
});
......@@ -269,8 +304,47 @@ export default {
* Import bookmarks described in importstr in reading list.
* Button is accessible only if json is valid and contains bookmarks
*/
importBookmarks: function() {
//TODO
importBookmarks: async function() {
this.importingbookmarks = true;
let imps = JSON.parse(this.importstr);
// AMR V1 export --> convert it to AMR V2
if (typeof imps.bookmarks === "string") {
imps.bookmarks = JSON.parse(imps.bookmarks).map(bm => {
return {
m: bm.mirror,
n: bm.name,
u: bm.url,
c: bm.chapUrl,
h: bm.chapName,
o: bm.note,
t: bm.type,
s: bm.scanUrl,
a: bm.scanName
};
});
}
if (imps.bookmarks && imps.bookmarks.length > 0) {
let addall = [];
imps.bookmarks.forEach(bm => {
// convert bookmark to something matching internal bookmarks
let nbm = {
mirror: bm.m,
name: bm.n,
url: bm.u,
chapUrl: bm.c,
chapName: bm.h,
note: bm.o,
type: bm.t,
};
if (bm.s) nbm.scanUrl = bm.s;
if (bm.a) nbm.scanName = bm.a;
nbm.action = "addUpdateBookmark";
addall.push(browser.runtime.sendMessage(nbm));
});
// add update all bookmarks
await Promise.all(addall);
}
this.importingbookmarks = false;
},
/**
* Import mangas and bookmarks described in importstr in reading list.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment