Almost getting pins

This commit is contained in:
benjaminramey
2019-11-11 13:54:56 -06:00
parent 7549e0a41c
commit 878ce7350f
2 changed files with 34 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
chrome.runtime.onInstalled.addListener(function() { chrome.runtime.onInstalled.addListener(function() {
var data = { var data = {
apiKey: null, apiKey: null,
pins: [],
groupings: [] groupings: []
}; };

View File

@@ -1,6 +1,9 @@
<template> <template>
<div class="app"> <div class="app">
<div class="fluid-container"> <div class="fluid-container">
<div class="alert alert-danger" role="alert" v-if="error">
{{ error }}
</div>
<h1>Pinboard Groupings</h1> <h1>Pinboard Groupings</h1>
<div class="card"> <div class="card">
<div class="card-body"> <div class="card-body">
@@ -18,14 +21,18 @@
<button type="submit" class="btn btn-primary btn-sm" v-if="!apiKey">save</button> <button type="submit" class="btn btn-primary btn-sm" v-if="!apiKey">save</button>
<button type="button" class="btn btn-secondary btn-sm" @click.prevent="edit" v-else>edit</button> <button type="button" class="btn btn-secondary btn-sm" @click.prevent="edit" v-else>edit</button>
</form> </form>
</div> </div>
</div> </div>
<div v-for="pin in pins" v-bind:key="pin.hash">
{{ pin.hash }}
</div>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import axios from 'axios'
export default { export default {
data () { data () {
return { return {
@@ -33,18 +40,31 @@ export default {
groupings: [], groupings: [],
form: { form: {
apiKey: null apiKey: null
} },
error: null
} }
}, },
methods: { methods: {
getPins() {
axios.get("https://api.pinboard.in/v1/posts/all?auth_token=" + this.apiKey)
.then(response => {
this.pins = response;
var data = { pins: this.pins };
chrome.storage.sync.set(data, () => {
console.log('done');
})
})
.catch(error => {
this.error = error;
});
},
save(event) { save(event) {
var data = { var data = {
apiKey: this.form.apiKey, apiKey: this.form.apiKey
groupings: this.groupings
}; };
chrome.storage.sync.set(data, () => { chrome.storage.sync.set(data, () => {
this.apiKey = data.apiKey; this.apiKey = data.apiKey;
this.groupings = data.groupings; this.getPins();
}); });
}, },
edit(event) { edit(event) {
@@ -52,10 +72,15 @@ export default {
this.apiKey = null; this.apiKey = null;
} }
}, },
created() { mounted() {
chrome.storage.sync.get(['apiKey', 'groupings'], result => { chrome.storage.sync.get(['apiKey', 'groupings','pins'], result => {
this.apiKey = result.apiKey; this.apiKey = result.apiKey;
this.groupings = result.groupings; this.groupings = result.groupings;
this.pins = result.pins;
if (this.apiKey && this.pins.length == 0) {
this.getPins();
}
}); });
} }
} }