Chore: Clean ReactionsModal - TypeScript (#3926)
This commit is contained in:
parent
5bd060b7b2
commit
3b3cd67d78
|
@ -8,7 +8,7 @@ import I18n from '../i18n';
|
||||||
import { CustomIcon } from '../lib/Icons';
|
import { CustomIcon } from '../lib/Icons';
|
||||||
import sharedStyles from '../views/Styles';
|
import sharedStyles from '../views/Styles';
|
||||||
import { themes } from '../constants/colors';
|
import { themes } from '../constants/colors';
|
||||||
import { withTheme } from '../theme';
|
import { useTheme, withTheme } from '../theme';
|
||||||
import { TGetCustomEmoji } from '../definitions/IEmoji';
|
import { TGetCustomEmoji } from '../definitions/IEmoji';
|
||||||
import { TMessageModel, ILoggedUser } from '../definitions';
|
import { TMessageModel, ILoggedUser } from '../definitions';
|
||||||
import SafeAreaView from './SafeAreaView';
|
import SafeAreaView from './SafeAreaView';
|
||||||
|
@ -61,38 +61,37 @@ const styles = StyleSheet.create({
|
||||||
const standardEmojiStyle = { fontSize: 20 };
|
const standardEmojiStyle = { fontSize: 20 };
|
||||||
const customEmojiStyle = { width: 20, height: 20 };
|
const customEmojiStyle = { width: 20, height: 20 };
|
||||||
|
|
||||||
interface IItem {
|
interface ISharedFields {
|
||||||
item: {
|
|
||||||
usernames: any;
|
|
||||||
emoji: string;
|
|
||||||
};
|
|
||||||
user?: Pick<ILoggedUser, 'username'>;
|
user?: Pick<ILoggedUser, 'username'>;
|
||||||
baseUrl?: string;
|
baseUrl: string;
|
||||||
getCustomEmoji?: TGetCustomEmoji;
|
getCustomEmoji: TGetCustomEmoji;
|
||||||
theme?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IModalContent {
|
interface IItem extends ISharedFields {
|
||||||
|
item: {
|
||||||
|
usernames: string[];
|
||||||
|
emoji: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IModalContent extends ISharedFields {
|
||||||
message?: TMessageModel;
|
message?: TMessageModel;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
theme: string;
|
theme: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IReactionsModal {
|
interface IReactionsModal extends ISharedFields {
|
||||||
message?: any;
|
message?: TMessageModel;
|
||||||
user?: Pick<ILoggedUser, 'username'>;
|
|
||||||
isVisible: boolean;
|
isVisible: boolean;
|
||||||
onClose(): void;
|
onClose(): void;
|
||||||
baseUrl: string;
|
|
||||||
getCustomEmoji?: TGetCustomEmoji;
|
|
||||||
theme: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Item = React.memo(({ item, user, baseUrl, getCustomEmoji, theme }: IItem) => {
|
const Item = React.memo(({ item, user, baseUrl, getCustomEmoji }: IItem) => {
|
||||||
|
const { theme } = useTheme();
|
||||||
const count = item.usernames.length;
|
const count = item.usernames.length;
|
||||||
let usernames = item.usernames
|
let usernames = item.usernames
|
||||||
.slice(0, 3)
|
.slice(0, 3)
|
||||||
.map((username: any) => (username === user?.username ? I18n.t('you') : username))
|
.map((username: string) => (username === user?.username ? I18n.t('you') : username))
|
||||||
.join(', ');
|
.join(', ');
|
||||||
if (count > 3) {
|
if (count > 3) {
|
||||||
usernames = `${usernames} ${I18n.t('and_more')} ${count - 3}`;
|
usernames = `${usernames} ${I18n.t('and_more')} ${count - 3}`;
|
||||||
|
@ -106,15 +105,15 @@ const Item = React.memo(({ item, user, baseUrl, getCustomEmoji, theme }: IItem)
|
||||||
content={item.emoji}
|
content={item.emoji}
|
||||||
standardEmojiStyle={standardEmojiStyle}
|
standardEmojiStyle={standardEmojiStyle}
|
||||||
customEmojiStyle={customEmojiStyle}
|
customEmojiStyle={customEmojiStyle}
|
||||||
baseUrl={baseUrl!}
|
baseUrl={baseUrl}
|
||||||
getCustomEmoji={getCustomEmoji!}
|
getCustomEmoji={getCustomEmoji}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
<View style={styles.peopleItemContainer}>
|
<View style={styles.peopleItemContainer}>
|
||||||
<Text style={[styles.reactCount, { color: themes[theme!].buttonText }]}>
|
<Text style={[styles.reactCount, { color: themes[theme].buttonText }]}>
|
||||||
{count === 1 ? I18n.t('1_person_reacted') : I18n.t('N_people_reacted', { n: count })}
|
{count === 1 ? I18n.t('1_person_reacted') : I18n.t('N_people_reacted', { n: count })}
|
||||||
</Text>
|
</Text>
|
||||||
<Text style={[styles.peopleReacted, { color: themes[theme!].buttonText }]}>{usernames}</Text>
|
<Text style={[styles.peopleReacted, { color: themes[theme].buttonText }]}>{usernames}</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
@ -143,7 +142,9 @@ const ModalContent = React.memo(({ message, onClose, ...props }: IModalContent)
|
||||||
});
|
});
|
||||||
|
|
||||||
const ReactionsModal = React.memo(
|
const ReactionsModal = React.memo(
|
||||||
({ isVisible, onClose, theme, ...props }: IReactionsModal) => (
|
({ isVisible, onClose, ...props }: IReactionsModal) => {
|
||||||
|
const { theme } = useTheme();
|
||||||
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
isVisible={isVisible}
|
isVisible={isVisible}
|
||||||
onBackdropPress={onClose}
|
onBackdropPress={onClose}
|
||||||
|
@ -153,8 +154,9 @@ const ReactionsModal = React.memo(
|
||||||
swipeDirection={['up', 'left', 'right', 'down']}>
|
swipeDirection={['up', 'left', 'right', 'down']}>
|
||||||
<ModalContent onClose={onClose} theme={theme} {...props} />
|
<ModalContent onClose={onClose} theme={theme} {...props} />
|
||||||
</Modal>
|
</Modal>
|
||||||
),
|
);
|
||||||
(prevProps, nextProps) => prevProps.isVisible === nextProps.isVisible && prevProps.theme === nextProps.theme
|
},
|
||||||
|
(prevProps, nextProps) => prevProps.isVisible === nextProps.isVisible
|
||||||
);
|
);
|
||||||
|
|
||||||
ReactionsModal.displayName = 'ReactionsModal';
|
ReactionsModal.displayName = 'ReactionsModal';
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { IRoom } from '../definitions/IRoom';
|
||||||
import { IOptionsField } from '../views/NotificationPreferencesView/options';
|
import { IOptionsField } from '../views/NotificationPreferencesView/options';
|
||||||
import { IServer } from '../definitions/IServer';
|
import { IServer } from '../definitions/IServer';
|
||||||
import { IAttachment } from '../definitions/IAttachment';
|
import { IAttachment } from '../definitions/IAttachment';
|
||||||
import { IMessage } from '../definitions/IMessage';
|
import { IMessage, TMessageModel } from '../definitions/IMessage';
|
||||||
import { ISubscription, SubscriptionType, TSubscriptionModel } from '../definitions/ISubscription';
|
import { ISubscription, SubscriptionType, TSubscriptionModel } from '../definitions/ISubscription';
|
||||||
import { ICannedResponse } from '../definitions/ICannedResponse';
|
import { ICannedResponse } from '../definitions/ICannedResponse';
|
||||||
import { ModalStackParamList } from './MasterDetailStack/types';
|
import { ModalStackParamList } from './MasterDetailStack/types';
|
||||||
|
@ -24,7 +24,7 @@ export type ChatsStackParamList = {
|
||||||
rid: string;
|
rid: string;
|
||||||
t: SubscriptionType;
|
t: SubscriptionType;
|
||||||
tmid?: string;
|
tmid?: string;
|
||||||
message?: object; // TODO: TMessageModel?
|
message?: TMessageModel;
|
||||||
name?: string;
|
name?: string;
|
||||||
fname?: string;
|
fname?: string;
|
||||||
prid?: string;
|
prid?: string;
|
||||||
|
|
|
@ -22,6 +22,7 @@ import styles from './styles';
|
||||||
import { ChatsStackParamList } from '../../stacks/types';
|
import { ChatsStackParamList } from '../../stacks/types';
|
||||||
import { ISubscription, SubscriptionType } from '../../definitions/ISubscription';
|
import { ISubscription, SubscriptionType } from '../../definitions/ISubscription';
|
||||||
import { IEmoji } from '../../definitions/IEmoji';
|
import { IEmoji } from '../../definitions/IEmoji';
|
||||||
|
import { TMessageModel } from '../../definitions';
|
||||||
|
|
||||||
interface IMessagesViewProps {
|
interface IMessagesViewProps {
|
||||||
user: {
|
user: {
|
||||||
|
@ -79,7 +80,7 @@ interface IParams {
|
||||||
rid: string;
|
rid: string;
|
||||||
t: SubscriptionType;
|
t: SubscriptionType;
|
||||||
tmid?: string;
|
tmid?: string;
|
||||||
message?: object;
|
message?: TMessageModel;
|
||||||
name?: string;
|
name?: string;
|
||||||
fname?: string;
|
fname?: string;
|
||||||
prid?: string;
|
prid?: string;
|
||||||
|
|
|
@ -77,6 +77,7 @@ import {
|
||||||
IVisitor,
|
IVisitor,
|
||||||
SubscriptionType,
|
SubscriptionType,
|
||||||
TAnyMessageModel,
|
TAnyMessageModel,
|
||||||
|
TMessageModel,
|
||||||
TSubscriptionModel,
|
TSubscriptionModel,
|
||||||
TThreadModel
|
TThreadModel
|
||||||
} from '../../definitions';
|
} from '../../definitions';
|
||||||
|
@ -150,7 +151,7 @@ interface IRoomViewState {
|
||||||
member: any;
|
member: any;
|
||||||
lastOpen: Date | null;
|
lastOpen: Date | null;
|
||||||
reactionsModalVisible: boolean;
|
reactionsModalVisible: boolean;
|
||||||
selectedMessage?: Object;
|
selectedMessage?: TAnyMessageModel;
|
||||||
canAutoTranslate: boolean;
|
canAutoTranslate: boolean;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
showingBlockingLoader: boolean;
|
showingBlockingLoader: boolean;
|
||||||
|
@ -686,7 +687,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
id: message.subscription.id
|
id: message.subscription.id
|
||||||
},
|
},
|
||||||
msg: message?.attachments?.[0]?.description || message.msg
|
msg: message?.attachments?.[0]?.description || message.msg
|
||||||
};
|
} as TMessageModel;
|
||||||
this.setState({ selectedMessage: newMessage, editing: true });
|
this.setState({ selectedMessage: newMessage, editing: true });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1374,7 +1375,6 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
baseUrl={baseUrl}
|
baseUrl={baseUrl}
|
||||||
onClose={this.onCloseReactionsModal}
|
onClose={this.onCloseReactionsModal}
|
||||||
getCustomEmoji={this.getCustomEmoji}
|
getCustomEmoji={this.getCustomEmoji}
|
||||||
theme={theme}
|
|
||||||
/>
|
/>
|
||||||
<JoinCode ref={this.joinCode} onJoin={this.onJoin} rid={rid} t={t} theme={theme} />
|
<JoinCode ref={this.joinCode} onJoin={this.onJoin} rid={rid} t={t} theme={theme} />
|
||||||
<Loading visible={showingBlockingLoader} />
|
<Loading visible={showingBlockingLoader} />
|
||||||
|
|
Loading…
Reference in New Issue