Skip to content

Commit 41f83b4

Browse files
authored
Merge pull request #27 from xsnippet/redirect-new-snippet
Add redirect to newly added snippet
2 parents 4c2bd61 + 658a1f2 commit 41f83b4

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/actions/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff 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
);

src/components/NewSnippet.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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() {

0 commit comments

Comments
 (0)