Compare commits

...

32 Commits

Author SHA1 Message Date
GleidsonDaniel 328733f3e8 chore: fix import 2022-01-11 14:03:37 -03:00
Gleidson Daniel Silva 7478d142be
Merge branch 'develop' into chore/migration-ts-redux-create-discussion 2022-01-11 13:42:17 -03:00
GleidsonDaniel 24053363e5 chore: migrate encryption to ts and add tests 2022-01-11 11:27:01 -03:00
GleidsonDaniel c25c34b725 chore: migrate createDiscussion to ts and add tests 2022-01-10 18:17:47 -03:00
GleidsonDaniel f1ac7ce77c chore: fix naming 2022-01-10 18:05:12 -03:00
GleidsonDaniel f19787f35a chore: migrate createChannel to ts and add tests 2022-01-10 17:47:54 -03:00
GleidsonDaniel 6bc0e82fdc chore: add more tests 2022-01-10 15:49:12 -03:00
GleidsonDaniel 1db676f424 chore: migrate connect to ts and add tests 2022-01-10 15:34:07 -03:00
GleidsonDaniel ba2931665b wip: migrate fixed consts to RootEnum 2022-01-07 17:40:48 -03:00
GleidsonDaniel 701361a686 chore: add tests and migrate RootEnum 2022-01-07 17:24:24 -03:00
GleidsonDaniel 16e04c7232 chore: init reducer/app migration to ts 2022-01-07 15:12:59 -03:00
GleidsonDaniel bc92a4f29d chore: update IBaseScreen definitions 2021-12-29 18:44:04 -03:00
GleidsonDaniel 0cf9765f86 chore: update definitions 2021-12-29 13:22:02 -03:00
GleidsonDaniel 48e4640bee chore: update interfaces and types names 2021-12-29 10:39:20 -03:00
GleidsonDaniel c471195d8c chore: fix IUser import 2021-12-23 10:20:38 -03:00
GleidsonDaniel 928fac17de chore: set eslint-plugin-jest version to 24.7.0 2021-12-23 10:14:43 -03:00
GleidsonDaniel bad5643a4d chore: move interfaces to reducer and import on screen 2021-12-22 16:40:29 -03:00
GleidsonDaniel f0977ddb22 chore: exprot initial state and then import on tests 2021-12-22 16:33:39 -03:00
GleidsonDaniel d12b28b5f5 chore: migrate redux tests to reducer folder and add eslint jest plugin 2021-12-22 16:27:19 -03:00
GleidsonDaniel ef0d2bf195 chore: remove unused const 2021-12-22 09:58:13 -03:00
GleidsonDaniel ff0925cc96 chore: move types to definition folder and fix imports 2021-12-22 09:38:11 -03:00
GleidsonDaniel b56f6048d4 chore: fix action type 2021-12-22 09:28:21 -03:00
GleidsonDaniel b5bda757bc test: add more selectedUsers tests 2021-12-22 09:27:40 -03:00
GleidsonDaniel b80c0635d6 test: create activeUser and selectedUser tests 2021-12-21 17:14:59 -03:00
GleidsonDaniel 69f27438b2 chore: remove applyAppStateMiddleware 2021-12-21 17:14:08 -03:00
GleidsonDaniel f169f6e0a7 chore: create mocketStore 2021-12-21 17:04:32 -03:00
GleidsonDaniel dc83f76843 chore: move state props to ISelectedUsersViewProps 2021-12-21 17:01:33 -03:00
GleidsonDaniel 010676aa85 chore: move IUser to base types 2021-12-21 12:04:39 -03:00
GleidsonDaniel 003f9fca68 chore: type selectedUsers action and reducer and improvement in the code of other files 2021-12-21 12:03:59 -03:00
GleidsonDaniel 9d7450b300 chore: remove mapDispatchToProps to use dispatch prop and clear some types 2021-12-21 10:17:11 -03:00
GleidsonDaniel 34e6ece871 chore: init types folder and set redux and BaseScreen interface 2021-12-21 10:11:40 -03:00
GleidsonDaniel 3b97c34959 chore: migrate activeUsers reducer and action to TS 2021-12-21 09:51:04 -03:00
35 changed files with 497 additions and 206 deletions

View File

