Allow importing collections from gist

This commit is contained in:
Liyas Thomas
2020-12-08 12:05:10 +05:30
parent 346b980a1d
commit 2978c8adfe
2 changed files with 27 additions and 3 deletions

View File

@@ -14,15 +14,17 @@
<div
v-tooltip="{
content:
!fb.currentUser &&
this.$store.state.postwoman.providerInfo.providerId !== 'github.com'
? $t('login_with_github_to') + $t('create_secret_gist')
: null,
}"
>
<button class="icon" @click="readCollectionGist" v-close-popover>
<i class="material-icons">code</i>
<span>{{ $t("import_from_gist") }}</span>
</button>
<button
:disabled="
!fb.currentUser &&
this.$store.state.postwoman.providerInfo.providerId !== 'github.com'
"
class="icon"
@@ -153,6 +155,26 @@ export default {
console.log(error)
})
},
async readCollectionGist() {
let gist = prompt(this.$t("enter_gist_url"))
if (!gist) return
await this.$axios
.$get(`https://api.github.com/gists/${gist.split("/").pop()}`, {
headers: {
Accept: "application/vnd.github.v3+json",
},
})
.then((response) => {
let collections = JSON.parse(Object.values(response.files)[0].content)
this.$store.commit("postwoman/replaceCollections", collections)
this.fileImported()
this.syncToFBCollections()
})
.catch((error) => {
this.failedImport()
console.log(error)
})
},
hideModal() {
this.$emit("hide-modal")
},

View File

@@ -297,5 +297,7 @@
"select_environment": "Select environment",
"login_with_github_to": "Login with GitHub to ",
"create_secret_gist": "Create secret Gist",
"gist_created": "Gist created"
"gist_created": "Gist created",
"import_from_gist": "Import from Gist",
"enter_gist_url": "Enter Gist URL"
}