Files
mattermost-mobile/app/screens/thread/thread_follow_button/thread_follow_button.tsx
Elias Nahum ae3c9e2ef2 [Gekidou] bug fixes found with e2e tests (#6130)
* Fix Search users in Create Direct Message

* Fix UserListRow style for onPress

* Prevent create direct message & browse channels from being dismissed with a swipe

* Only display Edit header option when tapping in the channel intro

* Fix localization for ThreadFollowButton

* Prevent New channel screen from being dismiss with a swipe
2022-04-07 09:57:43 -04:00

88 lines
2.5 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {Platform, StyleSheet, TouchableOpacity, View} from 'react-native';
import {updateThreadFollowing} from '@actions/remote/thread';
import FormattedText from '@components/formatted_text';
import {useServerUrl} from '@context/server';
import {useTheme} from '@context/theme';
import {t} from '@i18n';
import {preventDoubleTap} from '@utils/tap';
import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme';
import {typography} from '@utils/typography';
type Props = {
isFollowing: boolean;
teamId: string;
threadId: string;
};
const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => {
return {
container: {
borderColor: theme.sidebarHeaderTextColor,
borderWidth: StyleSheet.hairlineWidth,
borderRadius: 4,
paddingVertical: 4.5,
paddingHorizontal: 10,
opacity: 0.72,
...Platform.select({
android: {
marginRight: 12,
},
ios: {
right: -4,
},
}),
},
containerActive: {
backgroundColor: changeOpacity(theme.sidebarHeaderTextColor, 0.24),
borderColor: 'transparent',
opacity: 1,
},
text: {
color: theme.sidebarHeaderTextColor,
...typography('Heading', 75, 'SemiBold'),
},
};
});
function ThreadFollow({isFollowing, teamId, threadId}: Props) {
const theme = useTheme();
const styles = getStyleSheet(theme);
const serverUrl = useServerUrl();
const onPress = preventDoubleTap(() => {
updateThreadFollowing(serverUrl, teamId, threadId, !isFollowing);
});
const containerStyle = [styles.container];
let followTextProps = {
id: t('threads.follow'),
defaultMessage: 'Follow',
};
if (isFollowing) {
containerStyle.push(styles.containerActive);
followTextProps = {
id: t('threads.following'),
defaultMessage: 'Following',
};
}
return (
<TouchableOpacity onPress={onPress}>
<View style={containerStyle}>
<FormattedText
{...followTextProps}
style={styles.text}
/>
</View>
</TouchableOpacity>
);
}
export default ThreadFollow;