* Port WebSocket from mm-redux and batch actions * Update mm-redux and fix tests * Change action name * Naming batch actions * Fix unit tests * Dispatch connection change only if its different * Remove comment * Add Lint to TypeScript and fix linting errors * Add WebSocket Unit Tests * Revert from unwanted RN 0.62
60 lines
1.5 KiB
JavaScript
60 lines
1.5 KiB
JavaScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {networkStatusChangedAction} from 'redux-offline';
|
|
import {batchActions} from 'redux-batched-actions';
|
|
|
|
import {DeviceTypes} from 'app/constants';
|
|
|
|
export function connection(isOnline) {
|
|
return async (dispatch, getState) => {
|
|
const state = getState();
|
|
if (isOnline !== undefined && isOnline !== state.device.connection) { //eslint-disable-line no-undefined
|
|
dispatch(batchActions([
|
|
networkStatusChangedAction(isOnline), {
|
|
type: DeviceTypes.CONNECTION_CHANGED,
|
|
data: isOnline,
|
|
},
|
|
], 'BATCH_CONNECTION_CHANGED'));
|
|
}
|
|
};
|
|
}
|
|
|
|
export function setStatusBarHeight(height = 20) {
|
|
return {
|
|
type: DeviceTypes.STATUSBAR_HEIGHT_CHANGED,
|
|
data: height,
|
|
};
|
|
}
|
|
|
|
export function setDeviceDimensions(height, width) {
|
|
return {
|
|
type: DeviceTypes.DEVICE_DIMENSIONS_CHANGED,
|
|
data: {
|
|
deviceHeight: height,
|
|
deviceWidth: width,
|
|
},
|
|
};
|
|
}
|
|
|
|
export function setDeviceOrientation(orientation) {
|
|
return {
|
|
type: DeviceTypes.DEVICE_ORIENTATION_CHANGED,
|
|
data: orientation,
|
|
};
|
|
}
|
|
|
|
export function setDeviceAsTablet() {
|
|
return {
|
|
type: DeviceTypes.DEVICE_TYPE_CHANGED,
|
|
data: true,
|
|
};
|
|
}
|
|
|
|
export default {
|
|
connection,
|
|
setDeviceDimensions,
|
|
setDeviceOrientation,
|
|
setDeviceAsTablet,
|
|
setStatusBarHeight,
|
|
};
|