mattermost-mobile/app/reducers/views/recent_emojis.js
Daniel Espino García 4c8594d330
Add linter rules for import order and type member delimiters (#5514)
* Add linter rules for import order and type member delimiters

* Remove unneeded group

* Group all app/* imports before the internal imports

* Move app/ imports before parent imports

* Separate @node_modules imports into a different group

* Substitute app paths by aliases

* Fix @node_modules import order and add test related modules

* Add aliases for types and test, and group import types
2021-07-23 11:06:04 +02:00

37 lines
1.1 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {ViewTypes} from '@constants';
const MAXIMUM_RECENT_EMOJI = 27;
export default function recentEmojis(state = [], action) {
switch (action.type) {
case ViewTypes.ADD_RECENT_EMOJI: {
const nextState = [...state];
const index = nextState.indexOf(action.emoji);
if (index !== -1) {
nextState.splice(index, 1);
}
nextState.unshift(action.emoji);
if (nextState.length > MAXIMUM_RECENT_EMOJI) {
nextState.splice(MAXIMUM_RECENT_EMOJI);
}
return nextState;
}
case ViewTypes.ADD_RECENT_EMOJI_ARRAY: {
const nextRecentEmojis = action.emojis.reduce((currentState, emoji) => {
return [emoji, ...currentState.filter((currentEmoji) => currentEmoji !== emoji)];
}, state);
if (nextRecentEmojis.length > MAXIMUM_RECENT_EMOJI) {
nextRecentEmojis.splice(MAXIMUM_RECENT_EMOJI);
}
return nextRecentEmojis;
}
default:
return state;
}
}