mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 17:33:14 +01:00
Merge branch 'master' of bitbucket.org:ascribe/onion
This commit is contained in:
commit
52c980bfea
@ -1,6 +1,7 @@
|
|||||||
import alt from '../alt';
|
import alt from '../alt';
|
||||||
import PieceListFetcher from '../fetchers/piece_list_fetcher';
|
import PieceListFetcher from '../fetchers/piece_list_fetcher';
|
||||||
|
|
||||||
|
|
||||||
class PieceListActions {
|
class PieceListActions {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.generateActions(
|
this.generateActions(
|
||||||
|
23
js/actions/user_actions.js
Normal file
23
js/actions/user_actions.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import alt from '../alt';
|
||||||
|
import UserFetcher from '../fetchers/user_fetcher';
|
||||||
|
|
||||||
|
|
||||||
|
class UserActions {
|
||||||
|
constructor() {
|
||||||
|
this.generateActions(
|
||||||
|
'updateCurrentUser'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchCurrentUser() {
|
||||||
|
UserFetcher.fetchOne()
|
||||||
|
.then((res) => {
|
||||||
|
this.actions.updateCurrentUser(res['users'][0]);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default alt.createActions(UserActions);
|
@ -1,6 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Router from 'react-router';
|
import Router from 'react-router';
|
||||||
|
import Header from '../components/header';
|
||||||
|
|
||||||
let Link = Router.Link;
|
let Link = Router.Link;
|
||||||
let RouteHandler = Router.RouteHandler;
|
let RouteHandler = Router.RouteHandler;
|
||||||
@ -10,7 +10,7 @@ let AscribeApp = React.createClass({
|
|||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<header>ascribe</header>
|
<Header />
|
||||||
<navigation>
|
<navigation>
|
||||||
<Link to="pieces">pieces</Link>
|
<Link to="pieces">pieces</Link>
|
||||||
</navigation>
|
</navigation>
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import AltContainer from 'alt/AltContainer';
|
||||||
|
import UserActions from '../actions/user_actions';
|
||||||
|
import UserStore from '../stores/user_store';
|
||||||
|
|
||||||
|
|
||||||
|
let Header = React.createClass({
|
||||||
|
|
||||||
|
getInitialState() {
|
||||||
|
return UserStore.getState();
|
||||||
|
},
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
UserStore.listen(this.onChange)
|
||||||
|
UserActions.fetchCurrentUser();
|
||||||
|
},
|
||||||
|
|
||||||
|
onChange(state) {
|
||||||
|
this.setState(state);
|
||||||
|
},
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div>hello {this.state.currentUser.username}</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export default Header;
|
@ -1,5 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
|
|
||||||
let Piece = React.createClass({
|
let Piece = React.createClass({
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
@ -8,4 +9,4 @@ let Piece = React.createClass({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export default Piece;
|
export default Piece;
|
||||||
|
@ -11,6 +11,7 @@ import TableItemText from './table_item_text';
|
|||||||
|
|
||||||
let Link = Router.Link;
|
let Link = Router.Link;
|
||||||
|
|
||||||
|
|
||||||
let PieceList = React.createClass({
|
let PieceList = React.createClass({
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
@ -3,6 +3,7 @@ import React from 'react';
|
|||||||
import TableItem from './table_item';
|
import TableItem from './table_item';
|
||||||
import TableHeader from './table_header';
|
import TableHeader from './table_header';
|
||||||
|
|
||||||
|
|
||||||
let Table = React.createClass({
|
let Table = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
columnMap: React.PropTypes.object.isRequired
|
columnMap: React.PropTypes.object.isRequired
|
||||||
|
@ -3,6 +3,7 @@ import React from 'react';
|
|||||||
import TableColumnMixin from '../mixins/table_column_mixin';
|
import TableColumnMixin from '../mixins/table_column_mixin';
|
||||||
import GeneralUtils from '../utils/general_utils';
|
import GeneralUtils from '../utils/general_utils';
|
||||||
|
|
||||||
|
|
||||||
let TableHeader = React.createClass({
|
let TableHeader = React.createClass({
|
||||||
mixins: [TableColumnMixin],
|
mixins: [TableColumnMixin],
|
||||||
propTypes: {
|
propTypes: {
|
||||||
@ -35,4 +36,4 @@ let TableHeader = React.createClass({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export default TableHeader;
|
export default TableHeader;
|
||||||
|
@ -4,6 +4,7 @@ import TableColumnMixin from '../mixins/table_column_mixin';
|
|||||||
import TableItemImg from './table_item_img';
|
import TableItemImg from './table_item_img';
|
||||||
import TableItemText from './table_item_text';
|
import TableItemText from './table_item_text';
|
||||||
|
|
||||||
|
|
||||||
let TableItem = React.createClass({
|
let TableItem = React.createClass({
|
||||||
mixins: [TableColumnMixin],
|
mixins: [TableColumnMixin],
|
||||||
|
|
||||||
@ -54,4 +55,4 @@ let TableItem = React.createClass({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export default TableItem;
|
export default TableItem;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
|
|
||||||
let TableItemText = React.createClass({
|
let TableItemText = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
content: React.PropTypes.string.isRequired
|
content: React.PropTypes.string.isRequired
|
||||||
@ -14,4 +15,4 @@ let TableItemText = React.createClass({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export default TableItemText;
|
export default TableItemText;
|
||||||
|
@ -3,6 +3,7 @@ import fetch from 'isomorphic-fetch';
|
|||||||
import AppConstants from '../constants/application_constants';
|
import AppConstants from '../constants/application_constants';
|
||||||
import FetchApiUtils from '../utils/fetch_api_utils';
|
import FetchApiUtils from '../utils/fetch_api_utils';
|
||||||
|
|
||||||
|
|
||||||
let PieceListFetcher = {
|
let PieceListFetcher = {
|
||||||
/**
|
/**
|
||||||
* Fetches a list of pieces from the API.
|
* Fetches a list of pieces from the API.
|
||||||
@ -27,4 +28,4 @@ let PieceListFetcher = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default PieceListFetcher;
|
export default PieceListFetcher;
|
||||||
|
22
js/fetchers/user_fetcher.js
Normal file
22
js/fetchers/user_fetcher.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import fetch from 'isomorphic-fetch';
|
||||||
|
|
||||||
|
import AppConstants from '../constants/application_constants';
|
||||||
|
import FetchApiUtils from '../utils/fetch_api_utils';
|
||||||
|
|
||||||
|
|
||||||
|
let UserFetcher = {
|
||||||
|
/**
|
||||||
|
* Fetch one user from the API.
|
||||||
|
* If no arg is supplied, load the current user
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
fetchOne() {
|
||||||
|
return fetch(AppConstants.baseUrl + 'users/', {
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Basic ' + AppConstants.debugCredentialBase64
|
||||||
|
}
|
||||||
|
}).then((res) => res.json());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default UserFetcher;
|
@ -1,5 +1,6 @@
|
|||||||
import GeneralUtils from '../utils/general_utils';
|
import GeneralUtils from '../utils/general_utils';
|
||||||
|
|
||||||
|
|
||||||
let TableColumnMixin = {
|
let TableColumnMixin = {
|
||||||
/**
|
/**
|
||||||
* Generates the bootstrap grid column declarations automatically using
|
* Generates the bootstrap grid column declarations automatically using
|
||||||
@ -20,4 +21,4 @@ let TableColumnMixin = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default TableColumnMixin;
|
export default TableColumnMixin;
|
||||||
|
@ -7,6 +7,7 @@ import Piece from './components/piece';
|
|||||||
|
|
||||||
let Route = Router.Route;
|
let Route = Router.Route;
|
||||||
|
|
||||||
|
|
||||||
let routes = (
|
let routes = (
|
||||||
<Route name="app" path="/" handler={AscribeApp}>
|
<Route name="app" path="/" handler={AscribeApp}>
|
||||||
<Route name="pieces" handler={PieceList}>
|
<Route name="pieces" handler={PieceList}>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import alt from '../alt';
|
import alt from '../alt';
|
||||||
import PieceListActions from '../actions/piece_list_actions';
|
import PieceListActions from '../actions/piece_list_actions';
|
||||||
|
|
||||||
|
|
||||||
class PieceListStore {
|
class PieceListStore {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.itemList = []; // rename this to pieceList after figuring out AltContainer transform
|
this.itemList = []; // rename this to pieceList after figuring out AltContainer transform
|
||||||
|
16
js/stores/user_store.js
Normal file
16
js/stores/user_store.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import alt from '../alt';
|
||||||
|
import UserAction from '../actions/user_actions';
|
||||||
|
|
||||||
|
|
||||||
|
class UserStore{
|
||||||
|
constructor() {
|
||||||
|
this.currentUser = {}
|
||||||
|
this.bindActions(UserAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
onUpdateCurrentUser(user) {
|
||||||
|
this.currentUser = user;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default alt.createStore(UserStore);
|
@ -1,5 +1,6 @@
|
|||||||
import GeneralUtils from './general_utils';
|
import GeneralUtils from './general_utils';
|
||||||
|
|
||||||
|
|
||||||
// TODO: Create Unittests that test all functions
|
// TODO: Create Unittests that test all functions
|
||||||
let FetchApiUtils = {
|
let FetchApiUtils = {
|
||||||
|
|
||||||
@ -42,4 +43,4 @@ let FetchApiUtils = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default FetchApiUtils;
|
export default FetchApiUtils;
|
||||||
|
Loading…
Reference in New Issue
Block a user