diff --git a/src/background.js b/src/background.js index 54a1dba..29d8951 100644 --- a/src/background.js +++ b/src/background.js @@ -4,7 +4,7 @@ chrome.runtime.onInstalled.addListener(function() { groupings: [] }; - chrome.storage.sync.set(data, function() { + chrome.storage.local.set(data, function() { console.log("data initialized"); }); }); diff --git a/src/page/App.vue b/src/page/App.vue index 1bb3470..ad0feb3 100644 --- a/src/page/App.vue +++ b/src/page/App.vue @@ -3,8 +3,21 @@

Pinboard Groupings

+ +
+
+
+ + +
+ +
+
+
-
+
-
- - - -
- - -
- - +
+
-
- {{ grouping.tags }} +
+ {{ grouping.tags }}
@@ -85,33 +89,36 @@ export default { methods: { deleteGrouping(index) { this.groupings.splice(index, 1); - var data = { groupings: this.groupings }; - chrome.storage.sync.set(data, () => { }); + this.persistGroupings(); }, refreshGroupings(event) { + var promises = []; for(var key in this.groupings) { var grouping = this.groupings[key]; grouping.loading = true; grouping.pins = []; - this.getPinsForGroup(grouping); + promises.push(this.getPinsForGroup(key)); } + + axios.all(promises).finally(() => { + this.persistGroupings(); + }); }, - getPinsForGroup(grouping) { + getPinsForGroup(index) { var url = "https://api.pinboard.in/v1/posts/all?format=json&results=30"; url += "&auth_token=" + this.apiKey; - url += "&tag=" + grouping.tags; - - axios.get(url) - .then(response => { - grouping.pins = response.data; - grouping.loading = false; - var data = { groupings: this.groupings }; - chrome.storage.sync.set(data, () => { }); + url += "&tag=" + this.groupings[index].tags; + + var promise = axios.get(url); + promise.then(response => { + this.groupings[index].pins = response.data; + this.groupings[index].loading = false; }) .catch(error => { this.error = error; }); + return promise; }, saveNewGrouping(event) { this.groupings.push({ @@ -119,29 +126,33 @@ export default { pins: [], loading: true }); - var data = { groupings: this.groupings }; - chrome.storage.sync.set(data, () => { }); this.newGrouping = { tags: [] }; - - this.getPinsForGroup(this.groupings[this.groupings.length - 1]); + this.getPinsForGroup(this.groupings.length - 1) + .finally(() => { + this.persistGroupings(); + }); }, - save(event) { + saveApiKey(event) { var data = { apiKey: this.form.apiKey, groupings: this.apiKey !== this.form.apiKey ? [] : this.groupings }; - chrome.storage.sync.set(data, () => { + chrome.storage.local.set(data, () => { this.apiKey = data.apiKey; this.groupings = data.groupings; }); }, + persistGroupings() { + var data = { groupings: this.groupings }; + chrome.storage.local.set(data, () => {}); + }, editApiKey(event) { this.form.apiKey = this.apiKey; this.apiKey = null; } }, mounted() { - chrome.storage.sync.get(['apiKey','groupings'], result => { + chrome.storage.local.get(['apiKey','groupings'], result => { this.apiKey = result.apiKey; this.groupings = result.groupings; });