* refactor: started with draft, done until new tabs for draft * refactor: change the query and added the screen for draft * added condition for fetching draft for channel delete or not * refactor: added draft screen * linter fixes * Added draft post component * added avatar and header display name for the draft post list * added channel info component * channel info completed * proper naming * added image file markdown acknowledgement support * draft actions * Fix the draft receiver in drafts * separated send message handler * Done with send drafts * done with delete drafts * change save to send draft * handle lengthy message with show more button * done with persistent message edit, send and delete drafts * added alert for sending message * added update at time for the drafts * en.json extract fix * Updated dependencies for useCallback * refactor: added drafts list to animated list * added swipeable component and delete conformation for drafts * done with rendering of images in markdown for drafts * en.json issue fixed * fix en.json issue * refactor: en.json fix * addressed review comments * updated image metadata handling code * linter fixes * added the empty draft screen * linter fix * style fix * back button an android takes to the channel list page * en.json fix * draft actions theme compatible * CSS fix for draft channel_info and avatar component * removed the badge icon and change font style drafts * fix send alert sender name for GMs * updated snapshot * added testId to the drafts components * updated send draft test id * clicking on draft takes to the channel * Added toptip for draft tours * intl extract * Rebase to main and reverted local testing changes * Added tooltip for drafts * addressed review comments * reset navigation when click on a draft in draft tabs * fix the theme issue and navigation issue * reverted back the draft click navigation changes * observing draft when hitting back button * removed the unwanted animiation * updated regex for parsing markdown * removed unnecessary checks and change folder name * removed react memo and merge unwanted observes function * removed unnecessary comments * changed the name for observing and querying draft function * removed memo from component level * Text to FormattedText component * Text to formatted text, change image name * added confirmation modal for deleting draft from bottomsheet * using common send_handler for both draft and post * removed magic number for tooltip and bottomsheet * renamed channel_info to draft_post_header * text to formattedText for Edit drafts * removed unnecessary changes * minor fixes * mounting draft only when there is draft * map to reduce * renamed SwipeableDraft to DraftSwipeAction * name fixes * isValidUrl to isParsableUrl and added test * added test and addressed minor review comments * added inline component for the duplicate code * inlt fixes * clearDraft is not optional * optimised categories_list.tsx component * Swipeable to ReanimatedSwipeable, TouchableWithoutFeedback to Pressable and folder name changes * Added comment and disabled eslint rule for showing warning * fixed component file name * minor' * Removed deprecated Animated createAnimatedComponent flatlist * added test for missing protocol check * import change for SwipeableMethod * active tab for tablet view * Updated the drafts icons * Updated compass-icon version to v0.1.48 --------- Co-authored-by: Mattermost Build <build@mattermost.com>
237 lines
7.8 KiB
TypeScript
237 lines
7.8 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import React, {useCallback, useRef} from 'react';
|
|
import {useIntl} from 'react-intl';
|
|
import {type LayoutChangeEvent, Platform, ScrollView, View} from 'react-native';
|
|
import {type Edge, SafeAreaView} from 'react-native-safe-area-context';
|
|
|
|
import {useServerUrl} from '@context/server';
|
|
import {useTheme} from '@context/theme';
|
|
import {usePersistentNotificationProps} from '@hooks/persistent_notification_props';
|
|
import {persistentNotificationsConfirmation} from '@utils/post';
|
|
import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme';
|
|
|
|
import PostInput from '../post_input';
|
|
import QuickActions from '../quick_actions';
|
|
import SendAction from '../send_action';
|
|
import Typing from '../typing';
|
|
import Uploads from '../uploads';
|
|
|
|
import Header from './header';
|
|
|
|
import type {PasteInputRef} from '@mattermost/react-native-paste-input';
|
|
|
|
type Props = {
|
|
testID?: string;
|
|
channelId: string;
|
|
channelType?: ChannelType;
|
|
channelName?: string;
|
|
rootId?: string;
|
|
currentUserId: string;
|
|
canShowPostPriority?: boolean;
|
|
|
|
// Post Props
|
|
postPriority: PostPriority;
|
|
updatePostPriority: (postPriority: PostPriority) => void;
|
|
persistentNotificationInterval: number;
|
|
persistentNotificationMaxRecipients: number;
|
|
|
|
// Cursor Position Handler
|
|
updateCursorPosition: React.Dispatch<React.SetStateAction<number>>;
|
|
cursorPosition: number;
|
|
|
|
// Send Handler
|
|
sendMessage: () => void;
|
|
canSend: boolean;
|
|
maxMessageLength: number;
|
|
|
|
// Draft Handler
|
|
files: FileInfo[];
|
|
value: string;
|
|
uploadFileError: React.ReactNode;
|
|
updateValue: React.Dispatch<React.SetStateAction<string>>;
|
|
addFiles: (files: FileInfo[]) => void;
|
|
updatePostInputTop: (top: number) => void;
|
|
setIsFocused: (isFocused: boolean) => void;
|
|
}
|
|
|
|
const SAFE_AREA_VIEW_EDGES: Edge[] = ['left', 'right'];
|
|
|
|
const getStyleSheet = makeStyleSheetFromTheme((theme) => {
|
|
return {
|
|
actionsContainer: {
|
|
display: 'flex',
|
|
flexDirection: 'row',
|
|
justifyContent: 'space-between',
|
|
alignItems: 'center',
|
|
paddingBottom: Platform.select({
|
|
ios: 1,
|
|
android: 2,
|
|
}),
|
|
},
|
|
inputContainer: {
|
|
flex: 1,
|
|
flexDirection: 'column',
|
|
},
|
|
inputContentContainer: {
|
|
alignItems: 'stretch',
|
|
paddingTop: Platform.select({
|
|
ios: 7,
|
|
android: 0,
|
|
}),
|
|
},
|
|
inputWrapper: {
|
|
alignItems: 'flex-end',
|
|
flexDirection: 'row',
|
|
justifyContent: 'center',
|
|
paddingBottom: 2,
|
|
backgroundColor: theme.centerChannelBg,
|
|
borderWidth: 1,
|
|
borderBottomWidth: 0,
|
|
borderColor: changeOpacity(theme.centerChannelColor, 0.20),
|
|
borderTopLeftRadius: 12,
|
|
borderTopRightRadius: 12,
|
|
},
|
|
postPriorityLabel: {
|
|
marginLeft: 12,
|
|
marginTop: Platform.select({
|
|
ios: 3,
|
|
android: 10,
|
|
}),
|
|
},
|
|
};
|
|
});
|
|
|
|
export default function DraftInput({
|
|
testID,
|
|
channelId,
|
|
channelType,
|
|
channelName,
|
|
currentUserId,
|
|
canShowPostPriority,
|
|
files,
|
|
maxMessageLength,
|
|
rootId = '',
|
|
value,
|
|
uploadFileError,
|
|
sendMessage,
|
|
canSend,
|
|
updateValue,
|
|
addFiles,
|
|
updateCursorPosition,
|
|
cursorPosition,
|
|
updatePostInputTop,
|
|
postPriority,
|
|
updatePostPriority,
|
|
persistentNotificationInterval,
|
|
persistentNotificationMaxRecipients,
|
|
setIsFocused,
|
|
}: Props) {
|
|
const intl = useIntl();
|
|
const serverUrl = useServerUrl();
|
|
const theme = useTheme();
|
|
|
|
const handleLayout = useCallback((e: LayoutChangeEvent) => {
|
|
updatePostInputTop(e.nativeEvent.layout.height);
|
|
}, []);
|
|
|
|
const inputRef = useRef<PasteInputRef>();
|
|
const focus = useCallback(() => {
|
|
inputRef.current?.focus();
|
|
}, []);
|
|
|
|
// Render
|
|
const postInputTestID = `${testID}.post.input`;
|
|
const quickActionsTestID = `${testID}.quick_actions`;
|
|
const sendActionTestID = `${testID}.send_action`;
|
|
const style = getStyleSheet(theme);
|
|
|
|
const {persistentNotificationsEnabled, noMentionsError, mentionsList} = usePersistentNotificationProps({
|
|
value,
|
|
channelType,
|
|
postPriority,
|
|
});
|
|
|
|
const handleSendMessage = useCallback(async () => {
|
|
if (persistentNotificationsEnabled) {
|
|
persistentNotificationsConfirmation(serverUrl, value, mentionsList, intl, sendMessage, persistentNotificationMaxRecipients, persistentNotificationInterval, currentUserId, channelName, channelType);
|
|
} else {
|
|
sendMessage();
|
|
}
|
|
}, [serverUrl, mentionsList, persistentNotificationsEnabled, persistentNotificationMaxRecipients, sendMessage, value, channelType]);
|
|
|
|
const sendActionDisabled = !canSend || noMentionsError;
|
|
|
|
return (
|
|
<>
|
|
<Typing
|
|
channelId={channelId}
|
|
rootId={rootId}
|
|
/>
|
|
<SafeAreaView
|
|
edges={SAFE_AREA_VIEW_EDGES}
|
|
onLayout={handleLayout}
|
|
style={style.inputWrapper}
|
|
testID={testID}
|
|
>
|
|
|
|
<ScrollView
|
|
style={style.inputContainer}
|
|
contentContainerStyle={style.inputContentContainer}
|
|
keyboardShouldPersistTaps={'always'}
|
|
scrollEnabled={false}
|
|
showsVerticalScrollIndicator={false}
|
|
showsHorizontalScrollIndicator={false}
|
|
pinchGestureEnabled={false}
|
|
overScrollMode={'never'}
|
|
disableScrollViewPanResponder={true}
|
|
>
|
|
<Header
|
|
noMentionsError={noMentionsError}
|
|
postPriority={postPriority}
|
|
/>
|
|
<PostInput
|
|
testID={postInputTestID}
|
|
channelId={channelId}
|
|
maxMessageLength={maxMessageLength}
|
|
rootId={rootId}
|
|
cursorPosition={cursorPosition}
|
|
updateCursorPosition={updateCursorPosition}
|
|
updateValue={updateValue}
|
|
value={value}
|
|
addFiles={addFiles}
|
|
sendMessage={handleSendMessage}
|
|
inputRef={inputRef}
|
|
setIsFocused={setIsFocused}
|
|
/>
|
|
<Uploads
|
|
currentUserId={currentUserId}
|
|
files={files}
|
|
uploadFileError={uploadFileError}
|
|
channelId={channelId}
|
|
rootId={rootId}
|
|
/>
|
|
<View style={style.actionsContainer}>
|
|
<QuickActions
|
|
testID={quickActionsTestID}
|
|
fileCount={files.length}
|
|
addFiles={addFiles}
|
|
updateValue={updateValue}
|
|
value={value}
|
|
postPriority={postPriority}
|
|
updatePostPriority={updatePostPriority}
|
|
canShowPostPriority={canShowPostPriority}
|
|
focus={focus}
|
|
/>
|
|
<SendAction
|
|
testID={sendActionTestID}
|
|
disabled={sendActionDisabled}
|
|
sendMessage={handleSendMessage}
|
|
/>
|
|
</View>
|
|
</ScrollView>
|
|
</SafeAreaView>
|
|
</>
|
|
);
|
|
}
|