Chore: Evaluate CreateDiscussionView - TypeScript (#4133)
This commit is contained in:
parent
d99b31849a
commit
cb1dabbc16
|
@ -2,8 +2,16 @@ import { Action } from 'redux';
|
||||||
|
|
||||||
import { CREATE_DISCUSSION } from './actionsTypes';
|
import { CREATE_DISCUSSION } from './actionsTypes';
|
||||||
|
|
||||||
|
export interface ICreateDiscussionRequestData {
|
||||||
|
prid: string;
|
||||||
|
pmid?: string;
|
||||||
|
t_name?: string;
|
||||||
|
reply?: string;
|
||||||
|
users: string[];
|
||||||
|
encrypted?: boolean;
|
||||||
|
}
|
||||||
interface ICreateDiscussionRequest extends Action {
|
interface ICreateDiscussionRequest extends Action {
|
||||||
data: any;
|
data: ICreateDiscussionRequestData;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ICreateDiscussionSuccess extends Action {
|
interface ICreateDiscussionSuccess extends Action {
|
||||||
|
|
|
@ -6,7 +6,7 @@ export interface ISearchLocal {
|
||||||
name: string;
|
name: string;
|
||||||
t: string;
|
t: string;
|
||||||
fname: string;
|
fname: string;
|
||||||
encrypted: boolean | null;
|
encrypted: boolean;
|
||||||
lastMessage?: ILastMessage;
|
lastMessage?: ILastMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ const SelectChannel = ({
|
||||||
blockUnauthenticatedAccess,
|
blockUnauthenticatedAccess,
|
||||||
serverVersion,
|
serverVersion,
|
||||||
theme
|
theme
|
||||||
}: ICreateDiscussionViewSelectChannel): JSX.Element => {
|
}: ICreateDiscussionViewSelectChannel): React.ReactElement => {
|
||||||
const [channels, setChannels] = useState<ISearchLocal[]>([]);
|
const [channels, setChannels] = useState<ISearchLocal[]>([]);
|
||||||
|
|
||||||
const getChannels = debounce(async (keyword = '') => {
|
const getChannels = debounce(async (keyword = '') => {
|
||||||
|
@ -32,7 +32,7 @@ const SelectChannel = ({
|
||||||
}
|
}
|
||||||
}, 300);
|
}, 300);
|
||||||
|
|
||||||
const getAvatar = (item: any) =>
|
const getAvatar = (item: ISearchLocal) =>
|
||||||
avatarURL({
|
avatarURL({
|
||||||
text: getRoomAvatar(item),
|
text: getRoomAvatar(item),
|
||||||
type: item.t,
|
type: item.t,
|
||||||
|
|
|
@ -9,14 +9,9 @@ import { MultiSelect } from '../../containers/UIKit/MultiSelect';
|
||||||
import { themes } from '../../lib/constants';
|
import { themes } from '../../lib/constants';
|
||||||
import styles from './styles';
|
import styles from './styles';
|
||||||
import { ICreateDiscussionViewSelectUsers } from './interfaces';
|
import { ICreateDiscussionViewSelectUsers } from './interfaces';
|
||||||
import { SubscriptionType } from '../../definitions/ISubscription';
|
import { SubscriptionType, IUser } from '../../definitions';
|
||||||
import { getRoomAvatar, getRoomTitle, search } from '../../lib/methods';
|
import { getRoomAvatar, getRoomTitle, search } from '../../lib/methods';
|
||||||
|
|
||||||
interface IUser {
|
|
||||||
name: string;
|
|
||||||
username: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const SelectUsers = ({
|
const SelectUsers = ({
|
||||||
server,
|
server,
|
||||||
token,
|
token,
|
||||||
|
@ -26,7 +21,7 @@ const SelectUsers = ({
|
||||||
blockUnauthenticatedAccess,
|
blockUnauthenticatedAccess,
|
||||||
serverVersion,
|
serverVersion,
|
||||||
theme
|
theme
|
||||||
}: ICreateDiscussionViewSelectUsers): JSX.Element => {
|
}: ICreateDiscussionViewSelectUsers): React.ReactElement => {
|
||||||
const [users, setUsers] = useState<any[]>([]);
|
const [users, setUsers] = useState<any[]>([]);
|
||||||
|
|
||||||
const getUsers = debounce(async (keyword = '') => {
|
const getUsers = debounce(async (keyword = '') => {
|
||||||
|
@ -41,7 +36,7 @@ const SelectUsers = ({
|
||||||
}
|
}
|
||||||
}, 300);
|
}, 300);
|
||||||
|
|
||||||
const getAvatar = (item: any) =>
|
const getAvatar = (item: IUser) =>
|
||||||
avatarURL({
|
avatarURL({
|
||||||
text: getRoomAvatar(item),
|
text: getRoomAvatar(item),
|
||||||
type: SubscriptionType.DIRECT,
|
type: SubscriptionType.DIRECT,
|
||||||
|
|
|
@ -13,7 +13,7 @@ import { withTheme } from '../../theme';
|
||||||
import { getUserSelector } from '../../selectors/login';
|
import { getUserSelector } from '../../selectors/login';
|
||||||
import TextInput from '../../containers/TextInput';
|
import TextInput from '../../containers/TextInput';
|
||||||
import Navigation from '../../lib/navigation/appNavigation';
|
import Navigation from '../../lib/navigation/appNavigation';
|
||||||
import { createDiscussionRequest } from '../../actions/createDiscussion';
|
import { createDiscussionRequest, ICreateDiscussionRequestData } from '../../actions/createDiscussion';
|
||||||
import { showErrorAlert } from '../../utils/info';
|
import { showErrorAlert } from '../../utils/info';
|
||||||
import SafeAreaView from '../../containers/SafeAreaView';
|
import SafeAreaView from '../../containers/SafeAreaView';
|
||||||
import { goRoom } from '../../utils/goRoom';
|
import { goRoom } from '../../utils/goRoom';
|
||||||
|
@ -21,19 +21,19 @@ import { events, logEvent } from '../../utils/log';
|
||||||
import styles from './styles';
|
import styles from './styles';
|
||||||
import SelectUsers from './SelectUsers';
|
import SelectUsers from './SelectUsers';
|
||||||
import SelectChannel from './SelectChannel';
|
import SelectChannel from './SelectChannel';
|
||||||
import { ICreateChannelViewProps, IResult, IError } from './interfaces';
|
import { ICreateChannelViewProps, IResult, IError, ICreateChannelViewState } from './interfaces';
|
||||||
import { IApplicationState } from '../../definitions';
|
import { IApplicationState, ISearchLocal, ISubscription } from '../../definitions';
|
||||||
import { E2E_ROOM_TYPES, SWITCH_TRACK_COLOR, themes } from '../../lib/constants';
|
import { E2E_ROOM_TYPES, SWITCH_TRACK_COLOR, themes } from '../../lib/constants';
|
||||||
import { getRoomTitle } from '../../lib/methods';
|
import { getRoomTitle } from '../../lib/methods';
|
||||||
|
|
||||||
class CreateChannelView extends React.Component<ICreateChannelViewProps, any> {
|
class CreateChannelView extends React.Component<ICreateChannelViewProps, ICreateChannelViewState> {
|
||||||
private channel: any;
|
private channel: ISubscription;
|
||||||
|
|
||||||
constructor(props: ICreateChannelViewProps) {
|
constructor(props: ICreateChannelViewProps) {
|
||||||
super(props);
|
super(props);
|
||||||
const { route } = props;
|
const { route } = props;
|
||||||
this.channel = route.params?.channel;
|
this.channel = route.params?.channel;
|
||||||
const message: any = route.params?.message ?? {};
|
const message = route.params?.message ?? {};
|
||||||
this.state = {
|
this.state = {
|
||||||
channel: this.channel,
|
channel: this.channel,
|
||||||
message,
|
message,
|
||||||
|
@ -45,7 +45,7 @@ class CreateChannelView extends React.Component<ICreateChannelViewProps, any> {
|
||||||
this.setHeader();
|
this.setHeader();
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps: any, prevState: any) {
|
componentDidUpdate(prevProps: ICreateChannelViewProps, prevState: ICreateChannelViewState) {
|
||||||
const { channel, name } = this.state;
|
const { channel, name } = this.state;
|
||||||
const { loading, failure, error, result, isMasterDetail } = this.props;
|
const { loading, failure, error, result, isMasterDetail } = this.props;
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ class CreateChannelView extends React.Component<ICreateChannelViewProps, any> {
|
||||||
submit = () => {
|
submit = () => {
|
||||||
const {
|
const {
|
||||||
name: t_name,
|
name: t_name,
|
||||||
channel: { prid, rid },
|
channel,
|
||||||
message: { id: pmid },
|
message: { id: pmid },
|
||||||
reply,
|
reply,
|
||||||
users,
|
users,
|
||||||
|
@ -104,8 +104,8 @@ class CreateChannelView extends React.Component<ICreateChannelViewProps, any> {
|
||||||
} = this.state;
|
} = this.state;
|
||||||
const { dispatch } = this.props;
|
const { dispatch } = this.props;
|
||||||
|
|
||||||
const params: any = {
|
const params: ICreateDiscussionRequestData = {
|
||||||
prid: prid || rid,
|
prid: ('prid' in channel && channel.prid) || channel.rid,
|
||||||
pmid,
|
pmid,
|
||||||
t_name,
|
t_name,
|
||||||
reply,
|
reply,
|
||||||
|
@ -121,15 +121,15 @@ class CreateChannelView extends React.Component<ICreateChannelViewProps, any> {
|
||||||
valid = () => {
|
valid = () => {
|
||||||
const { channel, name } = this.state;
|
const { channel, name } = this.state;
|
||||||
|
|
||||||
return channel && channel.rid && channel.rid.trim().length && name.trim().length;
|
return channel && channel.rid && channel.rid.trim().length && name?.trim().length;
|
||||||
};
|
};
|
||||||
|
|
||||||
selectChannel = ({ value }: any) => {
|
selectChannel = ({ value }: { value: ISearchLocal }) => {
|
||||||
logEvent(events.CD_SELECT_CHANNEL);
|
logEvent(events.CD_SELECT_CHANNEL);
|
||||||
this.setState({ channel: value, encrypted: value?.encrypted });
|
this.setState({ channel: value, encrypted: value?.encrypted });
|
||||||
};
|
};
|
||||||
|
|
||||||
selectUsers = ({ value }: any) => {
|
selectUsers = ({ value }: { value: string[] }) => {
|
||||||
logEvent(events.CD_SELECT_USERS);
|
logEvent(events.CD_SELECT_USERS);
|
||||||
this.setState({ users: value });
|
this.setState({ users: value });
|
||||||
};
|
};
|
||||||
|
@ -140,7 +140,7 @@ class CreateChannelView extends React.Component<ICreateChannelViewProps, any> {
|
||||||
return encryptionEnabled && E2E_ROOM_TYPES[channel?.t];
|
return encryptionEnabled && E2E_ROOM_TYPES[channel?.t];
|
||||||
}
|
}
|
||||||
|
|
||||||
onEncryptedChange = (value: any) => {
|
onEncryptedChange = (value: boolean) => {
|
||||||
logEvent(events.CD_TOGGLE_ENCRY);
|
logEvent(events.CD_TOGGLE_ENCRY);
|
||||||
this.setState({ encrypted: value });
|
this.setState({ encrypted: value });
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { NewMessageStackParamList } from '../../stacks/types';
|
import { NewMessageStackParamList } from '../../stacks/types';
|
||||||
import { SubscriptionType } from '../../definitions/ISubscription';
|
import { ISubscription, SubscriptionType } from '../../definitions/ISubscription';
|
||||||
import { IBaseScreen } from '../../definitions';
|
import { IBaseScreen, IMessage, ISearchLocal, IUser } from '../../definitions';
|
||||||
import { TSupportedThemes } from '../../theme';
|
import { TSupportedThemes } from '../../theme';
|
||||||
|
|
||||||
export interface IResult {
|
export interface IResult {
|
||||||
|
@ -14,10 +14,7 @@ export interface IError {
|
||||||
}
|
}
|
||||||
export interface ICreateChannelViewProps extends IBaseScreen<NewMessageStackParamList, 'CreateDiscussionView'> {
|
export interface ICreateChannelViewProps extends IBaseScreen<NewMessageStackParamList, 'CreateDiscussionView'> {
|
||||||
server: string;
|
server: string;
|
||||||
user: {
|
user: IUser;
|
||||||
id: string;
|
|
||||||
token: string;
|
|
||||||
};
|
|
||||||
create: Function;
|
create: Function;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
result: IResult;
|
result: IResult;
|
||||||
|
@ -29,6 +26,15 @@ export interface ICreateChannelViewProps extends IBaseScreen<NewMessageStackPara
|
||||||
encryptionEnabled: boolean;
|
encryptionEnabled: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ICreateChannelViewState {
|
||||||
|
channel: ISubscription | ISearchLocal;
|
||||||
|
message: IMessage;
|
||||||
|
name?: string;
|
||||||
|
users: string[];
|
||||||
|
reply: string;
|
||||||
|
encrypted: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export interface ICreateDiscussionViewSelectChannel {
|
export interface ICreateDiscussionViewSelectChannel {
|
||||||
server: string;
|
server: string;
|
||||||
token: string;
|
token: string;
|
||||||
|
|
Loading…
Reference in New Issue