Skip to content

Commit

Permalink
Fix URL bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
mfix22 committed Oct 26, 2017
1 parent bdc9211 commit 8dec652
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 1 addition & 2 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ async function tweet(encodedImage) {
.catch(checkIfRateLimited)
}

const getGist = id => {
const uid = id.split('/').pop()
const getGist = uid => {
return gistClient
.get(`/gists/${uid}`)
.then(res => res.data)
Expand Down
6 changes: 3 additions & 3 deletions pages/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ import { getState, saveState } from '../lib/util'

const removeQueryString = str => {
const qI = str.indexOf('?')
return str.slice(1, qI)
return qI > 0 ? str.substr(0, qI) : str
}

class Editor extends React.Component {
static async getInitialProps({ asPath, query }) {
const path = removeQueryString(asPath)
const path = removeQueryString(asPath.split('/').pop())
const queryParams = getQueryStringState(query)
const initialState = Object.keys(queryParams).length ? queryParams : null
try {
// TODO fix this hack
if (path.length >= 20 && path.indexOf('.') === -1) {
if (path.length >= 19 && path.indexOf('.') === -1) {
const content = await api.getGist(path)
return { content, initialState }
}
Expand Down

0 comments on commit 8dec652

Please sign in to comment.