This commit is contained in:
Liyas Thomas
2020-05-10 07:10:32 +05:30
parent 77471a5f56
commit 80d0925ed7
2 changed files with 50 additions and 42 deletions

View File

@@ -21,7 +21,7 @@ const usersCollection = firebase.firestore().collection("users")
// the shared state object that any vue component // the shared state object that any vue component
// can get access to // can get access to
export const fb = { export const fb = {
currentUser: {}, currentUser: null,
currentFeeds: [], currentFeeds: [],
currentSettings: [], currentSettings: [],
currentHistory: [], currentHistory: [],
@@ -40,15 +40,15 @@ export const fb = {
.doc(fb.currentUser.uid) .doc(fb.currentUser.uid)
.collection("feeds") .collection("feeds")
.add(dt) .add(dt)
.catch(e => console.error("error inserting", dt, e)) .catch((e) => console.error("error inserting", dt, e))
}, },
deleteFeed: id => { deleteFeed: (id) => {
usersCollection usersCollection
.doc(fb.currentUser.uid) .doc(fb.currentUser.uid)
.collection("feeds") .collection("feeds")
.doc(id) .doc(id)
.delete() .delete()
.catch(e => console.error("error deleting", id, e)) .catch((e) => console.error("error deleting", id, e))
}, },
writeSettings: async (setting, value) => { writeSettings: async (setting, value) => {
const st = { const st = {
@@ -64,23 +64,23 @@ export const fb = {
.collection("settings") .collection("settings")
.doc(setting) .doc(setting)
.set(st) .set(st)
.catch(e => console.error("error updating", st, e)) .catch((e) => console.error("error updating", st, e))
}, },
writeHistory: async entry => { writeHistory: async (entry) => {
const hs = entry const hs = entry
usersCollection usersCollection
.doc(fb.currentUser.uid) .doc(fb.currentUser.uid)
.collection("history") .collection("history")
.add(hs) .add(hs)
.catch(e => console.error("error inserting", hs, e)) .catch((e) => console.error("error inserting", hs, e))
}, },
deleteHistory: entry => { deleteHistory: (entry) => {
usersCollection usersCollection
.doc(fb.currentUser.uid) .doc(fb.currentUser.uid)
.collection("history") .collection("history")
.doc(entry.id) .doc(entry.id)
.delete() .delete()
.catch(e => console.error("error deleting", entry, e)) .catch((e) => console.error("error deleting", entry, e))
}, },
clearHistory: () => { clearHistory: () => {
usersCollection usersCollection
@@ -88,7 +88,7 @@ export const fb = {
.collection("history") .collection("history")
.get() .get()
.then(({ docs }) => { .then(({ docs }) => {
docs.forEach(e => fb.deleteHistory(e)) docs.forEach((e) => fb.deleteHistory(e))
}) })
}, },
toggleStar: (entry, value) => { toggleStar: (entry, value) => {
@@ -97,9 +97,9 @@ export const fb = {
.collection("history") .collection("history")
.doc(entry.id) .doc(entry.id)
.update({ star: value }) .update({ star: value })
.catch(e => console.error("error deleting", entry, e)) .catch((e) => console.error("error deleting", entry, e))
}, },
writeCollections: async collection => { writeCollections: async (collection) => {
const cl = { const cl = {
updatedOn: new Date(), updatedOn: new Date(),
author: fb.currentUser.uid, author: fb.currentUser.uid,
@@ -112,9 +112,9 @@ export const fb = {
.collection("collections") .collection("collections")
.doc("sync") .doc("sync")
.set(cl) .set(cl)
.catch(e => console.error("error updating", cl, e)) .catch((e) => console.error("error updating", cl, e))
}, },
writeEnvironments: async environment => { writeEnvironments: async (environment) => {
const ev = { const ev = {
updatedOn: new Date(), updatedOn: new Date(),
author: fb.currentUser.uid, author: fb.currentUser.uid,
@@ -127,15 +127,15 @@ export const fb = {
.collection("environments") .collection("environments")
.doc("sync") .doc("sync")
.set(ev) .set(ev)
.catch(e => console.error("error updating", ev, e)) .catch((e) => console.error("error updating", ev, e))
}, },
} }
// When a user logs in or out, save that in the store // When a user logs in or out, save that in the store
firebase.auth().onAuthStateChanged(user => { firebase.auth().onAuthStateChanged((user) => {
if (user) { if (user) {
fb.currentUser = user fb.currentUser = user
fb.currentUser.providerData.forEach(profile => { fb.currentUser.providerData.forEach((profile) => {
let us = { let us = {
updatedOn: new Date(), updatedOn: new Date(),
provider: profile.providerId, provider: profile.providerId,
@@ -147,16 +147,16 @@ firebase.auth().onAuthStateChanged(user => {
usersCollection usersCollection
.doc(fb.currentUser.uid) .doc(fb.currentUser.uid)
.set(us) .set(us)
.catch(e => console.error("error updating", us, e)) .catch((e) => console.error("error updating", us, e))
}) })
usersCollection usersCollection
.doc(fb.currentUser.uid) .doc(fb.currentUser.uid)
.collection("feeds") .collection("feeds")
.orderBy("createdOn", "desc") .orderBy("createdOn", "desc")
.onSnapshot(feedsRef => { .onSnapshot((feedsRef) => {
const feeds = [] const feeds = []
feedsRef.forEach(doc => { feedsRef.forEach((doc) => {
const feed = doc.data() const feed = doc.data()
feed.id = doc.id feed.id = doc.id
feeds.push(feed) feeds.push(feed)
@@ -167,9 +167,9 @@ firebase.auth().onAuthStateChanged(user => {
usersCollection usersCollection
.doc(fb.currentUser.uid) .doc(fb.currentUser.uid)
.collection("settings") .collection("settings")
.onSnapshot(settingsRef => { .onSnapshot((settingsRef) => {
const settings = [] const settings = []
settingsRef.forEach(doc => { settingsRef.forEach((doc) => {
const setting = doc.data() const setting = doc.data()
setting.id = doc.id setting.id = doc.id
settings.push(setting) settings.push(setting)
@@ -180,9 +180,9 @@ firebase.auth().onAuthStateChanged(user => {
usersCollection usersCollection
.doc(fb.currentUser.uid) .doc(fb.currentUser.uid)
.collection("history") .collection("history")
.onSnapshot(historyRef => { .onSnapshot((historyRef) => {
const history = [] const history = []
historyRef.forEach(doc => { historyRef.forEach((doc) => {
const entry = doc.data() const entry = doc.data()
entry.id = doc.id entry.id = doc.id
history.push(entry) history.push(entry)
@@ -193,9 +193,9 @@ firebase.auth().onAuthStateChanged(user => {
usersCollection usersCollection
.doc(fb.currentUser.uid) .doc(fb.currentUser.uid)
.collection("collections") .collection("collections")
.onSnapshot(collectionsRef => { .onSnapshot((collectionsRef) => {
const collections = [] const collections = []
collectionsRef.forEach(doc => { collectionsRef.forEach((doc) => {
const collection = doc.data() const collection = doc.data()
collection.id = doc.id collection.id = doc.id
collections.push(collection) collections.push(collection)
@@ -206,9 +206,9 @@ firebase.auth().onAuthStateChanged(user => {
usersCollection usersCollection
.doc(fb.currentUser.uid) .doc(fb.currentUser.uid)
.collection("environments") .collection("environments")
.onSnapshot(environmentsRef => { .onSnapshot((environmentsRef) => {
const environments = [] const environments = []
environmentsRef.forEach(doc => { environmentsRef.forEach((doc) => {
const environment = doc.data() const environment = doc.data()
environment.id = doc.id environment.id = doc.id
environments.push(environment) environments.push(environment)

View File

@@ -263,13 +263,13 @@
</label> </label>
<input ref="payload" name="payload" type="file" @change="uploadPayload" /> <input ref="payload" name="payload" type="file" @change="uploadPayload" />
<button <button
class="icon" class="icon"
@click="prettifyRequestBody()" @click="prettifyRequestBody()"
v-tooltip="$t('prettify_body')" v-tooltip="$t('prettify_body')"
v-if="rawInput && this.contentType.endsWith('json')" v-if="rawInput && this.contentType.endsWith('json')"
> >
<i class="material-icons">assistant</i> <i class="material-icons">assistant</i>
</button> </button>
</div> </div>
</div> </div>
</li> </li>
@@ -858,8 +858,8 @@
</li> </li>
<li> <li>
<span class="select-wrapper"> <span class="select-wrapper">
<select <select
:name="'type' + index" :name="'type' + index"
@change=" @change="
$store.commit('setTypeParams', { $store.commit('setTypeParams', {
index, index,
@@ -867,8 +867,12 @@
}) })
" "
> >
<option value="query" :selected="param.type === 'query'">{{ $t("query") }}</option> <option value="query" :selected="param.type === 'query'">{{
<option value="path" :selected="param.type === 'path'">{{ $t("path") }}</option> $t("query")
}}</option>
<option value="path" :selected="param.type === 'path'">{{
$t("path")
}}</option>
</select> </select>
</span> </span>
</li> </li>
@@ -1329,7 +1333,11 @@ import { tokenRequest, oauthRedirect } from "../assets/js/oauth"
import { sendNetworkRequest } from "../functions/network" import { sendNetworkRequest } from "../functions/network"
import { fb } from "../functions/fb" import { fb } from "../functions/fb"
import { getEditorLangForMimeType } from "~/functions/editorutils" import { getEditorLangForMimeType } from "~/functions/editorutils"
import { hasPathParams, addPathParamsToVariables, getQueryParams } from "../functions/requestParams.js" import {
hasPathParams,
addPathParamsToVariables,
getQueryParams,
} from "../functions/requestParams.js"
import { parseUrlAndPath } from "../functions/utils/uri.js" import { parseUrlAndPath } from "../functions/utils/uri.js"
const statusCategories = [ const statusCategories = [
{ {
@@ -2193,7 +2201,7 @@ export default {
} }
})() })()
} catch (error) { } catch (error) {
console.error(error) console.log(error)
if (error.response) { if (error.response) {
this.response.headers = error.response.headers this.response.headers = error.response.headers
this.response.status = error.response.status this.response.status = error.response.status
@@ -2357,7 +2365,7 @@ export default {
url: window.location.href, url: window.location.href,
}) })
.then(() => {}) .then(() => {})
.catch(console.error) .catch(() => {})
} else { } else {
const dummy = document.createElement("input") const dummy = document.createElement("input")
document.body.appendChild(dummy) document.body.appendChild(dummy)