Skip to content
This repository has been archived by the owner on Jun 26, 2024. It is now read-only.

Commit

Permalink
fix(proposal): quit loading screen when sending proposal fails
Browse files Browse the repository at this point in the history
  • Loading branch information
vhf committed Oct 28, 2019
1 parent c7ffa09 commit ca2d7b7
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 32 deletions.
21 changes: 13 additions & 8 deletions api/github/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const helpersFactory = require('./helpers')
const octokitFactory = require('@octokit/rest')
const debug = require('debug')('editor:api')

const __cache = new Map()

module.exports = class GitHubAPIv3 {
constructor ({ forge, editor, ontology }) {
debug('new GitHubAPIv3')
Expand All @@ -27,26 +29,29 @@ module.exports = class GitHubAPIv3 {
const { getRefSHA, getFileSHA } = helpersFactory(this.__octokit)
this.__getRefSHA = getRefSHA
this.__getFileSHA = getFileSHA

this.__cache = new Map()
}

async createBranch () {
const owner = this.owner
const repo = this.repo
const sha = await this.__getRefSHA({
const getRefSHAParams = {
ref: `heads/${this.branch}`,
owner,
repo
})
}
debug('createBranch: getting SHA for ref', getRefSHAParams)
const sha = await this.__getRefSHA(getRefSHAParams)

const branchName = (new Date()).toISOString().replace(/:/g, '')
await this.__octokit.git.createRef({

const createRefParams = {
ref: `refs/heads/${branchName}`,
sha,
owner,
repo
})
}
debug('createBranch: creating ref', createRefParams)
await this.__octokit.git.createRef(createRefParams)

return {
name: branchName
Expand All @@ -59,15 +64,15 @@ module.exports = class GitHubAPIv3 {
const ref = `heads/${branch}`
const query = { owner, repo, path, ref }

const cached = this.__cache.get(`${ref}/${path}`)
const cached = __cache.get(`${ref}/${path}`)
const headers = cached ? { 'If-Modified-Since': cached.lastModified } : {}

let content
try {
const response = await this.__octokit.repos.getContents({ ...query, headers })
content = Buffer.from(response.data.content, 'base64').toString()
const lastModified = response.headers['last-modified']
this.__cache.set(`${ref}/${path}`, { lastModified, content })
__cache.set(`${ref}/${path}`, { lastModified, content })
}
catch (error) {
// '304 not modified', let's serve cached version
Expand Down
32 changes: 20 additions & 12 deletions pages/proposal/class.vue
Original file line number Diff line number Diff line change
Expand Up @@ -275,19 +275,27 @@ export default {
load: LOAD
}),
async sendProposal () {
// Send splash screen
this.isLoading = true
// remove draft status from the json proposalObject
this.$vuexSet('class.clss.isDraft', false)
// save the changes
await this.autosaveDraft()
this.stopAutosave()
try {
// Send splash screen
this.isLoading = true
// remove draft status from the json proposalObject
this.$vuexSet('class.clss.isDraft', false)
// save the changes
await this.autosaveDraft()
this.stopAutosave()
const token = this.$apolloHelpers.getToken()
// create the PR etc
await this.submit(token)
// submit will commit success or error to the store,
// see this page's `watch`ers
const token = this.$apolloHelpers.getToken()
// create the PR etc
await this.submit(token)
// submit will commit success or error to the store,
// see this page's `watch`ers
}
catch (err) {
this.$vuexSet('class.clss.isDraft', true)
// save the changes
await this.autosaveDraft()
this.isLoading = false
}
},
stopAutosave () {
clearInterval(this.saveInterval)
Expand Down
31 changes: 19 additions & 12 deletions pages/proposal/property.vue
Original file line number Diff line number Diff line change
Expand Up @@ -273,19 +273,26 @@ export default {
load: LOAD
}),
async sendProposal () {
// Send splash screen
this.isLoading = true
// remove draft status from the json proposalObject
this.$vuexSet('prop.prop.isDraft', false)
// save the changes
await this.autosaveDraft()
this.stopAutosave()
try {
// Send splash screen
this.isLoading = true
// remove draft status from the json proposalObject
this.$vuexSet('prop.prop.isDraft', false)
// save the changes
await this.autosaveDraft()
this.stopAutosave()
const token = this.$apolloHelpers.getToken()
// create the PR etc
await this.submit(token)
// submit will commit success or error to the store,
// see this page's `watch`ers
const token = this.$apolloHelpers.getToken()
// create the PR etc
await this.submit(token)
// submit will commit success or error to the store,
// see this page's `watch`ers
}
catch (err) {
this.$vuexSet('prop.prop.isDraft', true)
await this.autosaveDraft()
this.isLoading = false
}
},
stopAutosave () {
clearInterval(this.saveInterval)
Expand Down

0 comments on commit ca2d7b7

Please sign in to comment.