mattermost-mobile/app/components/post_draft/uploads/upload_item/upload_remove.tsx
Rajat Dabade 71fed8aa50
(Android) Common component for upload item for main application and share extension (#9028)
* Common component for upload item for main application and share extension

* Addressed review comments

* intl fixes

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
2025-09-11 12:54:54 +05:30

43 lines
1.2 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {useCallback} from 'react';
import {removeDraftFile} from '@actions/local/draft';
import RemoveButton from '@components/upload_item_shared/remove_button';
import {useEditPost} from '@context/edit_post';
import {useServerUrl} from '@context/server';
import DraftEditPostUploadManager from '@managers/draft_upload_manager';
type Props = {
channelId: string;
rootId: string;
clientId: string;
fileId: string;
}
export default function UploadRemove({
channelId,
rootId,
clientId,
fileId,
}: Props) {
const serverUrl = useServerUrl();
const {onFileRemove, isEditMode} = useEditPost();
const onPress = useCallback(() => {
if (isEditMode) {
onFileRemove?.(fileId || clientId);
return;
}
DraftEditPostUploadManager.cancel(clientId);
removeDraftFile(serverUrl, channelId, rootId, clientId);
}, [onFileRemove, isEditMode, fileId, clientId, serverUrl, channelId, rootId]);
return (
<RemoveButton
onPress={onPress}
testID={`remove-button-${fileId}`}
/>
);
}