mattermost-mobile/app/mm-redux/reducers/errors/index.ts
Elias Nahum 012eb08fde
Fix infinite skeleton in different use cases and do not scroll to messages already seen (#4304)
* Fix infinite skeleton in different use cases

* Apply suggestions from code review

Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>

* Update app/utils/teams.js

Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>
2020-05-19 18:54:34 -04:00

32 lines
984 B
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {ErrorTypes} from '@mm-redux/action_types';
import {GenericAction} from '@mm-redux/types/actions';
export default ((state: Array<{error: any;displayable?: boolean;date: string}> = [], action: GenericAction) => {
switch (action.type) {
case ErrorTypes.DISMISS_ERROR: {
const nextState = [...state];
nextState.splice(action.index!, 1);
return nextState;
}
case ErrorTypes.LOG_ERROR: {
const nextState = state.length ? [...state] : [];
const {displayable, error} = action;
nextState.push({
displayable,
error,
date: new Date(Date.now()).toUTCString(),
});
return nextState;
}
case ErrorTypes.RESTORE_ERRORS:
return action.data;
case ErrorTypes.CLEAR_ERRORS: {
return [];
}
default:
return state;
}
});