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 => (
31
31
. then ( json => dispatch ( setSyntaxes ( json ) ) )
32
32
) ;
33
33
34
- export const postSnippet = snippet => dispatch => (
34
+ export const postSnippet = ( snippet , onSuccess ) => dispatch => (
35
35
fetch ( 'http://api.xsnippet.org/snippets' , {
36
36
method : 'POST' ,
37
37
headers : {
@@ -41,5 +41,8 @@ export const postSnippet = snippet => dispatch => (
41
41
body : JSON . stringify ( snippet ) ,
42
42
} )
43
43
. then ( response => response . json ( ) )
44
- . then ( json => dispatch ( setSnippet ( json ) ) )
44
+ . then ( ( json ) => {
45
+ dispatch ( setSnippet ( json ) ) ;
46
+ onSuccess ( json ) ;
47
+ } )
45
48
) ;
Original file line number Diff line number Diff line change @@ -42,8 +42,8 @@ class NewSnippet extends React.Component {
42
42
43
43
postSnippet ( e ) {
44
44
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 } ` ) ) ) ;
47
47
}
48
48
49
49
render ( ) {
You can’t perform that action at this time.
0 commit comments