Skip to content

Commit

Permalink
Showing files even for invalid config file. + Redirecting to /list wh…
Browse files Browse the repository at this point in the history
…en at / and loggedin
  • Loading branch information
Shashwat986 committed Oct 19, 2017
1 parent c3e6082 commit abead99
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
12 changes: 12 additions & 0 deletions src/js/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ const checkLogin = (to, from, next) => {
}

const routes = [
{
path: '',
beforeEnter (to, from, next) {
const state = store.state;
if (state.github.githubKey &&
!window.folderJSON.isEmpty()) {
next('/list');
} else {
next();
}
}
},
{
path: '/list/:path*',
component: List,
Expand Down
18 changes: 13 additions & 5 deletions src/js/store/gistux.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ export default {
}

// If we didn't find a config file
return context.dispatch('updateFolderJSON').then(() => {
context.dispatch('updateGistUXConfig');
});
context.dispatch('updateFolderJSON');
return context.dispatch('updateGistUXConfig');
}

// If we have an existing folderJSON object when this is called
Expand All @@ -113,8 +112,13 @@ export default {
const fileContent = resp.data.files[context.getters.gistUXFileName].content;
if (!window.folderJSON.validateFile(fileContent)) {
context.dispatch('setError', 'Invalid GistUX file found. Do you have another file with the same name?');
return Promise.reject();

// If we can't read the config file, assume there isn't one, but don't write to it
context.commit('setGistPermission', false);
context.dispatch('updateFolderJSON');
return context.dispatch('updateGistUXConfig');
}

context.dispatch('updateFolderJSON', JSON.parse(fileContent));
context.commit('setFolderJSONConfigFileID', folderJSONConfigFile.id);

Expand Down Expand Up @@ -151,7 +155,11 @@ export default {
);
}
},
updateGistUXConfig (context) {
updateGistUXConfig (context, force = false) {
// If we know that we can't write to the gist
if (!context.rootState.github.ghGistPermission && !force)
return Promise.resolve(null);

return context.dispatch(
'writeGistContent',
{
Expand Down
2 changes: 1 addition & 1 deletion src/js/store/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
gh: null,
ghUser: null,
ghUserData: null,
ghGistPermission: null
ghGistPermission: true
},
mutations: {
setGithubKey (state, key) {
Expand Down
3 changes: 3 additions & 0 deletions src/js/views/list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<br/>
Fix this by <a href="https://github.com/settings/tokens" target="_blank">regenerating your Github Token</a> and giving it the <i>gist</i> permission.
<br />
Alternatively, if you have already given the <i>gist</i> permission, this may be caused by an existing file named <code>{{$store.getters.gistUXFileName}}</code> that doesn't have valid config information.
<br />
<br />
If you wish to go ahead with this, you may import/export your temporary config file from <router-link to="/config">here</router-link>
</p>
<ol class="breadcrumb">
Expand Down

0 comments on commit abead99

Please sign in to comment.