* Viewing Files in Edit mode in mobile with ability to delete and save * Added upload attachment to keyboard tracker view * using state instread of use ref * Minor * Added tests * intl extract * new function getFiles ById, batch file deletion and tests * Files fetching in edit options and tests * Removed DeviceEventEmitter and used React context * Added support to check minimum required version to show edit file attachments * resolve forward ref issue * Minor * memotized props for context and observe config with value * Import fixes
84 lines
2.3 KiB
TypeScript
84 lines
2.3 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import React from 'react';
|
|
import {View, Platform} from 'react-native';
|
|
|
|
import {removeDraftFile} from '@actions/local/draft';
|
|
import CompassIcon from '@components/compass_icon';
|
|
import TouchableWithFeedback from '@components/touchable_with_feedback';
|
|
import {useEditPost} from '@context/edit_post';
|
|
import {useServerUrl} from '@context/server';
|
|
import {useTheme} from '@context/theme';
|
|
import DraftUploadManager from '@managers/draft_upload_manager';
|
|
import {makeStyleSheetFromTheme, changeOpacity} from '@utils/theme';
|
|
|
|
type Props = {
|
|
channelId: string;
|
|
rootId: string;
|
|
clientId: string;
|
|
isEditMode: boolean;
|
|
fileId: string;
|
|
}
|
|
|
|
const getStyleSheet = makeStyleSheetFromTheme((theme) => {
|
|
return {
|
|
tappableContainer: {
|
|
position: 'absolute',
|
|
elevation: 11,
|
|
top: -7,
|
|
right: -8,
|
|
width: 24,
|
|
height: 24,
|
|
},
|
|
removeButton: {
|
|
borderRadius: 12,
|
|
alignSelf: 'center',
|
|
marginTop: Platform.select({
|
|
ios: 5.4,
|
|
android: 4.75,
|
|
}),
|
|
backgroundColor: theme.centerChannelBg,
|
|
width: 24,
|
|
height: 25,
|
|
},
|
|
};
|
|
});
|
|
|
|
export default function UploadRemove({
|
|
channelId,
|
|
rootId,
|
|
clientId,
|
|
isEditMode,
|
|
fileId,
|
|
}: Props) {
|
|
const theme = useTheme();
|
|
const style = getStyleSheet(theme);
|
|
const serverUrl = useServerUrl();
|
|
const {onFileRemove} = useEditPost();
|
|
|
|
const onPress = () => {
|
|
if (isEditMode) {
|
|
onFileRemove?.(fileId);
|
|
return;
|
|
}
|
|
DraftUploadManager.cancel(clientId);
|
|
removeDraftFile(serverUrl, channelId, rootId, clientId);
|
|
};
|
|
|
|
return (
|
|
<TouchableWithFeedback
|
|
style={style.tappableContainer}
|
|
onPress={onPress}
|
|
type={'opacity'}
|
|
>
|
|
<View style={style.removeButton}>
|
|
<CompassIcon
|
|
name='close-circle'
|
|
color={changeOpacity(theme.centerChannelColor, 0.64)}
|
|
size={24}
|
|
/>
|
|
</View>
|
|
</TouchableWithFeedback>
|
|
);
|
|
}
|