@ -6,7 +6,7 @@ import { connect } from 'react-redux';
import { SetUsernameStackParamList, StackParamList } from './navigationTypes';
import Navigation from './lib/Navigation';
import { defaultHeader, getActiveRouteName, navigationTheme } from './utils/navigation';
import { ROOT_INSIDE, ROOT_LOADING, ROOT_OUTSIDE, ROOT_SET_USERNAME } from './actions/app';
import { RootEnum } from './definitions';
// Stacks
import AuthLoadingView from './views/AuthLoadingView';
// SetUsername Stack
@ -56,13 +56,13 @@ const App = React.memo(({ root, isMasterDetail }: { root: string; isMasterDetail
}}>
<Stack.Navigator screenOptions={{ headerShown: false, animationEnabled: false }}>
<>
{root === ROOT_LOADING ? <Stack.Screen name='AuthLoading' component={AuthLoadingView} /> : null}
{root === ROOT_OUTSIDE ? <Stack.Screen name='OutsideStack' component={OutsideStack} /> : null}
{root === ROOT_INSIDE && isMasterDetail ? (
{root === RootEnum.ROOT_LOADING ? <Stack.Screen name='AuthLoading' component={AuthLoadingView} /> : null}
{root === RootEnum.ROOT_OUTSIDE ? <Stack.Screen name='OutsideStack' component={OutsideStack} /> : null}
{root === RootEnum.ROOT_INSIDE && isMasterDetail ? (
<Stack.Screen name='MasterDetailStack' component={MasterDetailStack} />
) : null}
{root === ROOT_INSIDE && !isMasterDetail ? <Stack.Screen name='InsideStack' component={InsideStack} /> : null}
{root === ROOT_SET_USERNAME ? <Stack.Screen name='SetUsernameStack' component={SetUsernameStack} /> : null}
{root === RootEnum.ROOT_INSIDE && !isMasterDetail ? <Stack.Screen name='InsideStack' component={InsideStack} /> : null}
{root === RootEnum.ROOT_SET_USERNAME ? <Stack.Screen name='SetUsernameStack' component={SetUsernameStack} /> : null}
</>
</Stack.Navigator>
</NavigationContainer>

View File

@ -2,8 +2,8 @@ const REQUEST = 'REQUEST';
const SUCCESS = 'SUCCESS';
const FAILURE = 'FAILURE';
const defaultTypes = [REQUEST, SUCCESS, FAILURE];
function createRequestTypes(base = {}, types = defaultTypes): Record<any, any> {
const res: Record<any, any> = {};
function createRequestTypes(base = {}, types = defaultTypes): Record<string, string> {
const res: Record<string, string> = {};
types.forEach(type => (res[type] = `${base}_${type}`));
return res;
}

View File

@ -3,7 +3,7 @@ import { Action } from 'redux';
import { IActiveUsers } from '../reducers/activeUsers';
import { SET_ACTIVE_USERS } from './actionsTypes';
export interface ISetActiveUsers extends Action {
interface ISetActiveUsers extends Action {
activeUsers: IActiveUsers;
}

View File

@ -1,39 +0,0 @@
import { APP } from './actionsTypes';
export const ROOT_OUTSIDE = 'outside';
export const ROOT_INSIDE = 'inside';
export const ROOT_LOADING = 'loading';
export const ROOT_SET_USERNAME = 'setUsername';
export function appStart({ root, ...args }) {
return {
type: APP.START,
root,
...args
};
}
export function appReady() {
return {
type: APP.READY
};
}
export function appInit() {
return {
type: APP.INIT
};
}
export function appInitLocalSettings() {
return {
type: APP.INIT_LOCAL_SETTINGS
};
}
export function setMasterDetail(isMasterDetail) {
return {
type: APP.SET_MASTER_DETAIL,
isMasterDetail
};
}

48
app/actions/app.ts Normal file
View File

@ -0,0 +1,48 @@
import { Action } from 'redux';
import { RootEnum } from '../definitions';
import { APP } from './actionsTypes';
interface IAppStart extends Action {
root: RootEnum;
text?: string;
}
interface ISetMasterDetail extends Action {
isMasterDetail: boolean;
}
export type TActionApp = IAppStart & ISetMasterDetail;
export function appStart({ root, ...args }: { root: RootEnum }): IAppStart {
return {
type: APP.START,
root,
...args
};
}
export function appReady(): Action {
return {
type: APP.READY
};
}
export function appInit(): Action {
return {
type: APP.INIT
};
}
export function appInitLocalSettings(): Action {
return {
type: APP.INIT_LOCAL_SETTINGS
};
}
export function setMasterDetail(isMasterDetail: boolean): ISetMasterDetail {
return {
type: APP.SET_MASTER_DETAIL,
isMasterDetail
};
}

View File

@ -1,20 +0,0 @@
import * as types from './actionsTypes';
export function connectRequest() {
return {
type: types.METEOR.REQUEST
};
}
export function connectSuccess() {
return {
type: types.METEOR.SUCCESS
};
}
export function disconnect(err) {
return {
type: types.METEOR.DISCONNECT,
err
};
}

21
app/actions/connect.ts Normal file
View File

@ -0,0 +1,21 @@
import { Action } from 'redux';
import * as types from './actionsTypes';
export function connectRequest(): Action {
return {
type: types.METEOR.REQUEST
};
}
export function connectSuccess(): Action {
return {
type: types.METEOR.SUCCESS
};
}
export function disconnect(): Action {
return {
type: types.METEOR.DISCONNECT
};
}

View File

@ -1,23 +0,0 @@
import * as types from './actionsTypes';
export function createChannelRequest(data) {
return {
type: types.CREATE_CHANNEL.REQUEST,
data
};
}
export function createChannelSuccess(data) {
return {
type: types.CREATE_CHANNEL.SUCCESS,
data
};
}
export function createChannelFailure(err, isTeam) {
return {
type: types.CREATE_CHANNEL.FAILURE,
err,
isTeam
};
}

View File

@ -0,0 +1,42 @@
import { Action } from 'redux';
import { CREATE_CHANNEL } from './actionsTypes';
// TODO FIX DATA VALUE
interface ICreateChannelRequest extends Action {
data: any;
}
interface ICreateChannelSuccess extends Action {
data: any;
}
interface ICreateChannelFailure extends Action {
err: any;
isTeam: boolean;
}
export type TActionCreateChannel = ICreateChannelRequest & ICreateChannelSuccess & ICreateChannelFailure;
export function createChannelRequest(data: any): ICreateChannelRequest {
return {
type: CREATE_CHANNEL.REQUEST,
data
};
}
export function createChannelSuccess(data: any): ICreateChannelSuccess {
return {
type: CREATE_CHANNEL.SUCCESS,
data
};
}
export function createChannelFailure(err: any, isTeam: boolean): ICreateChannelFailure {
return {
type: CREATE_CHANNEL.FAILURE,
err,
isTeam
};
}

View File

@ -1,22 +0,0 @@
import * as types from './actionsTypes';
export function createDiscussionRequest(data) {
return {
type: types.CREATE_DISCUSSION.REQUEST,
data
};
}
export function createDiscussionSuccess(data) {
return {
type: types.CREATE_DISCUSSION.SUCCESS,
data
};
}
export function createDiscussionFailure(err) {
return {
type: types.CREATE_DISCUSSION.FAILURE,
err
};
}

View File

@ -0,0 +1,38 @@
import { Action } from 'redux';
import { CREATE_DISCUSSION } from './actionsTypes';
interface ICreateDiscussionRequest extends Action {
data: any;
}
interface ICreateDiscussionSuccess extends Action {
data: any;
}
interface ICreateDiscussionFailure extends Action {
err: any;
}
export type TActionCreateDiscussion = ICreateDiscussionRequest & ICreateDiscussionSuccess & ICreateDiscussionFailure;
export function createDiscussionRequest(data: any): ICreateDiscussionRequest {
return {
type: CREATE_DISCUSSION.REQUEST,
data
};
}
export function createDiscussionSuccess(data: any): ICreateDiscussionSuccess {
return {
type: CREATE_DISCUSSION.SUCCESS,
data
};
}
export function createDiscussionFailure(err: any): ICreateDiscussionFailure {
return {
type: CREATE_DISCUSSION.FAILURE,
err
};
}

View File

@ -1,35 +0,0 @@
import * as types from './actionsTypes';
export function encryptionInit() {
return {
type: types.ENCRYPTION.INIT
};
}
export function encryptionStop() {
return {
type: types.ENCRYPTION.STOP
};
}
export function encryptionSet(enabled = false, banner = null) {
return {
type: types.ENCRYPTION.SET,
enabled,
banner
};
}
export function encryptionSetBanner(banner) {
return {
type: types.ENCRYPTION.SET_BANNER,
banner
};
}
export function encryptionDecodeKey(password) {
return {
type: types.ENCRYPTION.DECODE_KEY,
password
};
}

51
app/actions/encryption.ts Normal file
View File

@ -0,0 +1,51 @@
import { Action } from 'redux';
import { ENCRYPTION } from './actionsTypes';
interface IEncryptionSetBanner extends Action {
banner: null | any;
}
interface IEncryptionSet extends Action, IEncryptionSetBanner {
enabled: boolean;
}
interface IEncryptionDecodeKey extends Action {
password: string;
}
export type TActionEncryption = IEncryptionSetBanner & IEncryptionSet & IEncryptionDecodeKey;
export function encryptionInit(): Action {
return {
type: ENCRYPTION.INIT
};
}
export function encryptionStop(): Action {
return {
type: ENCRYPTION.STOP
};
}
export function encryptionSet(enabled = false, banner: null | any): IEncryptionSet {
return {
type: ENCRYPTION.SET,
enabled,
banner
};
}
export function encryptionSetBanner(banner: null | any): IEncryptionSetBanner {
return {
type: ENCRYPTION.SET_BANNER,
banner
};
}
export function encryptionDecodeKey(password: string): IEncryptionDecodeKey {
return {
type: ENCRYPTION.DECODE_KEY,
password
};
}

View File

@ -10,3 +10,5 @@ export interface IBaseScreen<T extends Record<string, object | undefined>, S ext
}
export * from './redux';
export * from './redux/TRootEnum';

View File

@ -0,0 +1,6 @@
export enum RootEnum {
ROOT_OUTSIDE = 'outside',
ROOT_INSIDE = 'inside',
ROOT_LOADING = 'loading',
ROOT_SET_USERNAME = 'setUsername'
}

View File

@ -1,31 +1,42 @@
import { TActionSelectedUsers } from '../../actions/selectedUsers';
import { TActionActiveUsers } from '../../actions/activeUsers';
import { TActionApp } from '../../actions/app';
import { TActionCreateChannel } from '../../actions/createChannel';
import { TActionEncryption } from '../../actions/encryption';
import { TActionSelectedUsers } from '../../actions/selectedUsers';
// REDUCERS
import { IActiveUsers } from '../../reducers/activeUsers';
import { IApp } from '../../reducers/app';
import { IConnect } from '../../reducers/connect';
import { ICreateChannel } from '../../reducers/createChannel';
import { IEncryption } from '../../reducers/encryption';
import { ISelectedUsers } from '../../reducers/selectedUsers';
export interface IApplicationState {
settings: any;
login: any;
meteor: any;
server: any;
selectedUsers: ISelectedUsers;
createChannel: any;
app: any;
room: any;
rooms: any;
sortPreferences: any;
share: any;
customEmojis: any;
activeUsers: IActiveUsers;
usersTyping: any;
inviteLinks: any;
app: IApp;
createChannel: ICreateChannel;
createDiscussion: any;
inquiry: any;
customEmojis: any;
encryption: IEncryption;
enterpriseModules: any;
encryption: any;
inquiry: any;
inviteLinks: any;
login: any;
meteor: IConnect;
permissions: any;
roles: any;
room: any;
rooms: any;
selectedUsers: ISelectedUsers;
server: any;
settings: any;
share: any;
sortPreferences: any;
usersTyping: any;
}
export type TApplicationActions = TActionActiveUsers & TActionSelectedUsers;
export type TApplicationActions = TActionActiveUsers &
TActionSelectedUsers &
TActionApp &
TActionCreateChannel &
TActionEncryption;

44
app/reducers/app.test.ts Normal file
View File

@ -0,0 +1,44 @@
import { appStart, appInit, setMasterDetail } from '../actions/app';
import { initialState } from './app';
import { mockedStore } from './mockedStore';
import { RootEnum } from '../definitions';
import { APP_STATE } from '../actions/actionsTypes';
describe('test reducer', () => {
it('should return initial state', () => {
const state = mockedStore.getState().app;
expect(state).toEqual(initialState);
});
it('should return root state after dispatch appStart action', () => {
mockedStore.dispatch(appStart({ root: RootEnum.ROOT_INSIDE }));
const { root } = mockedStore.getState().app;
expect(root).toEqual(RootEnum.ROOT_INSIDE);
});
it('should return ready state after dispatch appInit action', () => {
mockedStore.dispatch(appInit());
const { ready } = mockedStore.getState().app;
expect(ready).toEqual(false);
});
it('should return ready state after dispatch setMasterDetail action', () => {
mockedStore.dispatch(setMasterDetail(false));
const { isMasterDetail } = mockedStore.getState().app;
expect(isMasterDetail).toEqual(false);
});
it('should return correct state after app go to foreground', () => {
mockedStore.dispatch({ type: APP_STATE.FOREGROUND });
const { foreground, background } = mockedStore.getState().app;
expect(foreground).toEqual(true);
expect(background).toEqual(false);
});
it('should return correct state after app go to background', () => {
mockedStore.dispatch({ type: APP_STATE.BACKGROUND });
const { foreground, background } = mockedStore.getState().app;
expect(foreground).toEqual(false);
expect(background).toEqual(true);
});
});

View File

@ -1,15 +1,26 @@
import { TActionApp } from '../actions/app';
import { RootEnum } from '../definitions';
import { APP, APP_STATE } from '../actions/actionsTypes';
const initialState = {
root: null,
export interface IApp {
root?: RootEnum;
isMasterDetail: boolean;
text?: string;
ready: boolean;
foreground: boolean;
background: boolean;
}
export const initialState: IApp = {
root: undefined,
isMasterDetail: false,
text: null,
text: undefined,
ready: false,
foreground: true,
background: false
};
export default function app(state = initialState, action) {
export default function app(state = initialState, action: TActionApp): IApp {
switch (action.type) {
case APP_STATE.FOREGROUND:
return {

View File

@ -0,0 +1,28 @@
import { connectRequest, connectSuccess, disconnect } from '../actions/connect';
import { initialState } from './connect';
import { mockedStore } from './mockedStore';
describe('test reducer', () => {
it('should return initial state', () => {
const { meteor } = mockedStore.getState();
expect(meteor).toEqual(initialState);
});
it('should return correct meteor state after dispatch connectRequest action', () => {
mockedStore.dispatch(connectRequest());
const { meteor } = mockedStore.getState();
expect(meteor).toEqual({ connecting: true, connected: false });
});
it('should return correct meteor state after dispatch connectSuccess action', () => {
mockedStore.dispatch(connectSuccess());
const { meteor } = mockedStore.getState();
expect(meteor).toEqual({ connecting: false, connected: true });
});
it('should return correct meteor state after dispatch disconnect action', () => {
mockedStore.dispatch(disconnect());
const { meteor } = mockedStore.getState();
expect(meteor).toEqual(initialState);
});
});

View File

@ -1,11 +1,18 @@
import { Action } from 'redux';
import { METEOR } from '../actions/actionsTypes';
const initialState = {
export interface IConnect {
connecting: boolean;
connected: boolean;
}
export const initialState: IConnect = {
connecting: false,
connected: false
};
export default function connect(state = initialState, action) {
export default function connect(state = initialState, action: Action): IConnect {
switch (action.type) {
case METEOR.REQUEST:
return {

View File

@ -0,0 +1,33 @@
import { createChannelRequest, createChannelSuccess, createChannelFailure } from '../actions/createChannel';
import { initialState } from './createChannel';
import { mockedStore } from './mockedStore';
describe('test reducer', () => {
it('should return initial state', () => {
const { createChannel } = mockedStore.getState();
expect(createChannel).toEqual(initialState);
});
it('should return correct createChannel state after dispatch createChannelRequest action', () => {
mockedStore.dispatch(createChannelRequest({}));
const { createChannel } = mockedStore.getState();
expect(createChannel).toEqual({ isFetching: true, failure: false, error: {}, result: {} });
});
it('should return correct createChannel state after dispatch createChannelSuccess action', () => {
mockedStore.dispatch(createChannelSuccess({ data: true }));
const { createChannel } = mockedStore.getState();
expect(createChannel).toEqual({ isFetching: false, failure: false, result: { data: true }, error: {} });
});
it('should return correct createChannel state after dispatch createChannelFailure action', () => {
mockedStore.dispatch(createChannelFailure({ err: true }, true));
const { createChannel } = mockedStore.getState();
expect(createChannel).toEqual({
isFetching: false,
failure: true,
result: { data: true },
error: { err: true }
});
});
});

View File

@ -1,13 +1,21 @@
import { TApplicationActions } from '../definitions';
import { CREATE_CHANNEL } from '../actions/actionsTypes';
const initialState = {
export interface ICreateChannel {
isFetching: boolean;
failure: boolean;
result: Record<string, string>;
error: Record<string, string>;
}
export const initialState: ICreateChannel = {
isFetching: false,
failure: false,
result: {},
error: {}
};
export default function (state = initialState, action) {
export default function (state = initialState, action: TApplicationActions): ICreateChannel {
switch (action.type) {
case CREATE_CHANNEL.REQUEST:
return {

View File

@ -0,0 +1,33 @@
import { createDiscussionRequest, createDiscussionSuccess, createDiscussionFailure } from '../actions/createDiscussion';
import { initialState } from './createDiscussion';
import { mockedStore } from './mockedStore';
describe('test reducer', () => {
it('should return initial state', () => {
const { createDiscussion } = mockedStore.getState();
expect(createDiscussion).toEqual(initialState);
});
it('should return correct createDiscussion state after dispatch createDiscussionRequest action', () => {
mockedStore.dispatch(createDiscussionRequest({}));
const { createDiscussion } = mockedStore.getState();
expect(createDiscussion).toEqual({ isFetching: true, failure: false, error: {}, result: {} });
});
it('should return correct createDiscussion state after dispatch createDiscussionSuccess action', () => {
mockedStore.dispatch(createDiscussionSuccess({ data: true }));
const { createDiscussion } = mockedStore.getState();
expect(createDiscussion).toEqual({ isFetching: false, failure: false, result: { data: true }, error: {} });
});
it('should return correct createDiscussion state after dispatch createDiscussionFailure action', () => {
mockedStore.dispatch(createDiscussionFailure({ err: true }));
const { createDiscussion } = mockedStore.getState();
expect(createDiscussion).toEqual({
isFetching: false,
failure: true,
result: { data: true },
error: { err: true }
});
});
});

View File

@ -1,13 +1,21 @@
import { TApplicationActions } from '../definitions';
import { CREATE_DISCUSSION } from '../actions/actionsTypes';
const initialState = {
export interface ICreateDiscussion {
isFetching: boolean;
failure: boolean;
result: Record<string, string>;
error: Record<string, string>;
}
export const initialState: ICreateDiscussion = {
isFetching: false,
failure: false,
result: {},
error: {}
};
export default function (state = initialState, action) {
export default function (state = initialState, action: TApplicationActions): ICreateDiscussion {
switch (action.type) {
case CREATE_DISCUSSION.REQUEST:
return {

View File

@ -0,0 +1,24 @@
import { encryptionSet, encryptionSetBanner } from '../actions/encryption';
import { initialState } from './encryption';
import { mockedStore } from './mockedStore';
describe('test reducer', () => {
it('should return initial state', () => {
const { encryption } = mockedStore.getState();
expect(encryption).toEqual(initialState);
});
it('should return correct createDiscussion state after dispatch createDiscussionRequest action', () => {
mockedStore.dispatch(encryptionSet(true, {}));
const { encryption } = mockedStore.getState();
expect(encryption).toEqual({ enabled: true, banner: {} });
});
it('should return correct createDiscussion state after dispatch createDiscussionSuccess action', () => {
mockedStore.dispatch(encryptionSetBanner('test'));
const {
encryption: { banner }
} = mockedStore.getState();
expect(banner).toEqual('test');
});
});

View File

@ -1,11 +1,17 @@
import { TApplicationActions } from '../definitions';
import { ENCRYPTION } from '../actions/actionsTypes';
const initialState = {
export interface IEncryption {
enabled: boolean;
banner: null | any;
}
export const initialState: IEncryption = {
enabled: false,
banner: null
};
export default function encryption(state = initialState, action) {
export default function encryption(state = initialState, action: TApplicationActions): IEncryption {
switch (action.type) {
case ENCRYPTION.SET:
return {

View File

@ -8,11 +8,12 @@ import { inviteLinksRequest, inviteLinksSetToken } from '../actions/inviteLinks'
import database from '../lib/database';
import RocketChat from '../lib/rocketchat';
import EventEmitter from '../utils/events';
import { ROOT_INSIDE, ROOT_OUTSIDE, appInit, appStart } from '../actions/app';
import { appInit, appStart } from '../actions/app';
import { localAuthenticate } from '../utils/localAuthentication';
import { goRoom } from '../utils/goRoom';
import { loginRequest } from '../actions/login';
import log from '../utils/log';
import { RootEnum } from '../definitions';
const roomTypes = {
channel: 'c',
@ -41,7 +42,7 @@ const popToRoot = function popToRoot({ isMasterDetail }) {
};
const navigate = function* navigate({ params }) {
yield put(appStart({ root: ROOT_INSIDE }));
yield put(appStart({ root: RootEnum.ROOT_INSIDE }));
if (params.path || params.rid) {
let type;
let name;
@ -192,7 +193,7 @@ const handleOpen = function* handleOpen({ params }) {
yield fallbackNavigation();
return;
}
yield put(appStart({ root: ROOT_OUTSIDE }));
yield put(appStart({ root: RootEnum.ROOT_OUTSIDE }));
yield put(serverInitAdd(server));
yield delay(1000);
EventEmitter.emit('NewServer', { server: host });

View File

@ -9,7 +9,8 @@ import RocketChat from '../lib/rocketchat';
import log from '../utils/log';
import database from '../lib/database';
import { localAuthenticate } from '../utils/localAuthentication';
import { ROOT_OUTSIDE, appReady, appStart } from '../actions/app';
import { appReady, appStart } from '../actions/app';
import { RootEnum } from '../definitions';
export const initLocalSettings = function* initLocalSettings() {
const sortPreferences = yield RocketChat.getSortPreferences();
@ -22,7 +23,7 @@ const restore = function* restore() {
let userId = yield UserPreferences.getStringAsync(`${RocketChat.TOKEN_KEY}-${server}`);
if (!server) {
yield put(appStart({ root: ROOT_OUTSIDE }));
yield put(appStart({ root: RootEnum.ROOT_OUTSIDE }));
} else if (!userId) {
const serversDB = database.servers;
const serversCollection = serversDB.get('servers');
@ -38,7 +39,7 @@ const restore = function* restore() {
}
}
}
yield put(appStart({ root: ROOT_OUTSIDE }));
yield put(appStart({ root: RootEnum.ROOT_OUTSIDE }));
} else {
const serversDB = database.servers;
const serverCollections = serversDB.get('servers');
@ -56,7 +57,7 @@ const restore = function* restore() {
yield put(appReady({}));
} catch (e) {
log(e);
yield put(appStart({ root: ROOT_OUTSIDE }));
yield put(appStart({ root: RootEnum.ROOT_OUTSIDE }));
}
};

View File

@ -3,7 +3,7 @@ import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
import { Q } from '@nozbe/watermelondb';
import * as types from '../actions/actionsTypes';
import { ROOT_INSIDE, ROOT_LOADING, ROOT_OUTSIDE, ROOT_SET_USERNAME, appStart } from '../actions/app';
import { appStart } from '../actions/app';
import { selectServerRequest, serverFinishAdd } from '../actions/server';
import { loginFailure, loginSuccess, logout, setUser } from '../actions/login';
import { roomsRequest } from '../actions/rooms';
@ -20,6 +20,7 @@ import { encryptionInit, encryptionStop } from '../actions/encryption';
import UserPreferences from '../lib/userPreferences';
import { inquiryRequest, inquiryReset } from '../ee/omnichannel/actions/inquiry';
import { isOmnichannelStatusAvailable } from '../ee/omnichannel/lib';
import { RootEnum } from '../definitions';
const getServer = state => state.server.server;
const loginWithPasswordCall = args => RocketChat.loginWithPassword(args);
@ -38,7 +39,7 @@ const handleLoginRequest = function* handleLoginRequest({ credentials, logoutOnE
if (!result.username) {
yield put(serverFinishAdd());
yield put(setUser(result));
yield put(appStart({ root: ROOT_SET_USERNAME }));
yield put(appStart({ root: RootEnum.ROOT_SET_USERNAME }));
} else {
const server = yield select(getServer);
yield localAuthenticate(server);
@ -167,7 +168,7 @@ const handleLoginSuccess = function* handleLoginSuccess({ user }) {
yield put(setUser(user));
EventEmitter.emit('connected');
yield put(appStart({ root: ROOT_INSIDE }));
yield put(appStart({ root: RootEnum.ROOT_INSIDE }));
const inviteLinkToken = yield select(state => state.inviteLinks.token);
if (inviteLinkToken) {
yield put(inviteLinksRequest(inviteLinkToken));
@ -179,7 +180,7 @@ const handleLoginSuccess = function* handleLoginSuccess({ user }) {
const handleLogout = function* handleLogout({ forcedByServer }) {
yield put(encryptionStop());
yield put(appStart({ root: ROOT_LOADING, text: I18n.t('Logging_out') }));
yield put(appStart({ root: RootEnum.ROOT_LOADING, text: I18n.t('Logging_out') }));
const server = yield select(getServer);
if (server) {
try {
@ -187,7 +188,7 @@ const handleLogout = function* handleLogout({ forcedByServer }) {
// if the user was logged out by the server
if (forcedByServer) {
yield put(appStart({ root: ROOT_OUTSIDE }));
yield put(appStart({ root: RootEnum.ROOT_OUTSIDE }));
showErrorAlert(I18n.t('Logged_out_by_server'), I18n.t('Oops'));
yield delay(300);
EventEmitter.emit('NewServer', { server });
@ -209,10 +210,10 @@ const handleLogout = function* handleLogout({ forcedByServer }) {
}
}
// if there's no servers, go outside
yield put(appStart({ root: ROOT_OUTSIDE }));
yield put(appStart({ root: RootEnum.ROOT_OUTSIDE }));
}
} catch (e) {
yield put(appStart({ root: ROOT_OUTSIDE }));
yield put(appStart({ root: RootEnum.ROOT_OUTSIDE }));
log(e);
}
}

View File

@ -15,11 +15,12 @@ import database from '../lib/database';
import log, { logServerVersion } from '../utils/log';
import I18n from '../i18n';
import { BASIC_AUTH_KEY, setBasicAuth } from '../utils/fetch';
import { ROOT_INSIDE, ROOT_OUTSIDE, appStart } from '../actions/app';
import { appStart } from '../actions/app';
import UserPreferences from '../lib/userPreferences';
import { encryptionStop } from '../actions/encryption';
import SSLPinning from '../utils/sslPinning';
import { inquiryReset } from '../ee/omnichannel/actions/inquiry';
import { RootEnum } from '../definitions';
const getServerInfo = function* getServerInfo({ server, raiseError = true }) {
try {
@ -111,10 +112,10 @@ const handleSelectServer = function* handleSelectServer({ server, version, fetch
yield put(clearSettings());
yield RocketChat.connect({ server, user, logoutOnError: true });
yield put(setUser(user));
yield put(appStart({ root: ROOT_INSIDE }));
yield put(appStart({ root: RootEnum.ROOT_INSIDE }));
} else {
yield RocketChat.connect({ server });
yield put(appStart({ root: ROOT_OUTSIDE }));
yield put(appStart({ root: RootEnum.ROOT_OUTSIDE }));
}
// We can't use yield here because fetch of Settings & Custom Emojis is slower

View File

@ -5,11 +5,11 @@ import { setBadgeCount } from '../notifications/push';
import log from '../utils/log';
import { localAuthenticate, saveLastLocalAuthenticationSession } from '../utils/localAuthentication';
import { APP_STATE } from '../actions/actionsTypes';
import { ROOT_OUTSIDE } from '../actions/app';
import { RootEnum } from '../definitions';
const appHasComeBackToForeground = function* appHasComeBackToForeground() {
const appRoot = yield select(state => state.app.root);
if (appRoot === ROOT_OUTSIDE) {
if (appRoot === RootEnum.ROOT_OUTSIDE) {
return;
}
const login = yield select(state => state.login);
@ -29,7 +29,7 @@ const appHasComeBackToForeground = function* appHasComeBackToForeground() {
const appHasComeBackToBackground = function* appHasComeBackToBackground() {
const appRoot = yield select(state => state.app.root);
if (appRoot === ROOT_OUTSIDE) {
if (appRoot === RootEnum.ROOT_OUTSIDE) {
return;
}
try {

View File

@ -13,10 +13,11 @@ import StatusBar from '../../containers/StatusBar';
import * as List from '../../containers/List';
import { themes } from '../../constants/colors';
import { withTheme } from '../../theme';
import { ROOT_INSIDE, ROOT_LOADING, appStart as appStartAction } from '../../actions/app';
import { appStart as appStartAction } from '../../actions/app';
import { getUserSelector } from '../../selectors/login';
import database from '../../lib/database';
import SafeAreaView from '../../containers/SafeAreaView';
import { RootEnum } from '../../definitions';
interface ILanguageViewProps {
user: {
@ -73,7 +74,7 @@ class LanguageView extends React.Component<ILanguageViewProps, ILanguageViewStat
const shouldRestart = isRTL(language) || isRTL(user.language);
await appStart({ root: ROOT_LOADING, text: I18n.t('Change_language_loading') });
await appStart({ root: RootEnum.ROOT_LOADING, text: I18n.t('Change_language_loading') });
// shows loading for at least 300ms
await Promise.all([this.changeLanguage(language), new Promise(resolve => setTimeout(resolve, 300))]);
@ -81,7 +82,7 @@ class LanguageView extends React.Component<ILanguageViewProps, ILanguageViewStat
if (shouldRestart) {
await RNRestart.Restart();
} else {
await appStart({ root: ROOT_INSIDE });
await appStart({ root: RootEnum.ROOT_INSIDE });
}
};

View File

@ -8,7 +8,7 @@ import * as List from '../../containers/List';
import Button from '../../containers/Button';
import { toggleServerDropdown as toggleServerDropdownAction } from '../../actions/rooms';
import { selectServerRequest as selectServerRequestAction, serverInitAdd as serverInitAddAction } from '../../actions/server';
import { appStart as appStartAction, ROOT_OUTSIDE } from '../../actions/app';
import { appStart as appStartAction } from '../../actions/app';
import RocketChat from '../../lib/rocketchat';
import I18n from '../../i18n';
import EventEmitter from '../../utils/events';
@ -24,6 +24,8 @@ import log, { events, logEvent } from '../../utils/log';
import { headerHeight } from '../../containers/Header';
import { goRoom } from '../../utils/goRoom';
import UserPreferences from '../../lib/userPreferences';
import { RootEnum } from '../../definitions';
import styles from './styles';
const ROW_HEIGHT = 68;
@ -110,7 +112,7 @@ class ServerDropdown extends Component {
navToNewServer = previousServer => {
const { appStart, initAdd } = this.props;
batch(() => {
appStart({ root: ROOT_OUTSIDE });
appStart({ root: RootEnum.ROOT_OUTSIDE });
initAdd(previousServer);
});
};

View File

@ -50,6 +50,7 @@ import { E2E_BANNER_TYPE } from '../../lib/encryption/constants';
import { getInquiryQueueSelector } from '../../ee/omnichannel/selectors/inquiry';
import { changeLivechatStatus, isOmnichannelStatusAvailable } from '../../ee/omnichannel/lib';
import { DisplayMode, SortBy } from '../../constants/constantDisplayMode';
import { RootEnum } from '../../definitions';
import styles from './styles';
import ServerDropdown from './ServerDropdown';
import ListHeader from './ListHeader';
@ -862,7 +863,7 @@ class RoomsListView extends React.Component {
}
} else if (handleCommandAddNewServer(event)) {
batch(() => {
appStart({ root: ROOT_OUTSIDE });
appStart({ root: RootEnum.ROOT_OUTSIDE });
initAdd(server);
});
}

View File

@ -23,12 +23,13 @@ import { withTheme } from '../../theme';
import SidebarView from '../SidebarView';
import { LISTENER } from '../../containers/Toast';
import EventEmitter from '../../utils/events';
import { ROOT_LOADING, appStart as appStartAction } from '../../actions/app';
import { appStart as appStartAction } from '../../actions/app';
import { onReviewPress } from '../../utils/review';
import SafeAreaView from '../../containers/SafeAreaView';
import database from '../../lib/database';
import { isFDroidBuild } from '../../constants/environment';
import { getUserSelector } from '../../selectors/login';
import { RootEnum } from '../../definitions';
interface ISettingsViewProps {
navigation: StackNavigationProp<SettingsStackParamList, 'SettingsView'>;
@ -108,7 +109,7 @@ class SettingsView extends React.Component<ISettingsViewProps, any> {
appStart,
selectServerRequest
} = this.props;
appStart({ root: ROOT_LOADING, text: I18n.t('Clear_cache_loading') });
appStart({ root: RootEnum.ROOT_LOADING, text: I18n.t('Clear_cache_loading') });
await RocketChat.clearCache({ server });
await FastImage.clearMemoryCache();
await FastImage.clearDiskCache();