mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 17:33:14 +01:00
Work on UserStuff
This commit is contained in:
parent
f575f2b4ca
commit
0527e0184e
22
js/actions/user_actions.js
Normal file
22
js/actions/user_actions.js
Normal file
@ -0,0 +1,22 @@
|
||||
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,5 +1,6 @@
|
||||
import React from 'react';
|
||||
import Router from 'react-router';
|
||||
import Header from '../components/header';
|
||||
|
||||
|
||||
let Link = Router.Link;
|
||||
@ -10,7 +11,7 @@ let AscribeApp = React.createClass({
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<header>ascribe</header>
|
||||
<Header />
|
||||
<navigation>
|
||||
<Link to="pieces">pieces</Link>
|
||||
</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;
|
21
js/fetchers/user_fetcher.js
Normal file
21
js/fetchers/user_fetcher.js
Normal file
@ -0,0 +1,21 @@
|
||||
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;
|
15
js/stores/user_store.js
Normal file
15
js/stores/user_store.js
Normal file
@ -0,0 +1,15 @@
|
||||
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);
|
Loading…
Reference in New Issue
Block a user