Initial MVP of GitHub gist support
This commit is contained in:
@@ -6,6 +6,35 @@
|
|||||||
<div class="row-wrapper">
|
<div class="row-wrapper">
|
||||||
<h3 class="title">{{ $t("import_export") }} {{ $t("collections") }}</h3>
|
<h3 class="title">{{ $t("import_export") }} {{ $t("collections") }}</h3>
|
||||||
<div>
|
<div>
|
||||||
|
<v-popover>
|
||||||
|
<button class="tooltip-target icon" v-tooltip.left="$t('more')">
|
||||||
|
<i class="material-icons">more_vert</i>
|
||||||
|
</button>
|
||||||
|
<template slot="popover">
|
||||||
|
<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
|
||||||
|
:disabled="
|
||||||
|
!fb.currentUser &&
|
||||||
|
this.$store.state.postwoman.providerInfo.providerId !== 'github.com'
|
||||||
|
"
|
||||||
|
class="icon"
|
||||||
|
@click="createCollectionGist"
|
||||||
|
v-close-popover
|
||||||
|
>
|
||||||
|
<i class="material-icons">code</i>
|
||||||
|
<span>{{ $t("create_secret_gist") }}</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</v-popover>
|
||||||
<button class="icon" @click="hideModal">
|
<button class="icon" @click="hideModal">
|
||||||
<closeIcon class="material-icons" />
|
<closeIcon class="material-icons" />
|
||||||
</button>
|
</button>
|
||||||
@@ -97,6 +126,37 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
async createCollectionGist() {
|
||||||
|
await this.$axios
|
||||||
|
.$post(
|
||||||
|
"https://api.github.com/gists",
|
||||||
|
{
|
||||||
|
files: {
|
||||||
|
"hoppscotch-collections.json": {
|
||||||
|
content: this.collectionJson,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `token ${this.$store.state.postwoman.providerInfo.accessToken}`,
|
||||||
|
Accept: "application/vnd.github.v3+json",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.then((response) => {
|
||||||
|
this.$toast.success(this.$t("gist_created"), {
|
||||||
|
icon: "done",
|
||||||
|
})
|
||||||
|
window.open(response.html_url)
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
this.$toast.error(this.$t("something_went_wrong"), {
|
||||||
|
icon: "error",
|
||||||
|
})
|
||||||
|
console.log(error)
|
||||||
|
})
|
||||||
|
},
|
||||||
hideModal() {
|
hideModal() {
|
||||||
this.$emit("hide-modal")
|
this.$emit("hide-modal")
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -109,7 +109,12 @@ export default {
|
|||||||
},
|
},
|
||||||
async signInWithGithub() {
|
async signInWithGithub() {
|
||||||
try {
|
try {
|
||||||
const { additionalUserInfo } = await fb.signInUserWithGithub()
|
const { credential, additionalUserInfo } = await fb.signInUserWithGithub()
|
||||||
|
|
||||||
|
this.$store.commit("postwoman/setProviderInfo", {
|
||||||
|
providerId: "github.com",
|
||||||
|
accessToken: credential.accessToken,
|
||||||
|
})
|
||||||
|
|
||||||
if (additionalUserInfo.isNewUser) {
|
if (additionalUserInfo.isNewUser) {
|
||||||
this.$toast.info(`${this.$t("turn_on")} ${this.$t("sync")}`, {
|
this.$toast.info(`${this.$t("turn_on")} ${this.$t("sync")}`, {
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ export class FirebaseInstance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async signInUserWithGithub() {
|
async signInUserWithGithub() {
|
||||||
return await this.app.auth().signInWithPopup(this.authProviders.github())
|
return await this.app.auth().signInWithPopup(this.authProviders.github().addScope("repo gist"))
|
||||||
}
|
}
|
||||||
|
|
||||||
async signInWithEmailAndPassword(email, password) {
|
async signInWithEmailAndPassword(email, password) {
|
||||||
|
|||||||
@@ -294,5 +294,8 @@
|
|||||||
"experiments": "Experiments",
|
"experiments": "Experiments",
|
||||||
"experiments_notice": "This is a collection of experiments we're working on that might turn out to be useful, fun, both, or neither. They're not final and may not be stable, so if something overly weird happens, don't panic. Just turn the dang thing off. Jokes aside, ",
|
"experiments_notice": "This is a collection of experiments we're working on that might turn out to be useful, fun, both, or neither. They're not final and may not be stable, so if something overly weird happens, don't panic. Just turn the dang thing off. Jokes aside, ",
|
||||||
"use_experimental_url_bar": "Use experimental URL bar with environment highlighting",
|
"use_experimental_url_bar": "Use experimental URL bar with environment highlighting",
|
||||||
"select_environment": "Select environment"
|
"select_environment": "Select environment",
|
||||||
|
"login_with_github_to": "Login with GitHub to ",
|
||||||
|
"create_secret_gist": "Create secret Gist",
|
||||||
|
"gist_created": "Gist created"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ export const state = () => ({
|
|||||||
editingEnvironment: {},
|
editingEnvironment: {},
|
||||||
selectedRequest: {},
|
selectedRequest: {},
|
||||||
editingRequest: {},
|
editingRequest: {},
|
||||||
|
providerInfo: {},
|
||||||
})
|
})
|
||||||
|
|
||||||
export const mutations = {
|
export const mutations = {
|
||||||
@@ -335,6 +336,10 @@ export const mutations = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setProviderInfo(state, value) {
|
||||||
|
state.providerInfo = value
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
function testValue(myValue) {
|
function testValue(myValue) {
|
||||||
|
|||||||
Reference in New Issue
Block a user