From 3b97c349595121d4c53be7058cafdcf683fb3813 Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Tue, 21 Dec 2021 09:51:04 -0300 Subject: [PATCH 01/21] chore: migrate activeUsers reducer and action to TS --- app/actions/activeUsers.js | 8 -------- app/actions/activeUsers.ts | 14 ++++++++++++++ app/reducers/activeUsers.js | 15 --------------- app/reducers/activeUsers.ts | 27 +++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 23 deletions(-) delete mode 100644 app/actions/activeUsers.js create mode 100644 app/actions/activeUsers.ts delete mode 100644 app/reducers/activeUsers.js create mode 100644 app/reducers/activeUsers.ts diff --git a/app/actions/activeUsers.js b/app/actions/activeUsers.js deleted file mode 100644 index fc359602c17..00000000000 --- a/app/actions/activeUsers.js +++ /dev/null @@ -1,8 +0,0 @@ -import { SET_ACTIVE_USERS } from './actionsTypes'; - -export function setActiveUsers(activeUsers) { - return { - type: SET_ACTIVE_USERS, - activeUsers - }; -} diff --git a/app/actions/activeUsers.ts b/app/actions/activeUsers.ts new file mode 100644 index 00000000000..3e6271ee9ff --- /dev/null +++ b/app/actions/activeUsers.ts @@ -0,0 +1,14 @@ +import { Action } from 'redux'; + +import { ActiveUsers } from '../reducers/activeUsers'; +import { SET_ACTIVE_USERS } from './actionsTypes'; + +export interface SetActiveUsers extends Action { + type: typeof SET_ACTIVE_USERS; + activeUsers: ActiveUsers; +} + +export const setActiveUsers = (activeUsers: ActiveUsers): SetActiveUsers => ({ + type: SET_ACTIVE_USERS, + activeUsers +}); diff --git a/app/reducers/activeUsers.js b/app/reducers/activeUsers.js deleted file mode 100644 index 8f6c5b38ad6..00000000000 --- a/app/reducers/activeUsers.js +++ /dev/null @@ -1,15 +0,0 @@ -import { SET_ACTIVE_USERS } from '../actions/actionsTypes'; - -const initialState = {}; - -export default function activeUsers(state = initialState, action) { - switch (action.type) { - case SET_ACTIVE_USERS: - return { - ...state, - ...action.activeUsers - }; - default: - return state; - } -} diff --git a/app/reducers/activeUsers.ts b/app/reducers/activeUsers.ts new file mode 100644 index 00000000000..306c24e7e41 --- /dev/null +++ b/app/reducers/activeUsers.ts @@ -0,0 +1,27 @@ +import { SetActiveUsers } from '../actions/activeUsers'; +import { SET_ACTIVE_USERS } from '../actions/actionsTypes'; + +type UserStatus = 'online' | 'offline'; + +interface ActiveUser { + readonly status: UserStatus; + readonly statusText?: string; +} + +export interface ActiveUsers { + [key: string]: ActiveUser; +} + +const initialState: ActiveUsers = {}; + +export default function activeUsers(state = initialState, action: SetActiveUsers): ActiveUsers { + switch (action.type) { + case SET_ACTIVE_USERS: + return { + ...state, + ...action.activeUsers + }; + default: + return state; + } +} From 34e6ece8716cd8b33a1b6318427a10d9de11977e Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Tue, 21 Dec 2021 10:11:40 -0300 Subject: [PATCH 02/21] chore: init types folder and set redux and BaseScreen interface --- app/types/index.ts | 10 ++++++++++ app/types/redux/index.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 app/types/index.ts create mode 100644 app/types/redux/index.ts diff --git a/app/types/index.ts b/app/types/index.ts new file mode 100644 index 00000000000..ea8f9adb469 --- /dev/null +++ b/app/types/index.ts @@ -0,0 +1,10 @@ +import { StackNavigationProp } from '@react-navigation/stack'; +import { Dispatch } from 'redux'; + +export interface BaseScreen { + navigation: StackNavigationProp; + dispatch: Dispatch; + theme: string; +} + +export * from './redux'; diff --git a/app/types/redux/index.ts b/app/types/redux/index.ts new file mode 100644 index 00000000000..a52e979f35b --- /dev/null +++ b/app/types/redux/index.ts @@ -0,0 +1,28 @@ +import { SetActiveUsers } from '../../actions/activeUsers'; +import { ActiveUsers } from '../../reducers/activeUsers'; + +export interface ApplicationState { + settings: any; + login: any; + meteor: any; + server: any; + selectedUsers: any; + createChannel: any; + app: any; + room: any; + rooms: any; + sortPreferences: any; + share: any; + customEmojis: any; + activeUsers: ActiveUsers; + usersTyping: any; + inviteLinks: any; + createDiscussion: any; + inquiry: any; + enterpriseModules: any; + encryption: any; + permissions: any; + roles: any; +} + +export type ApplicationActions = SetActiveUsers; From 9d7450b300f162f48cf9cabd2a3302eada5ac013 Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Tue, 21 Dec 2021 10:17:11 -0300 Subject: [PATCH 03/21] chore: remove mapDispatchToProps to use dispatch prop and clear some types --- app/views/SelectedUsersView.tsx | 80 +++++++++++++++------------------ 1 file changed, 36 insertions(+), 44 deletions(-) diff --git a/app/views/SelectedUsersView.tsx b/app/views/SelectedUsersView.tsx index 8d4a19fc4ac..3e2ddeb9771 100644 --- a/app/views/SelectedUsersView.tsx +++ b/app/views/SelectedUsersView.tsx @@ -1,30 +1,30 @@ -import React from 'react'; -import { StackNavigationProp } from '@react-navigation/stack'; +import { Q } from '@nozbe/watermelondb'; import { RouteProp } from '@react-navigation/native'; +import orderBy from 'lodash/orderBy'; +import React from 'react'; import { FlatList, View } from 'react-native'; import { connect } from 'react-redux'; -import orderBy from 'lodash/orderBy'; -import { Q } from '@nozbe/watermelondb'; import { Subscription } from 'rxjs'; +import { addUser, removeUser, reset } from '../actions/selectedUsers'; +import { themes } from '../constants/colors'; +import * as HeaderButton from '../containers/HeaderButton'; import * as List from '../containers/List'; -import database from '../lib/database'; -import RocketChat from '../lib/rocketchat'; -import UserItem from '../presentation/UserItem'; import Loading from '../containers/Loading'; -import I18n from '../i18n'; -import log, { events, logEvent } from '../utils/log'; +import SafeAreaView from '../containers/SafeAreaView'; import SearchBox from '../containers/SearchBox'; -import * as HeaderButton from '../containers/HeaderButton'; import StatusBar from '../containers/StatusBar'; -import { themes } from '../constants/colors'; -import { withTheme } from '../theme'; +import I18n from '../i18n'; +import database from '../lib/database'; +import RocketChat from '../lib/rocketchat'; +import UserItem from '../presentation/UserItem'; import { getUserSelector } from '../selectors/login'; -import { addUser as addUserAction, removeUser as removeUserAction, reset as resetAction } from '../actions/selectedUsers'; +import { ChatsStackParamList } from '../stacks/types'; +import { withTheme } from '../theme'; +import { ApplicationState, BaseScreen } from '../types'; import { showErrorAlert } from '../utils/info'; -import SafeAreaView from '../containers/SafeAreaView'; +import log, { events, logEvent } from '../utils/log'; import sharedStyles from './Styles'; -import { ChatsStackParamList } from '../stacks/types'; const ITEM_WIDTH = 250; const getItemLayout = (_: any, index: number) => ({ length: ITEM_WIDTH, offset: ITEM_WIDTH * index, index }); @@ -37,19 +37,8 @@ interface IUser { // username is used when is from searching username?: string; } -interface ISelectedUsersViewState { - maxUsers?: number; - search: IUser[]; - chats: IUser[]; -} -interface ISelectedUsersViewProps { - navigation: StackNavigationProp; - route: RouteProp; - baseUrl: string; - addUser(user: IUser): void; - removeUser(user: IUser): void; - reset(): void; +type State = { users: IUser[]; loading: boolean; user: { @@ -58,7 +47,17 @@ interface ISelectedUsersViewProps { username: string; name: string; }; - theme: string; + baseUrl: string; +}; + +interface ISelectedUsersViewState { + maxUsers?: number; + search: IUser[]; + chats: IUser[]; +} + +interface ISelectedUsersViewProps extends BaseScreen, State { + route: RouteProp; } class SelectedUsersView extends React.Component { @@ -75,9 +74,9 @@ class SelectedUsersView extends React.Component { const { maxUsers } = this.state; const { - addUser, - removeUser, + dispatch, users, user: { username } } = this.props; @@ -177,10 +175,10 @@ class SelectedUsersView extends React.Component ({ +const mapStateToProps = (state: ApplicationState) => ({ baseUrl: state.server.server, users: state.selectedUsers.users, loading: state.selectedUsers.loading, user: getUserSelector(state) }); -const mapDispatchToProps = (dispatch: any) => ({ - addUser: (user: any) => dispatch(addUserAction(user)), - removeUser: (user: any) => dispatch(removeUserAction(user)), - reset: () => dispatch(resetAction()) -}); - -export default connect(mapStateToProps, mapDispatchToProps)(withTheme(SelectedUsersView)); +export default connect(mapStateToProps)(withTheme(SelectedUsersView)); From 003f9fca68987dc3404ea1de14991530419bf6d5 Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Tue, 21 Dec 2021 12:03:59 -0300 Subject: [PATCH 04/21] chore: type selectedUsers action and reducer and improvement in the code of other files --- .../{actionsTypes.js => actionsTypes.ts} | 4 +- app/actions/activeUsers.ts | 9 ++-- app/actions/selectedUsers.js | 28 ------------ app/actions/selectedUsers.ts | 43 +++++++++++++++++++ app/reducers/activeUsers.ts | 15 ++----- .../{selectedUsers.js => selectedUsers.ts} | 10 ++++- app/types/index.ts | 15 +++++++ app/types/redux/index.ts | 13 +++--- 8 files changed, 85 insertions(+), 52 deletions(-) rename app/actions/{actionsTypes.js => actionsTypes.ts} (96%) delete mode 100644 app/actions/selectedUsers.js create mode 100644 app/actions/selectedUsers.ts rename app/reducers/{selectedUsers.js => selectedUsers.ts} (67%) diff --git a/app/actions/actionsTypes.js b/app/actions/actionsTypes.ts similarity index 96% rename from app/actions/actionsTypes.js rename to app/actions/actionsTypes.ts index 852ce83eab5..ad2d1718de5 100644 --- a/app/actions/actionsTypes.js +++ b/app/actions/actionsTypes.ts @@ -2,8 +2,8 @@ const REQUEST = 'REQUEST'; const SUCCESS = 'SUCCESS'; const FAILURE = 'FAILURE'; const defaultTypes = [REQUEST, SUCCESS, FAILURE]; -function createRequestTypes(base, types = defaultTypes) { - const res = {}; +function createRequestTypes(base = {}, types = defaultTypes): Record { + const res: Record = {}; types.forEach(type => (res[type] = `${base}_${type}`)); return res; } diff --git a/app/actions/activeUsers.ts b/app/actions/activeUsers.ts index 3e6271ee9ff..1ba58c7982e 100644 --- a/app/actions/activeUsers.ts +++ b/app/actions/activeUsers.ts @@ -1,14 +1,15 @@ import { Action } from 'redux'; -import { ActiveUsers } from '../reducers/activeUsers'; +import { IActiveUsers } from '../reducers/activeUsers'; import { SET_ACTIVE_USERS } from './actionsTypes'; export interface SetActiveUsers extends Action { - type: typeof SET_ACTIVE_USERS; - activeUsers: ActiveUsers; + activeUsers: IActiveUsers; } -export const setActiveUsers = (activeUsers: ActiveUsers): SetActiveUsers => ({ +export type IActionActiveUsers = SetActiveUsers; + +export const setActiveUsers = (activeUsers: IActiveUsers): SetActiveUsers => ({ type: SET_ACTIVE_USERS, activeUsers }); diff --git a/app/actions/selectedUsers.js b/app/actions/selectedUsers.js deleted file mode 100644 index 65fbb00153f..00000000000 --- a/app/actions/selectedUsers.js +++ /dev/null @@ -1,28 +0,0 @@ -import * as types from './actionsTypes'; - -export function addUser(user) { - return { - type: types.SELECTED_USERS.ADD_USER, - user - }; -} - -export function removeUser(user) { - return { - type: types.SELECTED_USERS.REMOVE_USER, - user - }; -} - -export function reset() { - return { - type: types.SELECTED_USERS.RESET - }; -} - -export function setLoading(loading) { - return { - type: types.SELECTED_USERS.SET_LOADING, - loading - }; -} diff --git a/app/actions/selectedUsers.ts b/app/actions/selectedUsers.ts new file mode 100644 index 00000000000..844aa3473ca --- /dev/null +++ b/app/actions/selectedUsers.ts @@ -0,0 +1,43 @@ +import { Action } from 'redux'; + +import { IUser } from '../types'; +import * as types from './actionsTypes'; + +type User = { + user: IUser; +}; + +type IAction = Action & User; + +interface SetLoading extends Action { + loading: boolean; +} + +export type IActionSelectedUsers = IAction & SetLoading; + +export function addUser(user: IUser): IAction { + return { + type: types.SELECTED_USERS.ADD_USER, + user + }; +} + +export function removeUser(user: IUser): IAction { + return { + type: types.DEEP_LINKING, + user + }; +} + +export function reset(): Action { + return { + type: types.SELECTED_USERS.RESET + }; +} + +export function setLoading(loading: boolean): SetLoading { + return { + type: types.SELECTED_USERS.SET_LOADING, + loading + }; +} diff --git a/app/reducers/activeUsers.ts b/app/reducers/activeUsers.ts index 306c24e7e41..47d8cd2cd90 100644 --- a/app/reducers/activeUsers.ts +++ b/app/reducers/activeUsers.ts @@ -1,20 +1,13 @@ -import { SetActiveUsers } from '../actions/activeUsers'; +import { ActiveUser, ApplicationActions } from '../types'; import { SET_ACTIVE_USERS } from '../actions/actionsTypes'; -type UserStatus = 'online' | 'offline'; - -interface ActiveUser { - readonly status: UserStatus; - readonly statusText?: string; -} - -export interface ActiveUsers { +export interface IActiveUsers { [key: string]: ActiveUser; } -const initialState: ActiveUsers = {}; +const initialState: IActiveUsers = {}; -export default function activeUsers(state = initialState, action: SetActiveUsers): ActiveUsers { +export default function activeUsers(state = initialState, action: ApplicationActions): IActiveUsers { switch (action.type) { case SET_ACTIVE_USERS: return { diff --git a/app/reducers/selectedUsers.js b/app/reducers/selectedUsers.ts similarity index 67% rename from app/reducers/selectedUsers.js rename to app/reducers/selectedUsers.ts index 42d7982c1cc..bbc7bc99624 100644 --- a/app/reducers/selectedUsers.js +++ b/app/reducers/selectedUsers.ts @@ -1,11 +1,17 @@ +import { IUser, ApplicationActions } from '../types'; import { SELECTED_USERS } from '../actions/actionsTypes'; -const initialState = { +export interface ISelectedUsers { + users: IUser[]; + loading: boolean; +} + +const initialState: ISelectedUsers = { users: [], loading: false }; -export default function (state = initialState, action) { +export default function (state = initialState, action: ApplicationActions): ISelectedUsers { switch (action.type) { case SELECTED_USERS.ADD_USER: return { diff --git a/app/types/index.ts b/app/types/index.ts index ea8f9adb469..6bb354fdfe7 100644 --- a/app/types/index.ts +++ b/app/types/index.ts @@ -7,4 +7,19 @@ export interface BaseScreen { theme: string; } +export interface IUser { + _id: string; + name: string; + fname: string; + search?: boolean; + // username is used when is from searching + username?: string; +} + +type UserStatus = 'online' | 'offline'; +export interface ActiveUser { + status: UserStatus; + statusText?: string; +} + export * from './redux'; diff --git a/app/types/redux/index.ts b/app/types/redux/index.ts index a52e979f35b..fe61c50a515 100644 --- a/app/types/redux/index.ts +++ b/app/types/redux/index.ts @@ -1,12 +1,15 @@ -import { SetActiveUsers } from '../../actions/activeUsers'; -import { ActiveUsers } from '../../reducers/activeUsers'; +import { IActionSelectedUsers } from '../../actions/selectedUsers'; +import { IActionActiveUsers } from '../../actions/activeUsers'; +// REDUCERS +import { IActiveUsers } from '../../reducers/activeUsers'; +import { ISelectedUsers } from '../../reducers/selectedUsers'; export interface ApplicationState { settings: any; login: any; meteor: any; server: any; - selectedUsers: any; + selectedUsers: ISelectedUsers; createChannel: any; app: any; room: any; @@ -14,7 +17,7 @@ export interface ApplicationState { sortPreferences: any; share: any; customEmojis: any; - activeUsers: ActiveUsers; + activeUsers: IActiveUsers; usersTyping: any; inviteLinks: any; createDiscussion: any; @@ -25,4 +28,4 @@ export interface ApplicationState { roles: any; } -export type ApplicationActions = SetActiveUsers; +export type ApplicationActions = IActionActiveUsers & IActionSelectedUsers; From 010676aa851e97ad43225cda973c29203cf8f013 Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Tue, 21 Dec 2021 12:04:39 -0300 Subject: [PATCH 05/21] chore: move IUser to base types --- app/views/SelectedUsersView.tsx | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/app/views/SelectedUsersView.tsx b/app/views/SelectedUsersView.tsx index 3e2ddeb9771..4634bfa7e50 100644 --- a/app/views/SelectedUsersView.tsx +++ b/app/views/SelectedUsersView.tsx @@ -21,7 +21,7 @@ import UserItem from '../presentation/UserItem'; import { getUserSelector } from '../selectors/login'; import { ChatsStackParamList } from '../stacks/types'; import { withTheme } from '../theme'; -import { ApplicationState, BaseScreen } from '../types'; +import { ApplicationState, BaseScreen, IUser } from '../types'; import { showErrorAlert } from '../utils/info'; import log, { events, logEvent } from '../utils/log'; import sharedStyles from './Styles'; @@ -29,15 +29,6 @@ import sharedStyles from './Styles'; const ITEM_WIDTH = 250; const getItemLayout = (_: any, index: number) => ({ length: ITEM_WIDTH, offset: ITEM_WIDTH * index, index }); -interface IUser { - _id: string; - name: string; - fname: string; - search?: boolean; - // username is used when is from searching - username?: string; -} - type State = { users: IUser[]; loading: boolean; From dc83f7684324900c11e906d0cdc975e65141cda4 Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Tue, 21 Dec 2021 17:01:33 -0300 Subject: [PATCH 06/21] chore: move state props to ISelectedUsersViewProps --- app/views/SelectedUsersView.tsx | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/app/views/SelectedUsersView.tsx b/app/views/SelectedUsersView.tsx index 4634bfa7e50..e6c1b19aa98 100644 --- a/app/views/SelectedUsersView.tsx +++ b/app/views/SelectedUsersView.tsx @@ -29,7 +29,15 @@ import sharedStyles from './Styles'; const ITEM_WIDTH = 250; const getItemLayout = (_: any, index: number) => ({ length: ITEM_WIDTH, offset: ITEM_WIDTH * index, index }); -type State = { +interface ISelectedUsersViewState { + maxUsers?: number; + search: IUser[]; + chats: IUser[]; +} + +interface ISelectedUsersViewProps extends BaseScreen { + route: RouteProp; + // REDUX STATE users: IUser[]; loading: boolean; user: { @@ -39,16 +47,6 @@ type State = { name: string; }; baseUrl: string; -}; - -interface ISelectedUsersViewState { - maxUsers?: number; - search: IUser[]; - chats: IUser[]; -} - -interface ISelectedUsersViewProps extends BaseScreen, State { - route: RouteProp; } class SelectedUsersView extends React.Component { From f169f6e0a7b6ea42cf6c57f775f8f03951704578 Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Tue, 21 Dec 2021 17:04:32 -0300 Subject: [PATCH 07/21] chore: create mocketStore --- __mocks__/mockedStore.ts | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 __mocks__/mockedStore.ts diff --git a/__mocks__/mockedStore.ts b/__mocks__/mockedStore.ts new file mode 100644 index 00000000000..3da9dd0e9e7 --- /dev/null +++ b/__mocks__/mockedStore.ts @@ -0,0 +1,8 @@ +import { applyMiddleware, compose, createStore } from 'redux'; +import createSagaMiddleware from 'redux-saga'; + +import applyAppStateMiddleware from '../app/lib/appStateMiddleware'; +import reducers from '../app/reducers'; + +const enhancers = compose(applyAppStateMiddleware(), applyMiddleware(createSagaMiddleware())); +export const mockedStore = createStore(reducers, enhancers); From 69f27438b234020222119dfbf4dee62c5e7d49c1 Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Tue, 21 Dec 2021 17:14:08 -0300 Subject: [PATCH 08/21] chore: remove applyAppStateMiddleware --- __mocks__/mockedStore.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/__mocks__/mockedStore.ts b/__mocks__/mockedStore.ts index 3da9dd0e9e7..a29b7f62969 100644 --- a/__mocks__/mockedStore.ts +++ b/__mocks__/mockedStore.ts @@ -1,8 +1,7 @@ import { applyMiddleware, compose, createStore } from 'redux'; import createSagaMiddleware from 'redux-saga'; -import applyAppStateMiddleware from '../app/lib/appStateMiddleware'; import reducers from '../app/reducers'; -const enhancers = compose(applyAppStateMiddleware(), applyMiddleware(createSagaMiddleware())); +const enhancers = compose(applyMiddleware(createSagaMiddleware())); export const mockedStore = createStore(reducers, enhancers); From b80c0635d6820689196ce414829cd531adc37bd5 Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Tue, 21 Dec 2021 17:14:59 -0300 Subject: [PATCH 09/21] test: create activeUser and selectedUser tests --- __tests__/redux/activeUsers.test.ts | 16 ++++++++++++++++ __tests__/redux/selectedUsers.test.ts | 20 ++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 __tests__/redux/activeUsers.test.ts create mode 100644 __tests__/redux/selectedUsers.test.ts diff --git a/__tests__/redux/activeUsers.test.ts b/__tests__/redux/activeUsers.test.ts new file mode 100644 index 00000000000..e62f82471b2 --- /dev/null +++ b/__tests__/redux/activeUsers.test.ts @@ -0,0 +1,16 @@ +import { setActiveUsers } from '../../app/actions/activeUsers'; +import { IActiveUsers } from '../../app/reducers/activeUsers'; +import { mockedStore } from '../../__mocks__/mockedStore'; + +describe('test reducer', () => { + it('should return {} as initial state', async () => { + const state = mockedStore.getState().activeUsers; + expect(state).toEqual({}); + }); + it('should return modified store after action', async () => { + const activeUsers: IActiveUsers = { any: { status: 'online', statusText: 'any' } }; + mockedStore.dispatch(setActiveUsers(activeUsers)); + const state = mockedStore.getState().activeUsers; + expect(state).toEqual({ ...activeUsers }); + }); +}); diff --git a/__tests__/redux/selectedUsers.test.ts b/__tests__/redux/selectedUsers.test.ts new file mode 100644 index 00000000000..fda0d0a8940 --- /dev/null +++ b/__tests__/redux/selectedUsers.test.ts @@ -0,0 +1,20 @@ +import { addUser } from '../../app/actions/selectedUsers'; +import { mockedStore } from '../../__mocks__/mockedStore'; + +describe('test reducer', () => { + const initialState = { + users: [], + loading: false + }; + it('should return initial state', async () => { + const state = mockedStore.getState().selectedUsers; + expect(state).toEqual(initialState); + }); + + it('should return modified store after action', async () => { + const user = { _id: 'user.id', name: 'user.username', fname: 'user.name' }; + mockedStore.dispatch(addUser(user)); + const state = mockedStore.getState().selectedUsers; + expect(state).toEqual({ loading: false, users: [user] }); + }); +}); From b5bda757bcf293646758497cacafa2e2ad54fb2f Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Wed, 22 Dec 2021 09:27:40 -0300 Subject: [PATCH 10/21] test: add more selectedUsers tests --- __tests__/redux/selectedUsers.test.ts | 31 ++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/__tests__/redux/selectedUsers.test.ts b/__tests__/redux/selectedUsers.test.ts index fda0d0a8940..189ff504c07 100644 --- a/__tests__/redux/selectedUsers.test.ts +++ b/__tests__/redux/selectedUsers.test.ts @@ -1,20 +1,41 @@ -import { addUser } from '../../app/actions/selectedUsers'; +import { addUser, reset, setLoading, removeUser } from '../../app/actions/selectedUsers'; import { mockedStore } from '../../__mocks__/mockedStore'; -describe('test reducer', () => { +describe('test selectedUsers reducer', () => { const initialState = { users: [], loading: false }; + it('should return initial state', async () => { const state = mockedStore.getState().selectedUsers; expect(state).toEqual(initialState); }); - it('should return modified store after action', async () => { - const user = { _id: 'user.id', name: 'user.username', fname: 'user.name' }; + it('should return modified store after addUser', async () => { + const user = { _id: 'xxx', name: 'xxx', fname: 'xxx' }; mockedStore.dispatch(addUser(user)); + const state = mockedStore.getState().selectedUsers.users; + expect(state).toEqual([user]); + }); + + it('should return empty store after remove user', async () => { + const user = { _id: 'xxx', name: 'xxx', fname: 'xxx' }; + mockedStore.dispatch(removeUser(user)); + const state = mockedStore.getState().selectedUsers.users; + expect(state).toEqual([]); + }); + + it('should return initialState after reset', async () => { + mockedStore.dispatch(reset()); const state = mockedStore.getState().selectedUsers; - expect(state).toEqual({ loading: false, users: [user] }); + expect(state).toEqual(initialState); + }); + + it('should return loading after call action', async () => { + const user = { _id: 'user.id', name: 'user.username', fname: 'user.name' }; + mockedStore.dispatch(setLoading(true)); + const state = mockedStore.getState().selectedUsers.loading; + expect(state).toEqual(true); }); }); From b56f6048d4eff0fe5cd975691bc85780338917c8 Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Wed, 22 Dec 2021 09:28:21 -0300 Subject: [PATCH 11/21] chore: fix action type --- app/actions/selectedUsers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/actions/selectedUsers.ts b/app/actions/selectedUsers.ts index 844aa3473ca..cfb09d5855f 100644 --- a/app/actions/selectedUsers.ts +++ b/app/actions/selectedUsers.ts @@ -24,7 +24,7 @@ export function addUser(user: IUser): IAction { export function removeUser(user: IUser): IAction { return { - type: types.DEEP_LINKING, + type: types.SELECTED_USERS.REMOVE_USER, user }; } From ff0925cc9650b9749399747ad02b5b4c497e3dec Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Wed, 22 Dec 2021 09:38:11 -0300 Subject: [PATCH 12/21] chore: move types to definition folder and fix imports --- app/actions/selectedUsers.ts | 2 +- app/{types => definitions}/index.ts | 0 app/{types => definitions}/redux/index.ts | 0 app/reducers/activeUsers.ts | 2 +- app/reducers/selectedUsers.ts | 2 +- app/views/SelectedUsersView.tsx | 2 +- 6 files changed, 4 insertions(+), 4 deletions(-) rename app/{types => definitions}/index.ts (100%) rename app/{types => definitions}/redux/index.ts (100%) diff --git a/app/actions/selectedUsers.ts b/app/actions/selectedUsers.ts index cfb09d5855f..369808d0f8c 100644 --- a/app/actions/selectedUsers.ts +++ b/app/actions/selectedUsers.ts @@ -1,6 +1,6 @@ import { Action } from 'redux'; -import { IUser } from '../types'; +import { IUser } from '../definitions'; import * as types from './actionsTypes'; type User = { diff --git a/app/types/index.ts b/app/definitions/index.ts similarity index 100% rename from app/types/index.ts rename to app/definitions/index.ts diff --git a/app/types/redux/index.ts b/app/definitions/redux/index.ts similarity index 100% rename from app/types/redux/index.ts rename to app/definitions/redux/index.ts diff --git a/app/reducers/activeUsers.ts b/app/reducers/activeUsers.ts index 47d8cd2cd90..e37df651d3b 100644 --- a/app/reducers/activeUsers.ts +++ b/app/reducers/activeUsers.ts @@ -1,4 +1,4 @@ -import { ActiveUser, ApplicationActions } from '../types'; +import { ActiveUser, ApplicationActions } from '../definitions'; import { SET_ACTIVE_USERS } from '../actions/actionsTypes'; export interface IActiveUsers { diff --git a/app/reducers/selectedUsers.ts b/app/reducers/selectedUsers.ts index bbc7bc99624..2659649481b 100644 --- a/app/reducers/selectedUsers.ts +++ b/app/reducers/selectedUsers.ts @@ -1,4 +1,4 @@ -import { IUser, ApplicationActions } from '../types'; +import { IUser, ApplicationActions } from '../definitions'; import { SELECTED_USERS } from '../actions/actionsTypes'; export interface ISelectedUsers { diff --git a/app/views/SelectedUsersView.tsx b/app/views/SelectedUsersView.tsx index e6c1b19aa98..b22a2464944 100644 --- a/app/views/SelectedUsersView.tsx +++ b/app/views/SelectedUsersView.tsx @@ -21,7 +21,7 @@ import UserItem from '../presentation/UserItem'; import { getUserSelector } from '../selectors/login'; import { ChatsStackParamList } from '../stacks/types'; import { withTheme } from '../theme'; -import { ApplicationState, BaseScreen, IUser } from '../types'; +import { ApplicationState, BaseScreen, IUser } from '../definitions'; import { showErrorAlert } from '../utils/info'; import log, { events, logEvent } from '../utils/log'; import sharedStyles from './Styles'; From ef0d2bf195ce1abbffd07cf6bdc9da03c3708d3d Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Wed, 22 Dec 2021 09:58:13 -0300 Subject: [PATCH 13/21] chore: remove unused const --- __tests__/redux/selectedUsers.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/__tests__/redux/selectedUsers.test.ts b/__tests__/redux/selectedUsers.test.ts index 189ff504c07..b20c48733d7 100644 --- a/__tests__/redux/selectedUsers.test.ts +++ b/__tests__/redux/selectedUsers.test.ts @@ -33,7 +33,6 @@ describe('test selectedUsers reducer', () => { }); it('should return loading after call action', async () => { - const user = { _id: 'user.id', name: 'user.username', fname: 'user.name' }; mockedStore.dispatch(setLoading(true)); const state = mockedStore.getState().selectedUsers.loading; expect(state).toEqual(true); From d12b28b5f56776aedf6cc942e8de01be4a2377db Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Wed, 22 Dec 2021 16:27:19 -0300 Subject: [PATCH 14/21] chore: migrate redux tests to reducer folder and add eslint jest plugin --- .eslintrc.js | 5 +- .../reducers}/activeUsers.test.ts | 10 +-- {__mocks__ => app/reducers}/mockedStore.ts | 2 +- .../reducers}/selectedUsers.test.ts | 14 ++-- package.json | 1 + yarn.lock | 76 ++++++++++++++++++- 6 files changed, 91 insertions(+), 17 deletions(-) rename {__tests__/redux => app/reducers}/activeUsers.test.ts (54%) rename {__mocks__ => app/reducers}/mockedStore.ts (85%) rename {__tests__/redux => app/reducers}/selectedUsers.test.ts (66%) diff --git a/.eslintrc.js b/.eslintrc.js index 085f3a89d53..952621fbff2 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -17,14 +17,15 @@ module.exports = { legacyDecorators: true } }, - plugins: ['react', 'jsx-a11y', 'import', 'react-native', '@babel'], + plugins: ['react', 'jsx-a11y', 'import', 'react-native', '@babel', 'jest'], env: { browser: true, commonjs: true, es6: true, node: true, jquery: true, - mocha: true + mocha: true, + 'jest/globals': true }, rules: { 'import/extensions': [ diff --git a/__tests__/redux/activeUsers.test.ts b/app/reducers/activeUsers.test.ts similarity index 54% rename from __tests__/redux/activeUsers.test.ts rename to app/reducers/activeUsers.test.ts index e62f82471b2..379dcae4451 100644 --- a/__tests__/redux/activeUsers.test.ts +++ b/app/reducers/activeUsers.test.ts @@ -1,13 +1,13 @@ -import { setActiveUsers } from '../../app/actions/activeUsers'; -import { IActiveUsers } from '../../app/reducers/activeUsers'; -import { mockedStore } from '../../__mocks__/mockedStore'; +import { setActiveUsers } from '../actions/activeUsers'; +import { IActiveUsers } from './activeUsers'; +import { mockedStore } from './mockedStore'; describe('test reducer', () => { - it('should return {} as initial state', async () => { + it('should return {} as initial state', () => { const state = mockedStore.getState().activeUsers; expect(state).toEqual({}); }); - it('should return modified store after action', async () => { + it('should return modified store after action', () => { const activeUsers: IActiveUsers = { any: { status: 'online', statusText: 'any' } }; mockedStore.dispatch(setActiveUsers(activeUsers)); const state = mockedStore.getState().activeUsers; diff --git a/__mocks__/mockedStore.ts b/app/reducers/mockedStore.ts similarity index 85% rename from __mocks__/mockedStore.ts rename to app/reducers/mockedStore.ts index a29b7f62969..5a03297f291 100644 --- a/__mocks__/mockedStore.ts +++ b/app/reducers/mockedStore.ts @@ -1,7 +1,7 @@ import { applyMiddleware, compose, createStore } from 'redux'; import createSagaMiddleware from 'redux-saga'; -import reducers from '../app/reducers'; +import reducers from '.'; const enhancers = compose(applyMiddleware(createSagaMiddleware())); export const mockedStore = createStore(reducers, enhancers); diff --git a/__tests__/redux/selectedUsers.test.ts b/app/reducers/selectedUsers.test.ts similarity index 66% rename from __tests__/redux/selectedUsers.test.ts rename to app/reducers/selectedUsers.test.ts index b20c48733d7..b0f27903c47 100644 --- a/__tests__/redux/selectedUsers.test.ts +++ b/app/reducers/selectedUsers.test.ts @@ -1,5 +1,5 @@ -import { addUser, reset, setLoading, removeUser } from '../../app/actions/selectedUsers'; -import { mockedStore } from '../../__mocks__/mockedStore'; +import { addUser, reset, setLoading, removeUser } from '../actions/selectedUsers'; +import { mockedStore } from './mockedStore'; describe('test selectedUsers reducer', () => { const initialState = { @@ -7,32 +7,32 @@ describe('test selectedUsers reducer', () => { loading: false }; - it('should return initial state', async () => { + it('should return initial state', () => { const state = mockedStore.getState().selectedUsers; expect(state).toEqual(initialState); }); - it('should return modified store after addUser', async () => { + it('should return modified store after addUser', () => { const user = { _id: 'xxx', name: 'xxx', fname: 'xxx' }; mockedStore.dispatch(addUser(user)); const state = mockedStore.getState().selectedUsers.users; expect(state).toEqual([user]); }); - it('should return empty store after remove user', async () => { + it('should return empty store after remove user', () => { const user = { _id: 'xxx', name: 'xxx', fname: 'xxx' }; mockedStore.dispatch(removeUser(user)); const state = mockedStore.getState().selectedUsers.users; expect(state).toEqual([]); }); - it('should return initialState after reset', async () => { + it('should return initialState after reset', () => { mockedStore.dispatch(reset()); const state = mockedStore.getState().selectedUsers; expect(state).toEqual(initialState); }); - it('should return loading after call action', async () => { + it('should return loading after call action', () => { mockedStore.dispatch(setLoading(true)); const state = mockedStore.getState().selectedUsers.loading; expect(state).toEqual(true); diff --git a/package.json b/package.json index f807f61661a..716d48bbf7d 100644 --- a/package.json +++ b/package.json @@ -164,6 +164,7 @@ "eslint": "^7.31.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-import": "2.22.0", + "eslint-plugin-jest": "^25.3.0", "eslint-plugin-jsx-a11y": "6.3.1", "eslint-plugin-react": "7.20.3", "eslint-plugin-react-native": "3.8.1", diff --git a/yarn.lock b/yarn.lock index b4ca2beb5c6..3619b5e877f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4314,7 +4314,7 @@ resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.7.tgz#98a993516c859eb0d5c4c8f098317a9ea68db9ad" integrity sha512-cxWFQVseBm6O9Gbw1IWb8r6OS4OhSt3hPZLkFApLjM8TEXROBuQGLAH2i2gZpcXdLBIrpXuTDhH7Vbm1iXmNGA== -"@types/json-schema@^7.0.7": +"@types/json-schema@^7.0.7", "@types/json-schema@^7.0.9": version "7.0.9" resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.9.tgz#97edc9037ea0c38585320b28964dde3b39e4660d" integrity sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ== @@ -4593,6 +4593,18 @@ eslint-scope "^5.1.1" eslint-utils "^3.0.0" +"@typescript-eslint/experimental-utils@^5.0.0": + version "5.8.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-5.8.0.tgz#0916ffe98d34b3c95e3652efa0cace61a7b25728" + integrity sha512-KN5FvNH71bhZ8fKtL+lhW7bjm7cxs1nt+hrDZWIqb6ViCffQcWyLunGrgvISgkRojIDcXIsH+xlFfI4RCDA0xA== + dependencies: + "@types/json-schema" "^7.0.9" + "@typescript-eslint/scope-manager" "5.8.0" + "@typescript-eslint/types" "5.8.0" + "@typescript-eslint/typescript-estree" "5.8.0" + eslint-scope "^5.1.1" + eslint-utils "^3.0.0" + "@typescript-eslint/parser@^4.28.5": version "4.31.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.31.0.tgz#87b7cd16b24b9170c77595d8b1363f8047121e05" @@ -4611,11 +4623,24 @@ "@typescript-eslint/types" "4.31.0" "@typescript-eslint/visitor-keys" "4.31.0" +"@typescript-eslint/scope-manager@5.8.0": + version "5.8.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.8.0.tgz#2371095b4fa4c7be6a80b380f4e1b49c715e16f4" + integrity sha512-x82CYJsLOjPCDuFFEbS6e7K1QEWj7u5Wk1alw8A+gnJiYwNnDJk0ib6PCegbaPMjrfBvFKa7SxE3EOnnIQz2Gg== + dependencies: + "@typescript-eslint/types" "5.8.0" + "@typescript-eslint/visitor-keys" "5.8.0" + "@typescript-eslint/types@4.31.0": version "4.31.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.31.0.tgz#9a7c86fcc1620189567dc4e46cad7efa07ee8dce" integrity sha512-9XR5q9mk7DCXgXLS7REIVs+BaAswfdHhx91XqlJklmqWpTALGjygWVIb/UnLh4NWhfwhR5wNe1yTyCInxVhLqQ== +"@typescript-eslint/types@5.8.0": + version "5.8.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.8.0.tgz#e7fa74ec35d9dbe3560d039d3d8734986c3971e0" + integrity sha512-LdCYOqeqZWqCMOmwFnum6YfW9F3nKuxJiR84CdIRN5nfHJ7gyvGpXWqL/AaW0k3Po0+wm93ARAsOdzlZDPCcXg== + "@typescript-eslint/typescript-estree@4.31.0": version "4.31.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.31.0.tgz#4da4cb6274a7ef3b21d53f9e7147cc76f278a078" @@ -4629,6 +4654,19 @@ semver "^7.3.5" tsutils "^3.21.0" +"@typescript-eslint/typescript-estree@5.8.0": + version "5.8.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.8.0.tgz#900469ba9d5a37f4482b014ecce4a5dbb86cb4dd" + integrity sha512-srfeZ3URdEcUsSLbkOFqS7WoxOqn8JNil2NSLO9O+I2/Uyc85+UlfpEvQHIpj5dVts7KKOZnftoJD/Fdv0L7nQ== + dependencies: + "@typescript-eslint/types" "5.8.0" + "@typescript-eslint/visitor-keys" "5.8.0" + debug "^4.3.2" + globby "^11.0.4" + is-glob "^4.0.3" + semver "^7.3.5" + tsutils "^3.21.0" + "@typescript-eslint/visitor-keys@4.31.0": version "4.31.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.31.0.tgz#4e87b7761cb4e0e627dc2047021aa693fc76ea2b" @@ -4637,6 +4675,14 @@ "@typescript-eslint/types" "4.31.0" eslint-visitor-keys "^2.0.0" +"@typescript-eslint/visitor-keys@5.8.0": + version "5.8.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.8.0.tgz#22d4ed96fe2451135299239feedb9fe1dcec780c" + integrity sha512-+HDIGOEMnqbxdAHegxvnOqESUH6RWFRR2b8qxP1W9CZnnYh4Usz6MBL+2KMAgPk/P0o9c1HqnYtwzVH6GTIqug== + dependencies: + "@typescript-eslint/types" "5.8.0" + eslint-visitor-keys "^3.0.0" + "@ungap/promise-all-settled@1.1.2": version "1.1.2" resolved "https://registry.yarnpkg.com/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz#aa58042711d6e3275dd37dc597e5d31e8c290a44" @@ -7382,6 +7428,13 @@ debug@^4.3.1: dependencies: ms "2.1.2" +debug@^4.3.2: + version "4.3.3" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.3.tgz#04266e0b70a98d4462e6e288e38259213332b664" + integrity sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q== + dependencies: + ms "2.1.2" + decamelize@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290" @@ -8145,6 +8198,13 @@ eslint-plugin-import@^2.17.2: resolve "^1.20.0" tsconfig-paths "^3.11.0" +eslint-plugin-jest@^25.3.0: + version "25.3.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-25.3.0.tgz#6c04bbf13624a75684a05391a825b58e2e291950" + integrity sha512-79WQtuBsTN1S8Y9+7euBYwxIOia/k7ykkl9OCBHL3xuww5ecursHy/D8GCIlvzHVWv85gOkS5Kv6Sh7RxOgK1Q== + dependencies: + "@typescript-eslint/experimental-utils" "^5.0.0" + eslint-plugin-jsx-a11y@6.3.1: version "6.3.1" resolved "https://registry.yarnpkg.com/eslint-plugin-jsx-a11y/-/eslint-plugin-jsx-a11y-6.3.1.tgz#99ef7e97f567cc6a5b8dd5ab95a94a67058a2660" @@ -8241,6 +8301,11 @@ eslint-visitor-keys@^2.0.0, eslint-visitor-keys@^2.1.0: resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz#f65328259305927392c938ed44eb0a5c9b2bd303" integrity sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw== +eslint-visitor-keys@^3.0.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.1.0.tgz#eee4acea891814cda67a7d8812d9647dd0179af2" + integrity sha512-yWJFpu4DtjsWKkt5GeNBBuZMlNcYVs6vRCLoCVEJrTjaSB6LC98gFipNK/erM2Heg/E8mIK+hXG/pJMLK+eRZA== + eslint@^7.31.0: version "7.32.0" resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.32.0.tgz#c6d328a14be3fb08c8d1d21e12c02fdb7a2a812d" @@ -9443,7 +9508,7 @@ globby@8.0.2: pify "^3.0.0" slash "^1.0.0" -globby@^11.0.3: +globby@^11.0.3, globby@^11.0.4: version "11.0.4" resolved "https://registry.yarnpkg.com/globby/-/globby-11.0.4.tgz#2cbaff77c2f2a62e71e9b2813a67b97a3a3001a5" integrity sha512-9O4MVG9ioZJ08ffbcyVYyLOJLk5JQ688pJ4eMGLpdWLHq/Wr1D9BlriLQyL0E+jbkuePVZXYFj47QM/v093wHg== @@ -10264,6 +10329,13 @@ is-glob@^4.0.0, is-glob@^4.0.1, is-glob@~4.0.1: dependencies: is-extglob "^2.1.1" +is-glob@^4.0.3: + version "4.0.3" + resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.3.tgz#64f61e42cbbb2eec2071a9dac0b28ba1e65d5084" + integrity sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg== + dependencies: + is-extglob "^2.1.1" + is-hexadecimal@^1.0.0: version "1.0.4" resolved "https://registry.yarnpkg.com/is-hexadecimal/-/is-hexadecimal-1.0.4.tgz#cc35c97588da4bd49a8eedd6bc4082d44dcb23a7" From f0977ddb22161d1208937123e70e307dc4a10422 Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Wed, 22 Dec 2021 16:33:39 -0300 Subject: [PATCH 15/21] chore: exprot initial state and then import on tests --- app/reducers/activeUsers.test.ts | 6 +++--- app/reducers/activeUsers.ts | 2 +- app/reducers/selectedUsers.test.ts | 8 ++------ app/reducers/selectedUsers.ts | 2 +- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/app/reducers/activeUsers.test.ts b/app/reducers/activeUsers.test.ts index 379dcae4451..fbe35207a40 100644 --- a/app/reducers/activeUsers.test.ts +++ b/app/reducers/activeUsers.test.ts @@ -1,11 +1,11 @@ import { setActiveUsers } from '../actions/activeUsers'; -import { IActiveUsers } from './activeUsers'; +import { IActiveUsers, initialState } from './activeUsers'; import { mockedStore } from './mockedStore'; describe('test reducer', () => { - it('should return {} as initial state', () => { + it('should return initial state', () => { const state = mockedStore.getState().activeUsers; - expect(state).toEqual({}); + expect(state).toEqual(initialState); }); it('should return modified store after action', () => { const activeUsers: IActiveUsers = { any: { status: 'online', statusText: 'any' } }; diff --git a/app/reducers/activeUsers.ts b/app/reducers/activeUsers.ts index e37df651d3b..8e16fe25b43 100644 --- a/app/reducers/activeUsers.ts +++ b/app/reducers/activeUsers.ts @@ -5,7 +5,7 @@ export interface IActiveUsers { [key: string]: ActiveUser; } -const initialState: IActiveUsers = {}; +export const initialState: IActiveUsers = {}; export default function activeUsers(state = initialState, action: ApplicationActions): IActiveUsers { switch (action.type) { diff --git a/app/reducers/selectedUsers.test.ts b/app/reducers/selectedUsers.test.ts index b0f27903c47..329be4f916a 100644 --- a/app/reducers/selectedUsers.test.ts +++ b/app/reducers/selectedUsers.test.ts @@ -1,12 +1,8 @@ import { addUser, reset, setLoading, removeUser } from '../actions/selectedUsers'; import { mockedStore } from './mockedStore'; +import { initialState } from './selectedUsers'; describe('test selectedUsers reducer', () => { - const initialState = { - users: [], - loading: false - }; - it('should return initial state', () => { const state = mockedStore.getState().selectedUsers; expect(state).toEqual(initialState); @@ -26,7 +22,7 @@ describe('test selectedUsers reducer', () => { expect(state).toEqual([]); }); - it('should return initialState after reset', () => { + it('should return initial state after reset', () => { mockedStore.dispatch(reset()); const state = mockedStore.getState().selectedUsers; expect(state).toEqual(initialState); diff --git a/app/reducers/selectedUsers.ts b/app/reducers/selectedUsers.ts index 2659649481b..a31a01f1aa0 100644 --- a/app/reducers/selectedUsers.ts +++ b/app/reducers/selectedUsers.ts @@ -6,7 +6,7 @@ export interface ISelectedUsers { loading: boolean; } -const initialState: ISelectedUsers = { +export const initialState: ISelectedUsers = { users: [], loading: false }; From bad5643a4dd7c3abb707feaed29696385fba0607 Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Wed, 22 Dec 2021 16:40:29 -0300 Subject: [PATCH 16/21] chore: move interfaces to reducer and import on screen --- app/definitions/index.ts | 15 --------------- app/reducers/activeUsers.ts | 8 +++++++- app/reducers/selectedUsers.ts | 13 +++++++++++-- app/views/SelectedUsersView.tsx | 19 ++++++++++--------- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/app/definitions/index.ts b/app/definitions/index.ts index 6bb354fdfe7..ea8f9adb469 100644 --- a/app/definitions/index.ts +++ b/app/definitions/index.ts @@ -7,19 +7,4 @@ export interface BaseScreen { theme: string; } -export interface IUser { - _id: string; - name: string; - fname: string; - search?: boolean; - // username is used when is from searching - username?: string; -} - -type UserStatus = 'online' | 'offline'; -export interface ActiveUser { - status: UserStatus; - statusText?: string; -} - export * from './redux'; diff --git a/app/reducers/activeUsers.ts b/app/reducers/activeUsers.ts index 8e16fe25b43..6a63dfdf3c8 100644 --- a/app/reducers/activeUsers.ts +++ b/app/reducers/activeUsers.ts @@ -1,6 +1,12 @@ -import { ActiveUser, ApplicationActions } from '../definitions'; +import { ApplicationActions } from '../definitions'; import { SET_ACTIVE_USERS } from '../actions/actionsTypes'; +type UserStatus = 'online' | 'offline'; +export interface ActiveUser { + status: UserStatus; + statusText?: string; +} + export interface IActiveUsers { [key: string]: ActiveUser; } diff --git a/app/reducers/selectedUsers.ts b/app/reducers/selectedUsers.ts index a31a01f1aa0..e2be6b9a6ae 100644 --- a/app/reducers/selectedUsers.ts +++ b/app/reducers/selectedUsers.ts @@ -1,8 +1,17 @@ -import { IUser, ApplicationActions } from '../definitions'; +import { ApplicationActions } from '../definitions'; import { SELECTED_USERS } from '../actions/actionsTypes'; +export interface ISelectedUser { + _id: string; + name: string; + fname: string; + search?: boolean; + // username is used when is from searching + username?: string; +} + export interface ISelectedUsers { - users: IUser[]; + users: ISelectedUser[]; loading: boolean; } diff --git a/app/views/SelectedUsersView.tsx b/app/views/SelectedUsersView.tsx index b22a2464944..85b86afe40d 100644 --- a/app/views/SelectedUsersView.tsx +++ b/app/views/SelectedUsersView.tsx @@ -14,14 +14,15 @@ import Loading from '../containers/Loading'; import SafeAreaView from '../containers/SafeAreaView'; import SearchBox from '../containers/SearchBox'; import StatusBar from '../containers/StatusBar'; +import { ApplicationState, BaseScreen } from '../definitions'; import I18n from '../i18n'; import database from '../lib/database'; import RocketChat from '../lib/rocketchat'; import UserItem from '../presentation/UserItem'; +import { ISelectedUser } from '../reducers/selectedUsers'; import { getUserSelector } from '../selectors/login'; import { ChatsStackParamList } from '../stacks/types'; import { withTheme } from '../theme'; -import { ApplicationState, BaseScreen, IUser } from '../definitions'; import { showErrorAlert } from '../utils/info'; import log, { events, logEvent } from '../utils/log'; import sharedStyles from './Styles'; @@ -31,14 +32,14 @@ const getItemLayout = (_: any, index: number) => ({ length: ITEM_WIDTH, offset: interface ISelectedUsersViewState { maxUsers?: number; - search: IUser[]; - chats: IUser[]; + search: ISelectedUser[]; + chats: ISelectedUser[]; } interface ISelectedUsersViewProps extends BaseScreen { route: RouteProp; // REDUX STATE - users: IUser[]; + users: ISelectedUser[]; loading: boolean; user: { id: string; @@ -146,7 +147,7 @@ class SelectedUsersView extends React.Component el.name === username) !== -1; }; - toggleUser = (user: IUser) => { + toggleUser = (user: ISelectedUser) => { const { maxUsers } = this.state; const { dispatch, @@ -171,7 +172,7 @@ class SelectedUsersView extends React.Component { + _onPressItem = (id: string, item = {} as ISelectedUser) => { if (item.search) { this.toggleUser({ _id: item._id, name: item.username!, fname: item.name }); } else { @@ -179,7 +180,7 @@ class SelectedUsersView extends React.Component this.toggleUser(item); + _onPressSelectedItem = (item: ISelectedUser) => this.toggleUser(item); renderHeader = () => { const { theme } = this.props; @@ -218,7 +219,7 @@ class SelectedUsersView extends React.Component { + renderSelectedItem = ({ item }: { item: ISelectedUser }) => { const { theme } = this.props; return ( { + renderItem = ({ item, index }: { item: ISelectedUser; index: number }) => { const { search, chats } = this.state; const { theme } = this.props; From 928fac17def7022a4a7d8274865450c3b49ebc9c Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Thu, 23 Dec 2021 10:14:43 -0300 Subject: [PATCH 17/21] chore: set eslint-plugin-jest version to 24.7.0 --- package.json | 2 +- yarn.lock | 99 +++++++++++++++++++++------------------------------- 2 files changed, 41 insertions(+), 60 deletions(-) diff --git a/package.json b/package.json index 716d48bbf7d..a0fd6d506d8 100644 --- a/package.json +++ b/package.json @@ -164,7 +164,7 @@ "eslint": "^7.31.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-import": "2.22.0", - "eslint-plugin-jest": "^25.3.0", + "eslint-plugin-jest": "24.7.0", "eslint-plugin-jsx-a11y": "6.3.1", "eslint-plugin-react": "7.20.3", "eslint-plugin-react-native": "3.8.1", diff --git a/yarn.lock b/yarn.lock index 3619b5e877f..05a0d4385cc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4314,7 +4314,7 @@ resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.7.tgz#98a993516c859eb0d5c4c8f098317a9ea68db9ad" integrity sha512-cxWFQVseBm6O9Gbw1IWb8r6OS4OhSt3hPZLkFApLjM8TEXROBuQGLAH2i2gZpcXdLBIrpXuTDhH7Vbm1iXmNGA== -"@types/json-schema@^7.0.7", "@types/json-schema@^7.0.9": +"@types/json-schema@^7.0.7": version "7.0.9" resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.9.tgz#97edc9037ea0c38585320b28964dde3b39e4660d" integrity sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ== @@ -4593,15 +4593,15 @@ eslint-scope "^5.1.1" eslint-utils "^3.0.0" -"@typescript-eslint/experimental-utils@^5.0.0": - version "5.8.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-5.8.0.tgz#0916ffe98d34b3c95e3652efa0cace61a7b25728" - integrity sha512-KN5FvNH71bhZ8fKtL+lhW7bjm7cxs1nt+hrDZWIqb6ViCffQcWyLunGrgvISgkRojIDcXIsH+xlFfI4RCDA0xA== +"@typescript-eslint/experimental-utils@^4.0.1": + version "4.33.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-4.33.0.tgz#6f2a786a4209fa2222989e9380b5331b2810f7fd" + integrity sha512-zeQjOoES5JFjTnAhI5QY7ZviczMzDptls15GFsI6jyUOq0kOf9+WonkhtlIhh0RgHRnqj5gdNxW5j1EvAyYg6Q== dependencies: - "@types/json-schema" "^7.0.9" - "@typescript-eslint/scope-manager" "5.8.0" - "@typescript-eslint/types" "5.8.0" - "@typescript-eslint/typescript-estree" "5.8.0" + "@types/json-schema" "^7.0.7" + "@typescript-eslint/scope-manager" "4.33.0" + "@typescript-eslint/types" "4.33.0" + "@typescript-eslint/typescript-estree" "4.33.0" eslint-scope "^5.1.1" eslint-utils "^3.0.0" @@ -4623,23 +4623,23 @@ "@typescript-eslint/types" "4.31.0" "@typescript-eslint/visitor-keys" "4.31.0" -"@typescript-eslint/scope-manager@5.8.0": - version "5.8.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.8.0.tgz#2371095b4fa4c7be6a80b380f4e1b49c715e16f4" - integrity sha512-x82CYJsLOjPCDuFFEbS6e7K1QEWj7u5Wk1alw8A+gnJiYwNnDJk0ib6PCegbaPMjrfBvFKa7SxE3EOnnIQz2Gg== +"@typescript-eslint/scope-manager@4.33.0": + version "4.33.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.33.0.tgz#d38e49280d983e8772e29121cf8c6e9221f280a3" + integrity sha512-5IfJHpgTsTZuONKbODctL4kKuQje/bzBRkwHE8UOZ4f89Zeddg+EGZs8PD8NcN4LdM3ygHWYB3ukPAYjvl/qbQ== dependencies: - "@typescript-eslint/types" "5.8.0" - "@typescript-eslint/visitor-keys" "5.8.0" + "@typescript-eslint/types" "4.33.0" + "@typescript-eslint/visitor-keys" "4.33.0" "@typescript-eslint/types@4.31.0": version "4.31.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.31.0.tgz#9a7c86fcc1620189567dc4e46cad7efa07ee8dce" integrity sha512-9XR5q9mk7DCXgXLS7REIVs+BaAswfdHhx91XqlJklmqWpTALGjygWVIb/UnLh4NWhfwhR5wNe1yTyCInxVhLqQ== -"@typescript-eslint/types@5.8.0": - version "5.8.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.8.0.tgz#e7fa74ec35d9dbe3560d039d3d8734986c3971e0" - integrity sha512-LdCYOqeqZWqCMOmwFnum6YfW9F3nKuxJiR84CdIRN5nfHJ7gyvGpXWqL/AaW0k3Po0+wm93ARAsOdzlZDPCcXg== +"@typescript-eslint/types@4.33.0": + version "4.33.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.33.0.tgz#a1e59036a3b53ae8430ceebf2a919dc7f9af6d72" + integrity sha512-zKp7CjQzLQImXEpLt2BUw1tvOMPfNoTAfb8l51evhYbOEEzdWyQNmHWWGPR6hwKJDAi+1VXSBmnhL9kyVTTOuQ== "@typescript-eslint/typescript-estree@4.31.0": version "4.31.0" @@ -4654,16 +4654,16 @@ semver "^7.3.5" tsutils "^3.21.0" -"@typescript-eslint/typescript-estree@5.8.0": - version "5.8.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.8.0.tgz#900469ba9d5a37f4482b014ecce4a5dbb86cb4dd" - integrity sha512-srfeZ3URdEcUsSLbkOFqS7WoxOqn8JNil2NSLO9O+I2/Uyc85+UlfpEvQHIpj5dVts7KKOZnftoJD/Fdv0L7nQ== +"@typescript-eslint/typescript-estree@4.33.0": + version "4.33.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.33.0.tgz#0dfb51c2908f68c5c08d82aefeaf166a17c24609" + integrity sha512-rkWRY1MPFzjwnEVHsxGemDzqqddw2QbTJlICPD9p9I9LfsO8fdmfQPOX3uKfUaGRDFJbfrtm/sXhVXN4E+bzCA== dependencies: - "@typescript-eslint/types" "5.8.0" - "@typescript-eslint/visitor-keys" "5.8.0" - debug "^4.3.2" - globby "^11.0.4" - is-glob "^4.0.3" + "@typescript-eslint/types" "4.33.0" + "@typescript-eslint/visitor-keys" "4.33.0" + debug "^4.3.1" + globby "^11.0.3" + is-glob "^4.0.1" semver "^7.3.5" tsutils "^3.21.0" @@ -4675,13 +4675,13 @@ "@typescript-eslint/types" "4.31.0" eslint-visitor-keys "^2.0.0" -"@typescript-eslint/visitor-keys@5.8.0": - version "5.8.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.8.0.tgz#22d4ed96fe2451135299239feedb9fe1dcec780c" - integrity sha512-+HDIGOEMnqbxdAHegxvnOqESUH6RWFRR2b8qxP1W9CZnnYh4Usz6MBL+2KMAgPk/P0o9c1HqnYtwzVH6GTIqug== +"@typescript-eslint/visitor-keys@4.33.0": + version "4.33.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.33.0.tgz#2a22f77a41604289b7a186586e9ec48ca92ef1dd" + integrity sha512-uqi/2aSz9g2ftcHWf8uLPJA70rUv6yuMW5Bohw+bwcuzaxQIHaKFZCKGoGXIrc9vkTJ3+0txM73K0Hq3d5wgIg== dependencies: - "@typescript-eslint/types" "5.8.0" - eslint-visitor-keys "^3.0.0" + "@typescript-eslint/types" "4.33.0" + eslint-visitor-keys "^2.0.0" "@ungap/promise-all-settled@1.1.2": version "1.1.2" @@ -7428,13 +7428,6 @@ debug@^4.3.1: dependencies: ms "2.1.2" -debug@^4.3.2: - version "4.3.3" - resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.3.tgz#04266e0b70a98d4462e6e288e38259213332b664" - integrity sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q== - dependencies: - ms "2.1.2" - decamelize@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290" @@ -8198,12 +8191,12 @@ eslint-plugin-import@^2.17.2: resolve "^1.20.0" tsconfig-paths "^3.11.0" -eslint-plugin-jest@^25.3.0: - version "25.3.0" - resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-25.3.0.tgz#6c04bbf13624a75684a05391a825b58e2e291950" - integrity sha512-79WQtuBsTN1S8Y9+7euBYwxIOia/k7ykkl9OCBHL3xuww5ecursHy/D8GCIlvzHVWv85gOkS5Kv6Sh7RxOgK1Q== +eslint-plugin-jest@24.7.0: + version "24.7.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-24.7.0.tgz#206ac0833841e59e375170b15f8d0955219c4889" + integrity sha512-wUxdF2bAZiYSKBclsUMrYHH6WxiBreNjyDxbRv345TIvPeoCEgPNEn3Sa+ZrSqsf1Dl9SqqSREXMHExlMMu1DA== dependencies: - "@typescript-eslint/experimental-utils" "^5.0.0" + "@typescript-eslint/experimental-utils" "^4.0.1" eslint-plugin-jsx-a11y@6.3.1: version "6.3.1" @@ -8301,11 +8294,6 @@ eslint-visitor-keys@^2.0.0, eslint-visitor-keys@^2.1.0: resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz#f65328259305927392c938ed44eb0a5c9b2bd303" integrity sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw== -eslint-visitor-keys@^3.0.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.1.0.tgz#eee4acea891814cda67a7d8812d9647dd0179af2" - integrity sha512-yWJFpu4DtjsWKkt5GeNBBuZMlNcYVs6vRCLoCVEJrTjaSB6LC98gFipNK/erM2Heg/E8mIK+hXG/pJMLK+eRZA== - eslint@^7.31.0: version "7.32.0" resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.32.0.tgz#c6d328a14be3fb08c8d1d21e12c02fdb7a2a812d" @@ -9508,7 +9496,7 @@ globby@8.0.2: pify "^3.0.0" slash "^1.0.0" -globby@^11.0.3, globby@^11.0.4: +globby@^11.0.3: version "11.0.4" resolved "https://registry.yarnpkg.com/globby/-/globby-11.0.4.tgz#2cbaff77c2f2a62e71e9b2813a67b97a3a3001a5" integrity sha512-9O4MVG9ioZJ08ffbcyVYyLOJLk5JQ688pJ4eMGLpdWLHq/Wr1D9BlriLQyL0E+jbkuePVZXYFj47QM/v093wHg== @@ -10329,13 +10317,6 @@ is-glob@^4.0.0, is-glob@^4.0.1, is-glob@~4.0.1: dependencies: is-extglob "^2.1.1" -is-glob@^4.0.3: - version "4.0.3" - resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.3.tgz#64f61e42cbbb2eec2071a9dac0b28ba1e65d5084" - integrity sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg== - dependencies: - is-extglob "^2.1.1" - is-hexadecimal@^1.0.0: version "1.0.4" resolved "https://registry.yarnpkg.com/is-hexadecimal/-/is-hexadecimal-1.0.4.tgz#cc35c97588da4bd49a8eedd6bc4082d44dcb23a7" From c471195d8c26065326f1d12bcbcb4d2d0d9e5b51 Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Thu, 23 Dec 2021 10:20:38 -0300 Subject: [PATCH 18/21] chore: fix IUser import --- app/actions/selectedUsers.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/actions/selectedUsers.ts b/app/actions/selectedUsers.ts index 369808d0f8c..69ca5834f4d 100644 --- a/app/actions/selectedUsers.ts +++ b/app/actions/selectedUsers.ts @@ -1,10 +1,10 @@ import { Action } from 'redux'; -import { IUser } from '../definitions'; +import { ISelectedUser } from '../reducers/selectedUsers'; import * as types from './actionsTypes'; type User = { - user: IUser; + user: ISelectedUser; }; type IAction = Action & User; @@ -15,14 +15,14 @@ interface SetLoading extends Action { export type IActionSelectedUsers = IAction & SetLoading; -export function addUser(user: IUser): IAction { +export function addUser(user: ISelectedUser): IAction { return { type: types.SELECTED_USERS.ADD_USER, user }; } -export function removeUser(user: IUser): IAction { +export function removeUser(user: ISelectedUser): IAction { return { type: types.SELECTED_USERS.REMOVE_USER, user From 48e4640bee1d72aa1a9a1aca6779fb1d2d3053f3 Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Wed, 29 Dec 2021 10:33:41 -0300 Subject: [PATCH 19/21] chore: update interfaces and types names --- app/actions/activeUsers.ts | 6 +++--- app/actions/selectedUsers.ts | 10 +++++----- app/definitions/redux/index.ts | 6 +++--- app/reducers/activeUsers.ts | 8 ++++---- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/app/actions/activeUsers.ts b/app/actions/activeUsers.ts index 1ba58c7982e..737ae86b37b 100644 --- a/app/actions/activeUsers.ts +++ b/app/actions/activeUsers.ts @@ -3,13 +3,13 @@ import { Action } from 'redux'; import { IActiveUsers } from '../reducers/activeUsers'; import { SET_ACTIVE_USERS } from './actionsTypes'; -export interface SetActiveUsers extends Action { +export interface ISetActiveUsers extends Action { activeUsers: IActiveUsers; } -export type IActionActiveUsers = SetActiveUsers; +export type TActionActiveUsers = ISetActiveUsers; -export const setActiveUsers = (activeUsers: IActiveUsers): SetActiveUsers => ({ +export const setActiveUsers = (activeUsers: IActiveUsers): ISetActiveUsers => ({ type: SET_ACTIVE_USERS, activeUsers }); diff --git a/app/actions/selectedUsers.ts b/app/actions/selectedUsers.ts index 69ca5834f4d..607b3cebc12 100644 --- a/app/actions/selectedUsers.ts +++ b/app/actions/selectedUsers.ts @@ -3,17 +3,17 @@ import { Action } from 'redux'; import { ISelectedUser } from '../reducers/selectedUsers'; import * as types from './actionsTypes'; -type User = { +type TUser = { user: ISelectedUser; }; -type IAction = Action & User; +type IAction = Action & TUser; -interface SetLoading extends Action { +interface ISetLoading extends Action { loading: boolean; } -export type IActionSelectedUsers = IAction & SetLoading; +export type TActionSelectedUsers = IAction & ISetLoading; export function addUser(user: ISelectedUser): IAction { return { @@ -35,7 +35,7 @@ export function reset(): Action { }; } -export function setLoading(loading: boolean): SetLoading { +export function setLoading(loading: boolean): ISetLoading { return { type: types.SELECTED_USERS.SET_LOADING, loading diff --git a/app/definitions/redux/index.ts b/app/definitions/redux/index.ts index fe61c50a515..e80221c8c03 100644 --- a/app/definitions/redux/index.ts +++ b/app/definitions/redux/index.ts @@ -1,5 +1,5 @@ -import { IActionSelectedUsers } from '../../actions/selectedUsers'; -import { IActionActiveUsers } from '../../actions/activeUsers'; +import { TActionSelectedUsers } from '../../actions/selectedUsers'; +import { TActionActiveUsers } from '../../actions/activeUsers'; // REDUCERS import { IActiveUsers } from '../../reducers/activeUsers'; import { ISelectedUsers } from '../../reducers/selectedUsers'; @@ -28,4 +28,4 @@ export interface ApplicationState { roles: any; } -export type ApplicationActions = IActionActiveUsers & IActionSelectedUsers; +export type ApplicationActions = TActionActiveUsers & TActionSelectedUsers; diff --git a/app/reducers/activeUsers.ts b/app/reducers/activeUsers.ts index 6a63dfdf3c8..cd189fb6727 100644 --- a/app/reducers/activeUsers.ts +++ b/app/reducers/activeUsers.ts @@ -1,14 +1,14 @@ import { ApplicationActions } from '../definitions'; import { SET_ACTIVE_USERS } from '../actions/actionsTypes'; -type UserStatus = 'online' | 'offline'; -export interface ActiveUser { - status: UserStatus; +type TUserStatus = 'online' | 'offline'; +export interface IActiveUser { + status: TUserStatus; statusText?: string; } export interface IActiveUsers { - [key: string]: ActiveUser; + [key: string]: IActiveUser; } export const initialState: IActiveUsers = {}; From 0cf9765f86a4e733939c94599d515f64e6ae7299 Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Wed, 29 Dec 2021 13:19:48 -0300 Subject: [PATCH 20/21] chore: update definitions --- app/actions/selectedUsers.ts | 8 ++++---- app/definitions/index.ts | 4 ++-- app/definitions/redux/index.ts | 4 ++-- app/reducers/activeUsers.ts | 4 ++-- app/reducers/selectedUsers.ts | 4 ++-- app/views/SelectedUsersView.tsx | 6 +++--- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/app/actions/selectedUsers.ts b/app/actions/selectedUsers.ts index 607b3cebc12..6924a56964c 100644 --- a/app/actions/selectedUsers.ts +++ b/app/actions/selectedUsers.ts @@ -7,22 +7,22 @@ type TUser = { user: ISelectedUser; }; -type IAction = Action & TUser; +type TAction = Action & TUser; interface ISetLoading extends Action { loading: boolean; } -export type TActionSelectedUsers = IAction & ISetLoading; +export type TActionSelectedUsers = TAction & ISetLoading; -export function addUser(user: ISelectedUser): IAction { +export function addUser(user: ISelectedUser): TAction { return { type: types.SELECTED_USERS.ADD_USER, user }; } -export function removeUser(user: ISelectedUser): IAction { +export function removeUser(user: ISelectedUser): TAction { return { type: types.SELECTED_USERS.REMOVE_USER, user diff --git a/app/definitions/index.ts b/app/definitions/index.ts index ea8f9adb469..d8af539fdd2 100644 --- a/app/definitions/index.ts +++ b/app/definitions/index.ts @@ -1,8 +1,8 @@ import { StackNavigationProp } from '@react-navigation/stack'; import { Dispatch } from 'redux'; -export interface BaseScreen { - navigation: StackNavigationProp; +export interface IBaseScreen, S extends string> { + navigation: StackNavigationProp; dispatch: Dispatch; theme: string; } diff --git a/app/definitions/redux/index.ts b/app/definitions/redux/index.ts index e80221c8c03..e95763e29b3 100644 --- a/app/definitions/redux/index.ts +++ b/app/definitions/redux/index.ts @@ -4,7 +4,7 @@ import { TActionActiveUsers } from '../../actions/activeUsers'; import { IActiveUsers } from '../../reducers/activeUsers'; import { ISelectedUsers } from '../../reducers/selectedUsers'; -export interface ApplicationState { +export interface IApplicationState { settings: any; login: any; meteor: any; @@ -28,4 +28,4 @@ export interface ApplicationState { roles: any; } -export type ApplicationActions = TActionActiveUsers & TActionSelectedUsers; +export type TApplicationActions = TActionActiveUsers & TActionSelectedUsers; diff --git a/app/reducers/activeUsers.ts b/app/reducers/activeUsers.ts index cd189fb6727..9877a5cebb5 100644 --- a/app/reducers/activeUsers.ts +++ b/app/reducers/activeUsers.ts @@ -1,4 +1,4 @@ -import { ApplicationActions } from '../definitions'; +import { TApplicationActions } from '../definitions'; import { SET_ACTIVE_USERS } from '../actions/actionsTypes'; type TUserStatus = 'online' | 'offline'; @@ -13,7 +13,7 @@ export interface IActiveUsers { export const initialState: IActiveUsers = {}; -export default function activeUsers(state = initialState, action: ApplicationActions): IActiveUsers { +export default function activeUsers(state = initialState, action: TApplicationActions): IActiveUsers { switch (action.type) { case SET_ACTIVE_USERS: return { diff --git a/app/reducers/selectedUsers.ts b/app/reducers/selectedUsers.ts index e2be6b9a6ae..f6573ac9ec8 100644 --- a/app/reducers/selectedUsers.ts +++ b/app/reducers/selectedUsers.ts @@ -1,4 +1,4 @@ -import { ApplicationActions } from '../definitions'; +import { TApplicationActions } from '../definitions'; import { SELECTED_USERS } from '../actions/actionsTypes'; export interface ISelectedUser { @@ -20,7 +20,7 @@ export const initialState: ISelectedUsers = { loading: false }; -export default function (state = initialState, action: ApplicationActions): ISelectedUsers { +export default function (state = initialState, action: TApplicationActions): ISelectedUsers { switch (action.type) { case SELECTED_USERS.ADD_USER: return { diff --git a/app/views/SelectedUsersView.tsx b/app/views/SelectedUsersView.tsx index 85b86afe40d..8962555f39a 100644 --- a/app/views/SelectedUsersView.tsx +++ b/app/views/SelectedUsersView.tsx @@ -14,7 +14,7 @@ import Loading from '../containers/Loading'; import SafeAreaView from '../containers/SafeAreaView'; import SearchBox from '../containers/SearchBox'; import StatusBar from '../containers/StatusBar'; -import { ApplicationState, BaseScreen } from '../definitions'; +import { IApplicationState, IBaseScreen } from '../definitions'; import I18n from '../i18n'; import database from '../lib/database'; import RocketChat from '../lib/rocketchat'; @@ -36,7 +36,7 @@ interface ISelectedUsersViewState { chats: ISelectedUser[]; } -interface ISelectedUsersViewProps extends BaseScreen { +interface ISelectedUsersViewProps extends IBaseScreen { route: RouteProp; // REDUX STATE users: ISelectedUser[]; @@ -296,7 +296,7 @@ class SelectedUsersView extends React.Component ({ +const mapStateToProps = (state: IApplicationState) => ({ baseUrl: state.server.server, users: state.selectedUsers.users, loading: state.selectedUsers.loading, From bc92a4f29ded142dc42c1a4b2dd26e9601ba0826 Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Wed, 29 Dec 2021 18:44:04 -0300 Subject: [PATCH 21/21] chore: update IBaseScreen definitions --- app/definitions/index.ts | 2 ++ app/views/SelectedUsersView.tsx | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/definitions/index.ts b/app/definitions/index.ts index d8af539fdd2..f9ca20d4a8a 100644 --- a/app/definitions/index.ts +++ b/app/definitions/index.ts @@ -1,8 +1,10 @@ +import { RouteProp } from '@react-navigation/native'; import { StackNavigationProp } from '@react-navigation/stack'; import { Dispatch } from 'redux'; export interface IBaseScreen, S extends string> { navigation: StackNavigationProp; + route: RouteProp; dispatch: Dispatch; theme: string; } diff --git a/app/views/SelectedUsersView.tsx b/app/views/SelectedUsersView.tsx index 8962555f39a..85311154eee 100644 --- a/app/views/SelectedUsersView.tsx +++ b/app/views/SelectedUsersView.tsx @@ -1,5 +1,4 @@ import { Q } from '@nozbe/watermelondb'; -import { RouteProp } from '@react-navigation/native'; import orderBy from 'lodash/orderBy'; import React from 'react'; import { FlatList, View } from 'react-native'; @@ -36,8 +35,7 @@ interface ISelectedUsersViewState { chats: ISelectedUser[]; } -interface ISelectedUsersViewProps extends IBaseScreen { - route: RouteProp; +interface ISelectedUsersViewProps extends IBaseScreen { // REDUX STATE users: ISelectedUser[]; loading: boolean;