Merge pull request #3611 from RocketChat/chore/migration-ts-redux-users-typing

Chore: Migrate redux module usersTyping to Typescript
This commit is contained in:
Gleidson Daniel Silva 2022-01-26 13:52:08 -03:00 committed by GitHub
commit 48abf24b72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 73 additions and 29 deletions

View File

@ -1,21 +0,0 @@
import { USERS_TYPING } from './actionsTypes';
export function addUserTyping(username) {
return {
type: USERS_TYPING.ADD,
username
};
}
export function removeUserTyping(username) {
return {
type: USERS_TYPING.REMOVE,
username
};
}
export function clearUserTyping() {
return {
type: USERS_TYPING.CLEAR
};
}

View File

@ -0,0 +1,29 @@
import { Action } from 'redux';
import { USERS_TYPING } from './actionsTypes';
export interface IUsersTypingGenericAction extends Action {
username: string;
}
export type TActionUserTyping = IUsersTypingGenericAction & Action;
export function addUserTyping(username: string): IUsersTypingGenericAction {
return {
type: USERS_TYPING.ADD,
username
};
}
export function removeUserTyping(username: string): IUsersTypingGenericAction {
return {
type: USERS_TYPING.REMOVE,
username
};
}
export function clearUserTyping(): Action {
return {
type: USERS_TYPING.CLEAR
};
}

View File

@ -1,10 +1,11 @@
import { dequal } from 'dequal';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { dequal } from 'dequal';
import RoomHeader from './RoomHeader';
import { IApplicationState } from '../../definitions';
import { withDimensions } from '../../dimensions';
import I18n from '../../i18n';
import RoomHeader from './RoomHeader';
interface IRoomHeaderContainerProps {
title: string;
@ -122,8 +123,8 @@ class RoomHeaderContainer extends Component<IRoomHeaderContainerProps, any> {
}
}
const mapStateToProps = (state: any, ownProps: any) => {
let statusText;
const mapStateToProps = (state: IApplicationState, ownProps: any) => {
let statusText = '';
let status = 'offline';
const { roomUserId, type, visitor = {}, tmid } = ownProps;

View File

@ -6,6 +6,7 @@ import { IActionRoles } from '../../actions/roles';
import { TActionSelectedUsers } from '../../actions/selectedUsers';
import { IActionSettings } from '../../actions/settings';
import { TActionSortPreferences } from '../../actions/sortPreferences';
import { TActionUserTyping } from '../../actions/usersTyping';
// REDUCERS
import { IActiveUsers } from '../../reducers/activeUsers';
import { IEncryption } from '../../reducers/encryption';
@ -45,4 +46,5 @@ export type TApplicationActions = TActionActiveUsers &
IActionRoles &
IActionSettings &
TActionEncryption &
TActionSortPreferences;
TActionSortPreferences &
TActionUserTyping;

View File

@ -4,7 +4,7 @@ import { SET_ACTIVE_USERS } from '../actions/actionsTypes';
type TUserStatus = 'online' | 'offline';
export interface IActiveUser {
status: TUserStatus;
statusText?: string;
statusText: string;
}
export interface IActiveUsers {

View File

@ -0,0 +1,30 @@
import { addUserTyping, removeUserTyping, clearUserTyping } from '../actions/usersTyping';
import { mockedStore } from './mockedStore';
import { initialState } from './usersTyping';
describe('test usersTyping reducer', () => {
it('should return initial state', () => {
const state = mockedStore.getState().usersTyping;
expect(state).toEqual(initialState);
});
it('should return modified store after addUserTyping', () => {
mockedStore.dispatch(addUserTyping('diego'));
mockedStore.dispatch(addUserTyping('carlos'));
mockedStore.dispatch(addUserTyping('maria'));
const state = mockedStore.getState().usersTyping;
expect(state).toEqual(['diego', 'carlos', 'maria']);
});
it('should return modified store after removeUserTyping', () => {
mockedStore.dispatch(removeUserTyping('diego'));
const state = mockedStore.getState().usersTyping;
expect(state).toEqual(['carlos', 'maria']);
});
it('should return initial state after reset', () => {
mockedStore.dispatch(clearUserTyping());
const state = mockedStore.getState().usersTyping;
expect(state).toEqual(initialState);
});
});

View File

@ -1,8 +1,11 @@
import { USERS_TYPING } from '../actions/actionsTypes';
import { TApplicationActions } from '../definitions';
const initialState = [];
export type IUsersTyping = string[];
export default function usersTyping(state = initialState, action) {
export const initialState: IUsersTyping = [];
export default function usersTyping(state = initialState, action: TApplicationActions): IUsersTyping {
switch (action.type) {
case USERS_TYPING.ADD:
if (state.findIndex(item => item === action.username) === -1) {