@@ -19,7 +19,7 @@ import {
1919} from '/components' ;
2020import { CategoryApi , GitHubApi } from '/apis' ;
2121import { actions } from '/reducers' ;
22- import { extension , refineGist } from '/common/util' ;
22+ import { extension , handleError , refineGist } from '/common/util' ;
2323import { exts , languages , us } from '/common/config' ;
2424import { README_MD , SCRATCH_PAPER_MD } from '/skeletons' ;
2525import styles from './stylesheet.scss' ;
@@ -51,7 +51,7 @@ class App extends React.Component {
5151
5252 CategoryApi . getCategories ( )
5353 . then ( ( { categories } ) => this . props . setCategories ( categories ) )
54- . catch ( this . props . showErrorToast ) ;
54+ . catch ( handleError . bind ( this ) ) ;
5555
5656 window . onbeforeunload = ( ) => this . isGistSaved ( ) ? undefined : 'Changes you made will not be saved.' ;
5757 }
@@ -90,6 +90,7 @@ class App extends React.Component {
9090 . then ( user => {
9191 const { login, avatar_url } = user ;
9292 this . props . setUser ( { login, avatar_url } ) ;
93+ Cookies . set ( 'login' , login ) ;
9394 } )
9495 . then ( ( ) => this . loadScratchPapers ( ) )
9596 . catch ( ( ) => this . signOut ( ) ) ;
@@ -98,7 +99,10 @@ class App extends React.Component {
9899 signOut ( ) {
99100 Cookies . remove ( 'access_token' ) ;
100101 GitHubApi . auth ( undefined )
101- . then ( ( ) => this . props . setUser ( undefined ) )
102+ . then ( ( ) => {
103+ this . props . setUser ( undefined ) ;
104+ Cookies . remove ( 'login' ) ;
105+ } )
102106 . then ( ( ) => this . props . setScratchPapers ( [ ] ) ) ;
103107 }
104108
@@ -122,7 +126,7 @@ class App extends React.Component {
122126 } ) ;
123127 return paginateGists ( )
124128 . then ( scratchPapers => this . props . setScratchPapers ( scratchPapers ) )
125- . catch ( this . props . showErrorToast ) ;
129+ . catch ( handleError . bind ( this ) ) ;
126130 }
127131
128132 loadAlgorithm ( { categoryKey, algorithmKey, gistId } , forceLoad = false ) {
@@ -133,7 +137,8 @@ class App extends React.Component {
133137 if ( categoryKey && algorithmKey ) {
134138 fetchPromise = CategoryApi . getAlgorithm ( categoryKey , algorithmKey )
135139 . then ( ( { algorithm } ) => algorithm ) ;
136- } else if ( gistId === 'new' ) {
140+ } else if ( [ 'new' , 'forked' ] . includes ( gistId ) ) {
141+ gistId = 'new' ;
137142 const language = languages . find ( language => language . ext === ext ) ;
138143 fetchPromise = Promise . resolve ( {
139144 titles : [ 'Scratch Paper' , 'Untitled' ] ,
@@ -153,12 +158,15 @@ class App extends React.Component {
153158 fetchPromise = Promise . reject ( new Error ( ) ) ;
154159 }
155160 fetchPromise
156- . then ( algorithm => this . props . setCurrent ( categoryKey , algorithmKey , gistId , algorithm . titles , algorithm . files ) )
157- . catch ( ( ) => this . props . setCurrent ( undefined , undefined , undefined , [ 'Algorithm Visualizer' ] , [ {
158- name : 'README.md' ,
159- content : README_MD ,
160- contributors : [ us ] ,
161- } ] ) )
161+ . then ( algorithm => this . props . setCurrent ( categoryKey , algorithmKey , gistId , algorithm . titles , algorithm . files , algorithm . gist ) )
162+ . catch ( error => {
163+ if ( error . message ) handleError . bind ( this ) ( error ) ;
164+ this . props . setCurrent ( undefined , undefined , undefined , [ 'Algorithm Visualizer' ] , [ {
165+ name : 'README.md' ,
166+ content : README_MD ,
167+ contributors : [ us ] ,
168+ } ] , undefined ) ;
169+ } )
162170 . finally ( ( ) => {
163171 const { files } = this . props . current ;
164172 let editorTabIndex = files . findIndex ( file => extension ( file . name ) === ext ) ;
0 commit comments