forked from Ivasoft/mattermost-mobile
MM_35115: Fixing TS issues [IN PROGRESS]
This commit is contained in:
20
app/requests/helpers.ts
Normal file
20
app/requests/helpers.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
//fixme: do we really need this ?
|
||||
export class FormattedError extends Error {
|
||||
private intl: {
|
||||
values: any;
|
||||
defaultMessage: string;
|
||||
id: string
|
||||
};
|
||||
|
||||
constructor(id: string, defaultMessage: string, values: any = {}) {
|
||||
super(defaultMessage);
|
||||
this.intl = {
|
||||
id,
|
||||
defaultMessage,
|
||||
values,
|
||||
};
|
||||
}
|
||||
}
|
||||
121
app/requests/local/navigation.ts
Normal file
121
app/requests/local/navigation.ts
Normal file
@@ -0,0 +1,121 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import merge from 'deepmerge';
|
||||
import {Platform} from 'react-native';
|
||||
import {Navigation} from 'react-native-navigation';
|
||||
import {Store} from 'react-native-navigation/lib/dist/components/Store';
|
||||
|
||||
//fixme: to needful here for the whole file
|
||||
|
||||
function getThemeFromState() {
|
||||
const state = Store.redux?.getState() || {};
|
||||
|
||||
return getTheme(state);
|
||||
}
|
||||
|
||||
export function goToScreen(name, title, passProps = {}, options = {}) {
|
||||
const theme = getThemeFromState();
|
||||
const componentId = EphemeralStore.getNavigationTopComponentId();
|
||||
const defaultOptions = {
|
||||
layout: {
|
||||
componentBackgroundColor: theme.centerChannelBg,
|
||||
},
|
||||
popGesture: true,
|
||||
sideMenu: {
|
||||
left: {enabled: false},
|
||||
right: {enabled: false},
|
||||
},
|
||||
topBar: {
|
||||
animate: true,
|
||||
visible: true,
|
||||
backButton: {
|
||||
color: theme.sidebarHeaderTextColor,
|
||||
enableMenu: false,
|
||||
title: '',
|
||||
testID: 'screen.back.button',
|
||||
},
|
||||
background: {
|
||||
color: theme.sidebarHeaderBg,
|
||||
},
|
||||
title: {
|
||||
color: theme.sidebarHeaderTextColor,
|
||||
text: title,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Navigation.push(componentId, {
|
||||
component: {
|
||||
id: name,
|
||||
name,
|
||||
passProps,
|
||||
options: merge(defaultOptions, options),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function resetToChannel(passProps = {}) {
|
||||
const theme = getThemeFromState();
|
||||
|
||||
EphemeralStore.clearNavigationComponents();
|
||||
|
||||
const stack = {
|
||||
children: [{
|
||||
component: {
|
||||
id: NavigationTypes.CHANNEL_SCREEN,
|
||||
name: NavigationTypes.CHANNEL_SCREEN,
|
||||
passProps,
|
||||
options: {
|
||||
layout: {
|
||||
componentBackgroundColor: theme.centerChannelBg,
|
||||
},
|
||||
statusBar: {
|
||||
visible: true,
|
||||
},
|
||||
topBar: {
|
||||
visible: false,
|
||||
height: 0,
|
||||
background: {
|
||||
color: theme.sidebarHeaderBg,
|
||||
},
|
||||
backButton: {
|
||||
visible: false,
|
||||
color: theme.sidebarHeaderTextColor,
|
||||
enableMenu: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}],
|
||||
};
|
||||
|
||||
let platformStack = {stack};
|
||||
if (Platform.OS === 'android') {
|
||||
platformStack = {
|
||||
sideMenu: {
|
||||
left: {
|
||||
component: {
|
||||
id: 'MainSidebar',
|
||||
name: 'MainSidebar',
|
||||
},
|
||||
},
|
||||
center: {
|
||||
stack,
|
||||
},
|
||||
right: {
|
||||
component: {
|
||||
id: 'SettingsSidebar',
|
||||
name: 'SettingsSidebar',
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Navigation.setRoot({
|
||||
root: {
|
||||
...platformStack,
|
||||
},
|
||||
});
|
||||
}
|
||||
26
app/requests/remote/general.ts
Normal file
26
app/requests/remote/general.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
export const getPing = async () => {
|
||||
let data;
|
||||
let pingError = new FormattedError(
|
||||
'mobile.server_ping_failed',
|
||||
'Cannot connect to the server. Please check your server URL and internet connection.',
|
||||
);
|
||||
try {
|
||||
data = await Client4.ping();
|
||||
if (data.status !== 'OK') {
|
||||
// successful ping but not the right return {data}
|
||||
return {error: pingError};
|
||||
}
|
||||
} catch (error) {
|
||||
// Client4Error
|
||||
if (error.status_code === 401) {
|
||||
// When the server requires a client certificate to connect.
|
||||
pingError = error;
|
||||
}
|
||||
return {error: pingError};
|
||||
}
|
||||
|
||||
return {data};
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
45
app/utils/helpers.ts
Normal file
45
app/utils/helpers.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
// isMinimumServerVersion will return true if currentVersion is equal to higher or than
|
||||
// the provided minimum version. A non-equal major version will ignore minor and dot
|
||||
// versions, and a non-equal minor version will ignore dot version.
|
||||
// currentVersion is a string, e.g '4.6.0'
|
||||
// minMajorVersion, minMinorVersion, minDotVersion are integers
|
||||
export const isMinimumServerVersion = (currentVersion: string, minMajorVersion = 0, minMinorVersion = 0, minDotVersion = 0): boolean => {
|
||||
if (!currentVersion || typeof currentVersion !== 'string') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const split = currentVersion.split('.');
|
||||
|
||||
const major = parseInt(split[0], 10);
|
||||
const minor = parseInt(split[1] || '0', 10);
|
||||
const dot = parseInt(split[2] || '0', 10);
|
||||
|
||||
if (major > minMajorVersion) {
|
||||
return true;
|
||||
}
|
||||
if (major < minMajorVersion) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Major version is equal, check minor
|
||||
if (minor > minMinorVersion) {
|
||||
return true;
|
||||
}
|
||||
if (minor < minMinorVersion) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Minor version is equal, check dot
|
||||
if (dot > minDotVersion) {
|
||||
return true;
|
||||
}
|
||||
if (dot < minDotVersion) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Dot version is equal
|
||||
return true;
|
||||
};
|
||||
@@ -35,6 +35,7 @@ module.exports = {
|
||||
'@telemetry': './app/telemetry',
|
||||
'@typings': './types',
|
||||
'@utils': './app/utils',
|
||||
'@requests': './app/requests',
|
||||
'@websocket': './app/client/websocket',
|
||||
},
|
||||
}],
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
"@typings/*": ["types/*"],
|
||||
"@telemetry/*": ["/app/telemetry/*"],
|
||||
"@utils/*": ["app/utils/*"],
|
||||
"@requests/*": ["app/requests/*"],
|
||||
"@websocket": ["app/client/websocket"],
|
||||
"*": ["./*", "node_modules/*"],
|
||||
"react-native-redash/lib/module/v1": [
|
||||
|
||||
4
types/utils/index.d.ts
vendored
4
types/utils/index.d.ts
vendored
@@ -1,6 +1,10 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {ImageStyle, TextStyle, ViewStyle} from 'react-native';
|
||||
|
||||
type Dictionary<T> = {
|
||||
[key: string]: T;
|
||||
};
|
||||
|
||||
type Styles = ViewStyle | TextStyle | ImageStyle
|
||||
|
||||
Reference in New Issue
Block a user