Skip to content

Commit b97cd66

Browse files
committed
basic implementation for fetching ungit configuration on path container
1 parent 2f94e0f commit b97cd66

File tree

4 files changed

+51
-10
lines changed

4 files changed

+51
-10
lines changed

src-react/actions/ungit-config.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as types from 'constants/action-types';
2+
export function fetchUngitConfig() {
3+
return dispatch => {
4+
// consider wrap API call in separate modules
5+
// it will be easy to stub module's function when testing
6+
fetch('http://localhost:8448/ungit/config')
7+
.then(response => response.json())
8+
.then(json => {
9+
dispatch(receiveUgitConfig(json));
10+
});
11+
};
12+
};
13+
14+
export function receiveUgitConfig(ungitConfig) {
15+
return {
16+
type: types.RECEIVE_UNGIT_CONFIG,
17+
ungitConfig
18+
};
19+
};

src-react/constants/action-types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const RECEIVE_UNGIT_CONFIG = 'RECEIVE_UNGIT_CONFIG';

src-react/containers/path.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11
import React, { Component } from 'react';
2+
import { bindActionCreators } from 'redux';
23
import { connect } from 'react-redux'
34

5+
import * as ungitConfigActionCreators from 'actions/ungit-config';
46
import 'styles/styles.scss';
57

6-
@connect(state => { return { ...state } })
8+
@connect(state => {
9+
return { ...state };
10+
}, dispatch => {
11+
return {
12+
actions: bindActionCreators(Object.assign({}, ungitConfigActionCreators), dispatch)
13+
};
14+
})
715
class Path extends Component {
16+
17+
componentWillMount() {
18+
const { actions } = this.props;
19+
actions.fetchUngitConfig();
20+
}
21+
822
render() {
923
return (
10-
<div className="App">
11-
<div className="App-header">
12-
<h2>Welcome to { this.props.app }</h2>
24+
<div>
25+
<div className="app-top-margin"></div>
26+
<div className="app-wrapper">
27+
<div className="container" data-bind="shown: shown" data-ta-container="app">
28+
</div>
1329
</div>
14-
<p className="App-intro">
15-
To get started, edit <code>src/container/Path.js</code> and save to reload.
16-
</p>
1730
</div>
1831
);
1932
}

src-react/reducers/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
import * as types from 'constants/action-types';
2+
13
const initialState = {
2-
app: 'React'
4+
ungitConfig: null
35
};
46

5-
const ungitApp = function(state, action) {
6-
return { ...initialState };
7+
const ungitApp = function(state = initialState, action) {
8+
switch(action.type) {
9+
case types.RECEIVE_UNGIT_CONFIG:
10+
const { ungitConfig } = action;
11+
return { ...state, ungitConfig };
12+
default:
13+
return { ...state };
14+
}
715
}
816

917
export default ungitApp;

0 commit comments

Comments
 (0)