Skip to content

Commit

Permalink
Wip: keep statuses if edit circle
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode committed Sep 23, 2023
1 parent 5351751 commit 9212f82
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions app/javascript/mastodon/reducers/circles.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,22 @@ import {

const initialState = ImmutableList();

const normalizeList = (state, circle) => state.set(circle.id, fromJS(circle));
const normalizeCircle = (state, circle) => {
const old = state.get(circle.id);
if (old === false) {
return state;
}

let s = state.set(circle.id, fromJS(circle));
if (old) {
s = s.setIn([circle.id, 'statuses'], old.get('statuses'));
}
return s;
};

const normalizeLists = (state, circles) => {
const normalizeCircles = (state, circles) => {
circles.forEach(circle => {
state = normalizeList(state, circle);
state = normalizeCircle(state, circle);
});

return state;
Expand Down Expand Up @@ -57,9 +68,9 @@ export default function circles(state = initialState, action) {
case CIRCLE_FETCH_SUCCESS:
case CIRCLE_CREATE_SUCCESS:
case CIRCLE_UPDATE_SUCCESS:
return normalizeList(state, action.circle);
return normalizeCircle(state, action.circle);
case CIRCLES_FETCH_SUCCESS:
return normalizeLists(state, action.circles);
return normalizeCircles(state, action.circles);
case CIRCLE_DELETE_SUCCESS:
case CIRCLE_FETCH_FAIL:
return state.set(action.id, false);
Expand Down

0 comments on commit 9212f82

Please sign in to comment.