mattermost-mobile/app/components/post_draft/quick_actions/quick_actions.tsx
Rajat Dabade dae4b75720
Ability to show quick action and add files to edit post (#8926)
* 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

* Ability to show quick action and add files to edit post

* type safety for EditPostContext

* Reverted back the post priority props

* constant shift

* Added test for QuickAction to show slashcomand

* Added test for edit_post, upload_item and upload_remove

* Added test for Edit_post_input and edit_post index

* fix the height issue between attachment and keyboard due to safeArea

* Minor: removed debugging border color

* Addressed dev review comments

* Import fixes

* Address UX comments

* Fixed props for UploadItem and remove effective Edit mode

* handled save button disabled state when uploading attachments

* handled newly added and retry file removal without alert message

* Test updated

* Added test for input_quick_action index.tsx

* Added test for not in edit mode for upload_item index

* Added test for upload_remove component when not in edit mode

* added tests for file_upload_error hook

* Added test for calling callback when in edit mode

* Test for edit post input for server version check
2025-06-25 16:04:08 +05:30

116 lines
3.3 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {StyleSheet, View} from 'react-native';
import CameraAction from './camera_quick_action';
import FileAction from './file_quick_action';
import ImageAction from './image_quick_action';
import InputAction from './input_quick_action';
import PostPriorityAction from './post_priority_action';
type Props = {
testID?: string;
canUploadFiles: boolean;
fileCount: number;
isPostPriorityEnabled: boolean;
canShowPostPriority?: boolean;
canShowSlashCommands?: boolean;
maxFileCount: number;
// Draft Handler
value: string;
updateValue: (value: string) => void;
addFiles: (file: FileInfo[]) => void;
postPriority: PostPriority;
updatePostPriority: (postPriority: PostPriority) => void;
focus: () => void;
}
export const QUICK_ACTIONS_HEIGHT = 44;
const style = StyleSheet.create({
quickActionsContainer: {
display: 'flex',
flexDirection: 'row',
height: QUICK_ACTIONS_HEIGHT,
},
});
export default function QuickActions({
testID,
canUploadFiles,
value,
fileCount,
isPostPriorityEnabled,
canShowSlashCommands = true,
canShowPostPriority,
maxFileCount,
updateValue,
addFiles,
postPriority,
updatePostPriority,
focus,
}: Props) {
const atDisabled = value[value.length - 1] === '@';
const slashDisabled = value.length > 0;
const atInputActionTestID = `${testID}.at_input_action`;
const slashInputActionTestID = `${testID}.slash_input_action`;
const fileActionTestID = `${testID}.file_action`;
const imageActionTestID = `${testID}.image_action`;
const cameraActionTestID = `${testID}.camera_action`;
const postPriorityActionTestID = `${testID}.post_priority_action`;
const uploadProps = {
disabled: !canUploadFiles,
fileCount,
maxFileCount,
maxFilesReached: fileCount >= maxFileCount,
onUploadFiles: addFiles,
};
return (
<View
testID={testID}
style={style.quickActionsContainer}
>
<InputAction
testID={atInputActionTestID}
disabled={atDisabled}
inputType='at'
updateValue={updateValue}
focus={focus}
/>
{canShowSlashCommands && (
<InputAction
testID={slashInputActionTestID}
disabled={slashDisabled}
inputType='slash'
updateValue={updateValue}
focus={focus}
/>
)}
<FileAction
testID={fileActionTestID}
{...uploadProps}
/>
<ImageAction
testID={imageActionTestID}
{...uploadProps}
/>
<CameraAction
testID={cameraActionTestID}
{...uploadProps}
/>
{isPostPriorityEnabled && canShowPostPriority && (
<PostPriorityAction
testID={postPriorityActionTestID}
postPriority={postPriority}
updatePostPriority={updatePostPriority}
/>
)}
</View>
);
}