bigbuffet-rw/app/soapbox/reducers/security.js

27 lines
678 B
JavaScript
Raw Normal View History

import {
FETCH_TOKENS_SUCCESS,
REVOKE_TOKEN_SUCCESS,
2021-08-21 17:37:28 -07:00
} from '../actions/security';
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
const initialState = ImmutableMap({
tokens: ImmutableList(),
});
2021-08-03 12:29:36 -07:00
const deleteToken = (state, tokenId) => {
return state.update('tokens', tokens => {
return tokens.filterNot(token => token.get('id') === tokenId);
});
};
export default function security(state = initialState, action) {
switch(action.type) {
case FETCH_TOKENS_SUCCESS:
return state.set('tokens', fromJS(action.tokens));
case REVOKE_TOKEN_SUCCESS:
2021-08-03 12:29:36 -07:00
return deleteToken(state, action.id);
default:
return state;
}
2021-08-03 12:22:51 -07:00
}