File tree Expand file tree Collapse file tree 2 files changed +7
-4
lines changed
Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ export const fetchSyntaxes = dispatch => (
3131 . then ( json => dispatch ( setSyntaxes ( json ) ) )
3232) ;
3333
34- export const postSnippet = snippet => dispatch => (
34+ export const postSnippet = ( snippet , onSuccess ) => dispatch => (
3535 fetch ( 'http://api.xsnippet.org/snippets' , {
3636 method : 'POST' ,
3737 headers : {
@@ -41,5 +41,8 @@ export const postSnippet = snippet => dispatch => (
4141 body : JSON . stringify ( snippet ) ,
4242 } )
4343 . then ( response => response . json ( ) )
44- . then ( json => dispatch ( setSnippet ( json ) ) )
44+ . then ( ( json ) => {
45+ dispatch ( setSnippet ( json ) ) ;
46+ onSuccess ( json ) ;
47+ } )
4548) ;
Original file line number Diff line number Diff line change @@ -42,8 +42,8 @@ class NewSnippet extends React.Component {
4242
4343 postSnippet ( e ) {
4444 e . preventDefault ( ) ;
45- const { dispatch } = this . props ;
46- dispatch ( actions . postSnippet ( this . state ) ) ;
45+ const { dispatch, history } = this . props ;
46+ dispatch ( actions . postSnippet ( this . state , json => history . push ( `/ ${ json . id } ` ) ) ) ;
4747 }
4848
4949 render ( ) {
You can’t perform that action at this time.
0 commit comments