Lots of improvements
This commit is contained in:
@@ -4,7 +4,7 @@ chrome.runtime.onInstalled.addListener(function() {
|
|||||||
groupings: []
|
groupings: []
|
||||||
};
|
};
|
||||||
|
|
||||||
chrome.storage.sync.set(data, function() {
|
chrome.storage.local.set(data, function() {
|
||||||
console.log("data initialized");
|
console.log("data initialized");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,8 +3,21 @@
|
|||||||
<div class="fluid-container">
|
<div class="fluid-container">
|
||||||
<div class="d-flex justify-content-between">
|
<div class="d-flex justify-content-between">
|
||||||
<h1 class="py-2 pr-2">Pinboard Groupings</h1>
|
<h1 class="py-2 pr-2">Pinboard Groupings</h1>
|
||||||
|
|
||||||
|
<div class="tags-form py-2 pl-2">
|
||||||
|
<form @submit.prevent="saveNewGrouping" class="form-inline" v-if="apiKey">
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="sr-only" for="tags">Tags</label>
|
||||||
|
<input type="text" class="form-control" id="tags"
|
||||||
|
v-model="newGrouping.tags"
|
||||||
|
placeholder="new grouping tags">
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-link p-0 pl-2">add grouping</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="api-key-form py-2 pl-2">
|
<div class="api-key-form py-2 pl-2">
|
||||||
<form @submit.prevent="save" class="form-inline">
|
<form @submit.prevent="saveApiKey" class="form-inline">
|
||||||
<div class="form-group" v-if="!apiKey">
|
<div class="form-group" v-if="!apiKey">
|
||||||
<label class="sr-only" for="apiKey">Pinboard API Key</label>
|
<label class="sr-only" for="apiKey">Pinboard API Key</label>
|
||||||
<input type="text" class="form-control" id="apiKey"
|
<input type="text" class="form-control" id="apiKey"
|
||||||
@@ -24,29 +37,20 @@
|
|||||||
{{ error }}
|
{{ error }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="my-2 d-flex justify-content-between" v-if="apiKey">
|
<div class="my-2" v-if="apiKey && groupings.length > 0">
|
||||||
<button type="button" class="btn btn-link"
|
<button type="button" class="btn btn-link p-0"
|
||||||
v-if="groupings.length > 0"
|
@click="refreshGroupings">
|
||||||
@click="refreshGroupings">refresh groupings</button>
|
refresh groupings
|
||||||
|
</button>
|
||||||
<form @submit.prevent="saveNewGrouping" class="form-inline">
|
|
||||||
<div class="form-group">
|
|
||||||
<label class="sr-only" for="tags">Tags</label>
|
|
||||||
<input type="text" class="form-control" id="tags"
|
|
||||||
v-model="newGrouping.tags"
|
|
||||||
placeholder="new grouping tags">
|
|
||||||
</div>
|
|
||||||
<button type="submit" class="btn btn-link p-0 pl-2">add grouping</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="groupings card-columns" v-if="apiKey">
|
<div class="groupings card-columns" v-if="apiKey">
|
||||||
<div class="grouping card" v-for="(grouping, index) in groupings" v-bind:key="grouping.tags">
|
<div class="grouping card" v-for="(grouping, index) in groupings" v-bind:key="grouping.tags">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h5 class="card-title">
|
<h5 class="card-title d-flex justify-content-between">
|
||||||
{{ grouping.tags }}
|
<span>{{ grouping.tags }}</span>
|
||||||
<button type="button"
|
<button type="button"
|
||||||
class="btn btn-link"
|
class="btn btn-link p-0"
|
||||||
:dataIdx="index"
|
:dataIdx="index"
|
||||||
@click="deleteGrouping(index)">
|
@click="deleteGrouping(index)">
|
||||||
delete
|
delete
|
||||||
@@ -55,7 +59,7 @@
|
|||||||
<p class="card-text" v-if="grouping.loading">
|
<p class="card-text" v-if="grouping.loading">
|
||||||
loading...
|
loading...
|
||||||
</p>
|
</p>
|
||||||
<p class="card-text" v-else v-for="pin in grouping.pins" v-bind:key="pin.hash">
|
<p class="card-text m-0" v-else v-for="pin in grouping.pins" v-bind:key="pin.hash">
|
||||||
<a target="_blank" :href="pin.href">{{ pin.description }}</a>
|
<a target="_blank" :href="pin.href">{{ pin.description }}</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -85,33 +89,36 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
deleteGrouping(index) {
|
deleteGrouping(index) {
|
||||||
this.groupings.splice(index, 1);
|
this.groupings.splice(index, 1);
|
||||||
var data = { groupings: this.groupings };
|
this.persistGroupings();
|
||||||
chrome.storage.sync.set(data, () => { });
|
|
||||||
},
|
},
|
||||||
refreshGroupings(event) {
|
refreshGroupings(event) {
|
||||||
|
var promises = [];
|
||||||
for(var key in this.groupings) {
|
for(var key in this.groupings) {
|
||||||
var grouping = this.groupings[key];
|
var grouping = this.groupings[key];
|
||||||
grouping.loading = true;
|
grouping.loading = true;
|
||||||
grouping.pins = [];
|
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";
|
var url = "https://api.pinboard.in/v1/posts/all?format=json&results=30";
|
||||||
url += "&auth_token=" + this.apiKey;
|
url += "&auth_token=" + this.apiKey;
|
||||||
url += "&tag=" + grouping.tags;
|
url += "&tag=" + this.groupings[index].tags;
|
||||||
|
|
||||||
axios.get(url)
|
var promise = axios.get(url);
|
||||||
.then(response => {
|
promise.then(response => {
|
||||||
grouping.pins = response.data;
|
this.groupings[index].pins = response.data;
|
||||||
grouping.loading = false;
|
this.groupings[index].loading = false;
|
||||||
var data = { groupings: this.groupings };
|
|
||||||
chrome.storage.sync.set(data, () => { });
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
this.error = error;
|
this.error = error;
|
||||||
});
|
});
|
||||||
|
return promise;
|
||||||
},
|
},
|
||||||
saveNewGrouping(event) {
|
saveNewGrouping(event) {
|
||||||
this.groupings.push({
|
this.groupings.push({
|
||||||
@@ -119,29 +126,33 @@ export default {
|
|||||||
pins: [],
|
pins: [],
|
||||||
loading: true
|
loading: true
|
||||||
});
|
});
|
||||||
var data = { groupings: this.groupings };
|
|
||||||
chrome.storage.sync.set(data, () => { });
|
|
||||||
this.newGrouping = { tags: [] };
|
this.newGrouping = { tags: [] };
|
||||||
|
this.getPinsForGroup(this.groupings.length - 1)
|
||||||
this.getPinsForGroup(this.groupings[this.groupings.length - 1]);
|
.finally(() => {
|
||||||
|
this.persistGroupings();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
save(event) {
|
saveApiKey(event) {
|
||||||
var data = {
|
var data = {
|
||||||
apiKey: this.form.apiKey,
|
apiKey: this.form.apiKey,
|
||||||
groupings: this.apiKey !== this.form.apiKey ? [] : this.groupings
|
groupings: this.apiKey !== this.form.apiKey ? [] : this.groupings
|
||||||
};
|
};
|
||||||
chrome.storage.sync.set(data, () => {
|
chrome.storage.local.set(data, () => {
|
||||||
this.apiKey = data.apiKey;
|
this.apiKey = data.apiKey;
|
||||||
this.groupings = data.groupings;
|
this.groupings = data.groupings;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
persistGroupings() {
|
||||||
|
var data = { groupings: this.groupings };
|
||||||
|
chrome.storage.local.set(data, () => {});
|
||||||
|
},
|
||||||
editApiKey(event) {
|
editApiKey(event) {
|
||||||
this.form.apiKey = this.apiKey;
|
this.form.apiKey = this.apiKey;
|
||||||
this.apiKey = null;
|
this.apiKey = null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
chrome.storage.sync.get(['apiKey','groupings'], result => {
|
chrome.storage.local.get(['apiKey','groupings'], result => {
|
||||||
this.apiKey = result.apiKey;
|
this.apiKey = result.apiKey;
|
||||||
this.groupings = result.groupings;
|
this.groupings = result.groupings;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user