-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
namlook
committed
Jun 15, 2016
1 parent
e2c3e4e
commit 21b249b
Showing
25 changed files
with
635 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
|
||
export Component from './RecordFormWidget'; | ||
export * as actions from '../../../stores/RecordStore/actions'; | ||
export * as constants from '../../../stores/RecordStore/constants'; | ||
export * as actions from '../../../stores/record-store/actions'; | ||
export * as constants from '../../../stores/record-store/constants'; | ||
export reducer from './reducer'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/components/contrib/collection-query-widget/CollectionQueryWidget.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React, { PropTypes } from 'react'; | ||
|
||
// import CardWidget from 'odyssee-client/lib/components/widgets/CardWidget'; | ||
|
||
class CollectionQueryWidget extends React.Component { | ||
|
||
componentWillMount() { | ||
// this.initStore(); | ||
const { ownActions } = this.props; | ||
ownActions.fetchData(); | ||
} | ||
// | ||
// initStore() { | ||
// const { params, collectionStore, linkedRouteParams, ownActions } = this.props; | ||
// const requestedRecord = findRecordFromStore(collectionStore, linkedRouteParams, params); | ||
// if (requestedRecord) { | ||
// ownActions.update(requestedRecord); | ||
// } else { | ||
// ownActions.clear(); | ||
// } | ||
// } | ||
|
||
render() { | ||
// const { collectionActions, ...other } = this.props; | ||
|
||
return null; | ||
// return ( | ||
// <CardWidget _name="collection-query" {...other}> | ||
// <p><button onClick={() => collectionActions.fetchCollection()}>fetch</button> expense</p> | ||
// </CardWidget> | ||
// ); | ||
} | ||
} | ||
|
||
CollectionQueryWidget.propTypes = { | ||
params: PropTypes.object.isRequired, | ||
linkedRouteParams: PropTypes.object, | ||
ownStore: PropTypes.object.isRequired, | ||
ownActions: PropTypes.object.isRequired, | ||
fields: PropTypes.array.isRequired, | ||
}; | ||
|
||
export default CollectionQueryWidget; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
|
||
import { FETCH_REQUEST } from './constants'; | ||
// import { FETCH_REQUEST, FETCH_FAIL, FETCH_SUCCESS } from './constants'; | ||
import { createAction } from '../../../utils'; | ||
|
||
import { addBulkRecords } from '../../../stores/collection-store/actions'; | ||
import { pushMessage } from '../flash-messages-widget/actions'; | ||
|
||
const fetchRequested = createAction(FETCH_REQUEST); | ||
// const fetchSucceed = createAction(FETCH_SUCCESS, 'payload'); | ||
// const fetchFailed = createAction(FETCH_FAIL, 'error'); | ||
|
||
// const fetchRequested = (_storeName) => () => ({ type: FETCH_REQUEST, _storeName, }); | ||
// const fetchSucceed = (_storeName) => (data) => | ||
// ({ type: FETCH_SUCCESS, payload: data, _storeName }); | ||
// const fetchFailed = (_storeName) => (error) => ({ type: FETCH_FAIL, error, _storeName }); | ||
|
||
const checkStatus = (response) => { | ||
if (response.status >= 200 && response.status < 300) { | ||
return response; | ||
} | ||
const error = new Error(response.statusText); | ||
error.response = response; | ||
throw error; | ||
}; | ||
|
||
export const fetchData = (storeName, storeConfig) => { | ||
const fetchRequestedAction = fetchRequested(storeName); | ||
|
||
const addBulkRecordsAction = addBulkRecords(storeConfig.linkedStores.collection); | ||
const pushMessageAction = pushMessage(storeConfig.linkedStores.message); | ||
|
||
return () => (dispatch) => { | ||
dispatch(fetchRequestedAction()); | ||
|
||
return window.fetch(storeConfig.remote.endpoint) | ||
.then(checkStatus) | ||
.then((response) => response.json()) | ||
.then((data) => { | ||
dispatch(pushMessageAction({ | ||
title: 'ok', | ||
body: 'heyad', | ||
type: 'success', | ||
})); | ||
dispatch(pushMessageAction({ | ||
title: 'info', | ||
body: 'skfjsklj', | ||
type: 'info', | ||
})); | ||
dispatch(addBulkRecordsAction(data.data)); | ||
}) | ||
.catch((error) => { | ||
dispatch(pushMessageAction({ | ||
title: 'An error occured', | ||
body: `${error}`, | ||
type: 'error', | ||
})); | ||
}); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const FETCH_REQUEST = 'CollectionQueryWidget.FETCH_REQUEST'; | ||
export const FETCH_SUCCESS = 'CollectionQueryWidget.FETCH_SUCCESS'; | ||
export const FETCH_FAIL = 'CollectionQueryWidget.FAIL'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
export Component from './CollectionQueryWidget'; | ||
|
||
export * as actions from './actions'; | ||
export * as constants from './constants'; | ||
export reducer from './reducer'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
import { FETCH_REQUEST, FETCH_SUCCESS, FETCH_FAIL } from './constants'; | ||
import { Map as iMap/* , List as iList, Record as iRecord*/ } from 'immutable'; | ||
|
||
export default (/* config */) => { | ||
const initialState = iMap({ | ||
// query: iList(), | ||
loading: false, | ||
error: null, | ||
}); | ||
|
||
const actions = { | ||
[FETCH_REQUEST]: (state) => (state.set('loading', true)), | ||
[FETCH_SUCCESS]: (state) => (state.set('loading', false)), | ||
[FETCH_FAIL]: (state, { payload }) => ( | ||
state.set('loading', false).update('error', () => payload) | ||
), | ||
}; | ||
|
||
return { initialState, actions }; | ||
}; |
Oops, something went wrong.