Files
mattermost-mobile/app/actions/views/crt.ts
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

32 lines
1.5 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {PreferenceTypes} from '@mm-redux/action_types';
import {General, Preferences} from '@mm-redux/constants';
import {getConfig} from '@mm-redux/selectors/entities/general';
import {getCollapsedThreadsPreference} from '@mm-redux/selectors/entities/preferences';
import EventEmitter from '@mm-redux/utils/event_emitter';
import type {ActionResult, DispatchFunc, GetStateFunc} from '@mm-redux/types/actions';
import type {PreferenceType} from '@mm-redux/types/preferences';
export function handleCRTPreferenceChange(preferences: PreferenceType[]) {
return async (dispatch: DispatchFunc, getState: GetStateFunc): Promise<ActionResult> => {
const state = getState();
const newCRTPreference = preferences.find((preference) => preference.name === Preferences.COLLAPSED_REPLY_THREADS);
if (newCRTPreference && getConfig(state).CollapsedThreads !== undefined) {
const newCRTValue = newCRTPreference.value;
const oldCRTValue = getCollapsedThreadsPreference(state);
if (newCRTValue !== oldCRTValue) {
dispatch({
type: PreferenceTypes.RECEIVED_PREFERENCES,
data: preferences,
});
EventEmitter.emit(General.CRT_PREFERENCE_CHANGED, newCRTValue);
return {data: true};
}
}
return {data: false};
};
}