Skip to content

Commit d52fe78

Browse files
chrisbobbegnprice
authored andcommitted
accounts [nfc]: Inline remaining reducer handler-helpers
See the previous commit, where we did just one of these.
1 parent 51ed73c commit d52fe78

File tree

1 file changed

+48
-57
lines changed

1 file changed

+48
-57
lines changed

src/account/accountsReducer.js

Lines changed: 48 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -27,57 +27,6 @@ const findAccount = (state: AccountsState, identity: Identity): number => {
2727
);
2828
};
2929

30-
const loginSuccess = (state, action) => {
31-
const { realm, email, apiKey } = action;
32-
const accountIndex = findAccount(state, { realm, email });
33-
if (accountIndex === -1) {
34-
return [
35-
{
36-
realm,
37-
email,
38-
apiKey,
39-
userId: null,
40-
ackedPushToken: null,
41-
zulipVersion: null,
42-
zulipFeatureLevel: null,
43-
lastDismissedServerPushSetupNotice: null,
44-
},
45-
...state,
46-
];
47-
}
48-
return [
49-
{ ...state[accountIndex], apiKey, ackedPushToken: null },
50-
...state.slice(0, accountIndex),
51-
...state.slice(accountIndex + 1),
52-
];
53-
};
54-
55-
const ackPushToken = (state, action) => {
56-
const { pushToken: ackedPushToken, identity } = action;
57-
const accountIndex = findAccount(state, identity);
58-
if (accountIndex === -1) {
59-
return state;
60-
}
61-
return [
62-
...state.slice(0, accountIndex),
63-
{ ...state[accountIndex], ackedPushToken },
64-
...state.slice(accountIndex + 1),
65-
];
66-
};
67-
68-
const unackPushToken = (state, action) => {
69-
const { identity } = action;
70-
const accountIndex = findAccount(state, identity);
71-
if (accountIndex === -1) {
72-
return state;
73-
}
74-
return [
75-
...state.slice(0, accountIndex),
76-
{ ...state[accountIndex], ackedPushToken: null },
77-
...state.slice(accountIndex + 1),
78-
];
79-
};
80-
8130
// eslint-disable-next-line default-param-last
8231
export default (state: AccountsState = initialState, action: Action): AccountsState => {
8332
switch (action.type) {
@@ -107,14 +56,56 @@ export default (state: AccountsState = initialState, action: Action): AccountsSt
10756
: [account, ...state.filter(a => a !== account)]; // put account first
10857
}
10958

110-
case LOGIN_SUCCESS:
111-
return loginSuccess(state, action);
59+
case LOGIN_SUCCESS: {
60+
const { realm, email, apiKey } = action;
61+
const accountIndex = findAccount(state, { realm, email });
62+
if (accountIndex === -1) {
63+
return [
64+
{
65+
realm,
66+
email,
67+
apiKey,
68+
userId: null,
69+
ackedPushToken: null,
70+
zulipVersion: null,
71+
zulipFeatureLevel: null,
72+
lastDismissedServerPushSetupNotice: null,
73+
},
74+
...state,
75+
];
76+
}
77+
return [
78+
{ ...state[accountIndex], apiKey, ackedPushToken: null },
79+
...state.slice(0, accountIndex),
80+
...state.slice(accountIndex + 1),
81+
];
82+
}
11283

113-
case ACK_PUSH_TOKEN:
114-
return ackPushToken(state, action);
84+
case ACK_PUSH_TOKEN: {
85+
const { pushToken: ackedPushToken, identity } = action;
86+
const accountIndex = findAccount(state, identity);
87+
if (accountIndex === -1) {
88+
return state;
89+
}
90+
return [
91+
...state.slice(0, accountIndex),
92+
{ ...state[accountIndex], ackedPushToken },
93+
...state.slice(accountIndex + 1),
94+
];
95+
}
11596

116-
case UNACK_PUSH_TOKEN:
117-
return unackPushToken(state, action);
97+
case UNACK_PUSH_TOKEN: {
98+
const { identity } = action;
99+
const accountIndex = findAccount(state, identity);
100+
if (accountIndex === -1) {
101+
return state;
102+
}
103+
return [
104+
...state.slice(0, accountIndex),
105+
{ ...state[accountIndex], ackedPushToken: null },
106+
...state.slice(accountIndex + 1),
107+
];
108+
}
118109

119110
case LOGOUT: {
120111
return [{ ...state[0], apiKey: '', ackedPushToken: null }, ...state.slice(1)];

0 commit comments

Comments
 (0)