@@ -4,6 +4,7 @@ import { connect } from 'react-redux';
44import Promise from 'bluebird' ;
55import { Helmet } from 'react-helmet' ;
66import AutosizeInput from 'react-input-autosize' ;
7+ import queryString from 'query-string' ;
78import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' ;
89import faPlus from '@fortawesome/fontawesome-free-solid/faPlus' ;
910import {
@@ -16,9 +17,9 @@ import {
1617 ToastContainer ,
1718 VisualizationViewer ,
1819} from '/components' ;
19- import { AlgorithmApi , GitHubApi } from '/apis' ;
20+ import { AlgorithmApi , GitHubApi , VisualizationApi } from '/apis' ;
2021import { actions } from '/reducers' ;
21- import { extension , refineGist } from '/common/util' ;
22+ import { createUserFile , extension , refineGist } from '/common/util' ;
2223import { exts , languages } from '/common/config' ;
2324import { CONTRIBUTING_MD } from '/files' ;
2425import styles from './stylesheet.scss' ;
@@ -43,7 +44,9 @@ class App extends BaseComponent {
4344 window . signIn = this . signIn . bind ( this ) ;
4445 window . signOut = this . signOut . bind ( this ) ;
4546
46- this . loadAlgorithm ( this . props . match . params ) ;
47+ const { params } = this . props . match ;
48+ const { search } = this . props . location ;
49+ this . loadAlgorithm ( params , queryString . parse ( search ) ) ;
4750
4851 const accessToken = Cookies . get ( 'access_token' ) ;
4952 if ( accessToken ) this . signIn ( accessToken ) ;
@@ -64,12 +67,13 @@ class App extends BaseComponent {
6467
6568 componentWillReceiveProps ( nextProps ) {
6669 const { params } = nextProps . match ;
67- if ( params !== this . props . match . params ) {
70+ const { search } = nextProps . location ;
71+ if ( params !== this . props . match . params || search !== this . props . location . search ) {
6872 const { categoryKey, algorithmKey, gistId } = params ;
6973 const { algorithm, scratchPaper } = nextProps . current ;
7074 if ( algorithm && algorithm . categoryKey === categoryKey && algorithm . algorithmKey === algorithmKey ) return ;
7175 if ( scratchPaper && scratchPaper . gistId === gistId ) return ;
72- this . loadAlgorithm ( params ) ;
76+ this . loadAlgorithm ( params , queryString . parse ( search ) ) ;
7377 }
7478 }
7579
@@ -138,7 +142,7 @@ class App extends BaseComponent {
138142 . catch ( this . handleError ) ;
139143 }
140144
141- loadAlgorithm ( { categoryKey, algorithmKey, gistId } ) {
145+ loadAlgorithm ( { categoryKey, algorithmKey, gistId } , { visualizationId } ) {
142146 const { ext } = this . props . env ;
143147 const fetch = ( ) => {
144148 if ( window . __PRELOADED_ALGORITHM__ ) {
@@ -147,6 +151,16 @@ class App extends BaseComponent {
147151 } else if ( categoryKey && algorithmKey ) {
148152 return AlgorithmApi . getAlgorithm ( categoryKey , algorithmKey )
149153 . then ( ( { algorithm } ) => this . props . setAlgorithm ( algorithm ) ) ;
154+ } else if ( gistId === 'new' && visualizationId ) {
155+ return VisualizationApi . getVisualization ( visualizationId )
156+ . then ( content => {
157+ this . props . setScratchPaper ( {
158+ login : undefined ,
159+ gistId,
160+ title : 'Untitled' ,
161+ files : [ CONTRIBUTING_MD , createUserFile ( 'traces.json' , JSON . stringify ( content ) ) ] ,
162+ } ) ;
163+ } ) ;
150164 } else if ( gistId === 'new' ) {
151165 const language = languages . find ( language => language . ext === ext ) ;
152166 this . props . setScratchPaper ( {
@@ -175,7 +189,8 @@ class App extends BaseComponent {
175189 selectDefaultTab ( ) {
176190 const { ext } = this . props . env ;
177191 const { files } = this . props . current ;
178- let editorTabIndex = files . findIndex ( file => extension ( file . name ) === ext ) ;
192+ let editorTabIndex = files . findIndex ( file => extension ( file . name ) === 'json' ) ;
193+ if ( ! ~ editorTabIndex ) files . findIndex ( file => extension ( file . name ) === ext ) ;
179194 if ( ! ~ editorTabIndex ) editorTabIndex = files . findIndex ( file => exts . includes ( extension ( file . name ) ) ) ;
180195 if ( ! ~ editorTabIndex ) editorTabIndex = Math . min ( 0 , files . length - 1 ) ;
181196 this . handleChangeEditorTabIndex ( editorTabIndex ) ;
0 commit comments