mattermost-mobile/app/screens/post_options/post_option.tsx
Anurag Shivarathri 856d8bd05f
MM-34842 global threads options (#5630)
* fixes MM-37294 MM-37296 MM-37297

* Added conditions to check for post & thread existence

* Update app/mm-redux/selectors/entities/threads.ts

Co-authored-by: Kyriakos Z. <3829551+koox00@users.noreply.github.com>

* type fix

* Never disabling Mark All as unread

* Added follow/unfollow message for not yet thread posts

* Test case fix for mark all as unread enabled all the time

* Removed hardcoded condition

* Fixed MM-37509

* Updated snapshot for sidebar

* Global thread actions init

* Added options

* Update post_options.js

* Test cases fix

* Added border bottom for each thread option

* Update test case

* Reverting snapshot

* Updated snapshot

* Moved options to screens & removed redundants translations

* Reusing post_option for thread_option

* Component name changed to PostOption from ThreadOption

* Snapshot updated

* Removed factory

* Update app/screens/thread_options/index.ts

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>

* Update app/screens/thread_options/index.ts

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>

Co-authored-by: Kyriakos Z. <3829551+koox00@users.noreply.github.com>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
2021-10-11 13:24:38 +05:30

153 lines
4 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {
Text,
Platform,
TouchableHighlight,
TouchableNativeFeedback,
View,
} from 'react-native';
import FastImage from 'react-native-fast-image';
import CompassIcon from '@components/compass_icon';
import {Theme} from '@mm-redux/types/theme';
import {preventDoubleTap} from '@utils/tap';
import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme';
import {isValidUrl} from '@utils/url';
type Props = {
testID?: string;
destructive?: boolean;
icon: string | {
uri: string;
};
onPress: () => void;
text: string;
theme: Theme;
};
function PostOption({destructive, icon, onPress, testID, text, theme}: Props) {
const style = getStyleSheet(theme);
const handleOnPress = React.useCallback(preventDoubleTap(onPress, 500), []);
let Touchable: React.ElementType;
if (Platform.OS === 'android') {
Touchable = TouchableNativeFeedback;
} else {
Touchable = TouchableHighlight;
}
const touchableProps = Platform.select({
ios: {
underlayColor: 'rgba(0, 0, 0, 0.1)',
},
android: {
background: TouchableNativeFeedback.Ripple( //eslint-disable-line new-cap
'rgba(0, 0, 0, 0.1)',
false,
),
},
});
const imageStyle = [style.icon, destructive ? style.destructive : null];
let image;
let iconStyle = [style.iconContainer];
if (typeof icon === 'object') {
if (icon.uri) {
imageStyle.push({width: 24, height: 24});
image = isValidUrl(icon.uri) && (
<FastImage
source={icon}
style={imageStyle}
/>
);
} else {
iconStyle = [style.noIconContainer];
}
} else {
image = (
<CompassIcon
name={icon}
size={24}
style={[style.icon, destructive ? style.destructive : null]}
/>
);
}
return (
<View
testID={testID}
style={style.container}
>
<Touchable
onPress={handleOnPress}
{...touchableProps}
style={style.row}
>
<View style={style.row}>
<View style={iconStyle}>
{image}
</View>
<View style={style.textContainer}>
<Text style={[style.text, destructive ? style.destructive : null]}>
{text}
</Text>
</View>
</View>
</Touchable>
<View style={style.footer}/>
</View>
);
}
export default PostOption;
const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => {
return {
container: {
height: 51,
width: '100%',
},
destructive: {
color: '#D0021B',
},
row: {
flex: 1,
flexDirection: 'row',
},
iconContainer: {
alignItems: 'center',
height: 50,
justifyContent: 'center',
width: 60,
},
noIconContainer: {
height: 50,
width: 18,
},
icon: {
color: changeOpacity(theme.centerChannelColor, 0.64),
},
textContainer: {
justifyContent: 'center',
flex: 1,
height: 50,
marginRight: 5,
},
text: {
color: theme.centerChannelColor,
fontSize: 16,
lineHeight: 19,
opacity: 0.9,
letterSpacing: -0.45,
},
footer: {
marginHorizontal: 17,
borderBottomWidth: 0.5,
borderBottomColor: changeOpacity(theme.centerChannelColor, 0.2),
},
};
});