Improve how account detailed view looks, load account's statuses
This commit is contained in:
parent
dafcb02153
commit
0967961de7
9 changed files with 208 additions and 76 deletions
|
@ -1,20 +1,50 @@
|
|||
import { TIMELINE_SET, TIMELINE_UPDATE, TIMELINE_DELETE } from '../actions/timelines';
|
||||
import { REBLOG_SUCCESS, FAVOURITE_SUCCESS } from '../actions/interactions';
|
||||
import { ACCOUNT_SET_SELF, ACCOUNT_FETCH_SUCCESS, ACCOUNT_FOLLOW_SUCCESS, ACCOUNT_UNFOLLOW_SUCCESS } from '../actions/accounts';
|
||||
import { STATUS_FETCH_SUCCESS } from '../actions/statuses';
|
||||
import { FOLLOW_SUBMIT_SUCCESS } from '../actions/follow';
|
||||
import Immutable from 'immutable';
|
||||
import {
|
||||
TIMELINE_SET,
|
||||
TIMELINE_UPDATE,
|
||||
TIMELINE_DELETE
|
||||
} from '../actions/timelines';
|
||||
import {
|
||||
REBLOG_SUCCESS,
|
||||
FAVOURITE_SUCCESS
|
||||
} from '../actions/interactions';
|
||||
import {
|
||||
ACCOUNT_SET_SELF,
|
||||
ACCOUNT_FETCH_SUCCESS,
|
||||
ACCOUNT_FOLLOW_SUCCESS,
|
||||
ACCOUNT_UNFOLLOW_SUCCESS,
|
||||
ACCOUNT_TIMELINE_FETCH_SUCCESS
|
||||
} from '../actions/accounts';
|
||||
import { STATUS_FETCH_SUCCESS } from '../actions/statuses';
|
||||
import { FOLLOW_SUBMIT_SUCCESS } from '../actions/follow';
|
||||
import Immutable from 'immutable';
|
||||
|
||||
const initialState = Immutable.Map({
|
||||
home: Immutable.List([]),
|
||||
mentions: Immutable.List([]),
|
||||
statuses: Immutable.Map(),
|
||||
accounts: Immutable.Map(),
|
||||
accounts_timelines: Immutable.Map(),
|
||||
me: null,
|
||||
ancestors: Immutable.Map(),
|
||||
descendants: Immutable.Map()
|
||||
});
|
||||
|
||||
export function selectStatus(state, id) {
|
||||
let status = state.getIn(['timelines', 'statuses', id], null);
|
||||
|
||||
if (status === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
status = status.set('account', state.getIn(['timelines', 'accounts', status.get('account')]));
|
||||
|
||||
if (status.get('reblog') !== null) {
|
||||
status = status.set('reblog', selectStatus(state, status.get('reblog')));
|
||||
}
|
||||
|
||||
return status;
|
||||
};
|
||||
|
||||
function statusToMaps(state, status) {
|
||||
// Separate account
|
||||
let account = status.get('account');
|
||||
|
@ -59,6 +89,15 @@ function timelineToMaps(state, timeline, statuses) {
|
|||
return state;
|
||||
};
|
||||
|
||||
function accountTimelineToMaps(state, accountId, statuses) {
|
||||
statuses.forEach((status, i) => {
|
||||
state = statusToMaps(state, status);
|
||||
state = state.updateIn(['accounts_timelines', accountId], Immutable.List(), list => list.set(i, status.get('id')));
|
||||
});
|
||||
|
||||
return state;
|
||||
};
|
||||
|
||||
function updateTimelineWithMaps(state, timeline, status) {
|
||||
state = statusToMaps(state, status);
|
||||
state = state.update(timeline, list => list.unshift(status.get('id')));
|
||||
|
@ -120,6 +159,8 @@ export default function timelines(state = initialState, action) {
|
|||
return accountToMaps(state, Immutable.fromJS(action.account));
|
||||
case STATUS_FETCH_SUCCESS:
|
||||
return contextToMaps(state, Immutable.fromJS(action.status), Immutable.fromJS(action.context.ancestors), Immutable.fromJS(action.context.descendants));
|
||||
case ACCOUNT_TIMELINE_FETCH_SUCCESS:
|
||||
return accountTimelineToMaps(state, action.id, Immutable.fromJS(action.statuses));
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue