mirror of https://github.com/mastodon/mastodon
Improve initialState loading
parent
2e71bb031b
commit
23ebf60b95
@ -1,8 +0,0 @@
|
||||
export const ACCESS_TOKEN_SET = 'ACCESS_TOKEN_SET';
|
||||
|
||||
export function setAccessToken(token) {
|
||||
return {
|
||||
type: ACCESS_TOKEN_SET,
|
||||
token: token
|
||||
};
|
||||
};
|
@ -0,0 +1,17 @@
|
||||
import Immutable from 'immutable';
|
||||
|
||||
export const STORE_HYDRATE = 'STORE_HYDRATE';
|
||||
|
||||
const convertState = rawState =>
|
||||
Immutable.fromJS(rawState, (k, v) =>
|
||||
Immutable.Iterable.isIndexed(v) ? v.toList() : v.toMap().mapKeys(x =>
|
||||
Number.isNaN(x * 1) ? x : x * 1));
|
||||
|
||||
export function hydrateStore(rawState) {
|
||||
const state = convertState(rawState);
|
||||
|
||||
return {
|
||||
type: STORE_HYDRATE,
|
||||
state
|
||||
};
|
||||
};
|
@ -1,8 +1,10 @@
|
||||
import { connect } from 'react-redux';
|
||||
import NavigationBar from '../components/navigation_bar';
|
||||
|
||||
const mapStateToProps = (state, props) => ({
|
||||
const mapStateToProps = (state, props) => {
|
||||
return {
|
||||
account: state.getIn(['accounts', state.getIn(['meta', 'me'])])
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps)(NavigationBar);
|
||||
|
@ -1,4 +1,22 @@
|
||||
- content_for :header_tags do
|
||||
:javascript
|
||||
window.INITIAL_STATE = {
|
||||
"meta": {
|
||||
"access_token": "#{@token}",
|
||||
"locale": "#{I18n.locale}",
|
||||
"me": #{current_account.id}
|
||||
},
|
||||
|
||||
"compose": {
|
||||
"me": #{current_account.id},
|
||||
"private": #{current_account.locked?}
|
||||
},
|
||||
|
||||
"accounts": {
|
||||
#{current_account.id}: #{render(file: 'api/v1/accounts/show', locals: { account: current_user.account }, formats: :json)}
|
||||
}
|
||||
};
|
||||
|
||||
= javascript_include_tag 'application'
|
||||
|
||||
= react_component 'Mastodon', default_props, class: 'app-holder', prerender: false
|
||||
|
Loading…
Reference in New Issue