From af321a243865d3080fb2057af608bdaab515b6e5 Mon Sep 17 00:00:00 2001 From: benjaminramey Date: Tue, 12 Nov 2019 13:50:15 -0600 Subject: [PATCH] Working!!! --- src/background.js | 1 - src/page/App.vue | 97 +++++++++++++++++++++++++++++++++-------------- 2 files changed, 69 insertions(+), 29 deletions(-) diff --git a/src/background.js b/src/background.js index f8efe10..54a1dba 100644 --- a/src/background.js +++ b/src/background.js @@ -1,7 +1,6 @@ chrome.runtime.onInstalled.addListener(function() { var data = { apiKey: null, - pins: [], groupings: [] }; diff --git a/src/page/App.vue b/src/page/App.vue index 3bd1d78..c6cbbea 100644 --- a/src/page/App.vue +++ b/src/page/App.vue @@ -3,7 +3,7 @@

Pinboard Groupings

-
+
@@ -15,7 +15,7 @@ {{ apiKey }}
- +
@@ -24,9 +24,33 @@ {{ error }}
-
-
- {{ pin.hash }} +
+ + +
+
+ + +
+ +
+
+ +
+
+
+
{{ grouping.tags }}
+

+ loading... +

+

+ {{ pin.description }} +

+
@@ -44,52 +68,69 @@ export default { form: { apiKey: null }, - pins: [], + newGrouping: { + tags: [] + }, error: null } }, methods: { - getPins() { - axios.get("https://api.pinboard.in/v1/posts/all?format=json&results=10&auth_token=" + this.apiKey) + refreshGroupings(event) { + for(var key in this.groupings) { + var grouping = this.groupings[key]; + grouping.loading = true; + grouping.pins = []; + + this.getPinsForGroup(grouping); + } + }, + getPinsForGroup(grouping) { + 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 => { - console.log(response.data); - this.pins = response.data; - var data = { pins: this.pins }; - chrome.storage.sync.set(data, () => { - console.log('done'); - }) + grouping.pins = response.data; + grouping.loading = false; + var data = { groupings: this.groupings }; + chrome.storage.sync.set(data, () => { }); }) .catch(error => { this.error = error; }); }, + saveNewGrouping(event) { + this.groupings.push({ + tags: this.newGrouping.tags, + pins: [], + loading: true + }); + var data = { groupings: this.groupings }; + chrome.storage.sync.set(data, () => { }); + this.newGrouping = { tags: [] }; + + this.getPinsForGroup(this.groupings[this.groupings.length - 1]); + }, save(event) { var data = { apiKey: this.form.apiKey, - pins: [] + groupings: this.apiKey !== this.form.apiKey ? [] : this.groupings }; chrome.storage.sync.set(data, () => { this.apiKey = data.apiKey; - this.pins = data.pins; - if (this.apiKey) { - this.getPins(); - } + this.groupings = data.groupings; }); }, - edit(event) { + editApiKey(event) { this.form.apiKey = this.apiKey; this.apiKey = null; } }, mounted() { - chrome.storage.sync.get(['apiKey', 'groupings','pins'], result => { + chrome.storage.sync.get(['apiKey','groupings'], result => { this.apiKey = result.apiKey; this.groupings = result.groupings; - this.pins = result.pins; - - if (this.apiKey && this.pins.length == 0) { - this.getPins(); - } }); } } @@ -105,10 +146,10 @@ export default { h1 { font-size: 1rem; } -.api-key * { +.api-key-form *, .tags-form * { font-size: 0.8rem; } -.api-key input.form-control { +.api-key-form input.form-control { width: 17rem; }