mirror of
https://github.com/mattermost/mattermost-mobile.git
synced 2026-11-05 10:28:54 +00:00
* Expo-Router partial migration * Full migration to ExpoRouter * i18n * add tests * Merge branch 'main' into expo-router * align package-lock.json * i18n * feedback review * feedback review * android 16kb patch * Refactored emoji picker keyboard using a state machine * set android launch_screen in drawables instead of layout * no conditional hooks * remove duplicate call in test * address feedback * fix tests and address more feedback * small corrections * small corrections * small corrections * fix draft test * fix draft test 2 * remove navigateToScreen in draff test * fix nit in draft test * remove doc file * Feedback review * fix snapshots * improve test coverage * fix i18n * Upgrade t o RN 0.83, other dependencies and new architecture (#9737) * library hardware-keyboard android new arch support fix * library rnshare android new arch support fix * library rnutils android new arch support fix * library secure-pdf-viewer add new arch support * Enable new arch on iOS and Android * update emm and network client with new-arch * update intune to use new-arch * performance improvements * fix tests * fixes post input on new-arch * fix android emoji picker * remove doc * run tests in parallel * upgrade to React Native 0.83.9, Expo 55, React 19, and New Architecture Bumps core dependencies to their latest versions: - React Native 0.77.3 → 0.83.9 (New Architecture enabled) - React 18.3.1 → 19.2.5 - Expo SDK 52 → 55 - TypeScript 5.8.3 → 6.0.3 - Node.js 22.16.0 → 24.15.0 - react-native-reanimated 3.17.3 → 4.3.0 - Various other dependency upgrades Migrates iOS AppDelegate from Objective-C to Swift, updates Android build tooling and Gradle wrapper, refreshes all patches and font assets, and adapts app code, tests, and CI workflows throughout for API changes introduced by these upgrades. * remove unecessary dismissKeyboard in notifications * feedback review * update intune to use new-arch * update @mattermost deps * missing i18n string * additional fixes * update fastlane
152 lines
5.1 KiB
TypeScript
152 lines
5.1 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import React, {useCallback, useEffect, useRef} from 'react';
|
|
import {useIntl} from 'react-intl';
|
|
|
|
import {addFilesToDraft, removeDraft} from '@actions/local/draft';
|
|
import {useServerUrl} from '@context/server';
|
|
import useFileUploadError from '@hooks/file_upload_error';
|
|
import DraftEditPostUploadManager from '@managers/draft_upload_manager';
|
|
import {fileMaxWarning, fileSizeWarning, getUploadErrorMessage, uploadDisabledWarning} from '@utils/file';
|
|
|
|
import SendHandler from '../send_handler';
|
|
|
|
import type {ErrorHandlers} from '@typings/components/upload_error_handlers';
|
|
import type {AvailableScreens} from '@typings/screens/navigation';
|
|
|
|
type Props = {
|
|
testID?: string;
|
|
channelId: string;
|
|
cursorPosition: number;
|
|
rootId?: string;
|
|
canShowPostPriority?: boolean;
|
|
files?: FileInfo[];
|
|
maxFileCount: number;
|
|
maxFileSize: number;
|
|
canUploadFiles: boolean;
|
|
updateCursorPosition: React.Dispatch<React.SetStateAction<number>>;
|
|
updatePostInputTop: (top: number) => void;
|
|
updateValue: React.Dispatch<React.SetStateAction<string>>;
|
|
value: string;
|
|
setIsFocused: (isFocused: boolean) => void;
|
|
onPostCreated?: (postId: string) => void;
|
|
location?: AvailableScreens;
|
|
}
|
|
|
|
const emptyFileList: FileInfo[] = [];
|
|
|
|
export default function DraftHandler(props: Props) {
|
|
const {
|
|
testID,
|
|
channelId,
|
|
cursorPosition,
|
|
rootId = '',
|
|
canShowPostPriority,
|
|
files,
|
|
maxFileCount,
|
|
maxFileSize,
|
|
canUploadFiles,
|
|
updateCursorPosition,
|
|
updatePostInputTop,
|
|
updateValue,
|
|
value,
|
|
setIsFocused,
|
|
onPostCreated,
|
|
location,
|
|
} = props;
|
|
|
|
const serverUrl = useServerUrl();
|
|
const intl = useIntl();
|
|
|
|
const uploadErrorHandlers = useRef<ErrorHandlers>({});
|
|
const {uploadError, newUploadError} = useFileUploadError();
|
|
|
|
const handleUploadError = useCallback((errorMessage: string, errorName?: string) => {
|
|
newUploadError(getUploadErrorMessage(intl, errorMessage, errorName));
|
|
}, [intl, newUploadError]);
|
|
|
|
const clearDraft = useCallback(() => {
|
|
removeDraft(serverUrl, channelId, rootId);
|
|
updateValue('');
|
|
}, [serverUrl, channelId, rootId, updateValue]);
|
|
|
|
const addFiles = useCallback((newFiles: FileInfo[]) => {
|
|
if (!newFiles.length) {
|
|
return;
|
|
}
|
|
|
|
if (!canUploadFiles) {
|
|
newUploadError(uploadDisabledWarning(intl));
|
|
return;
|
|
}
|
|
|
|
const currentFileCount = files?.length || 0;
|
|
const availableCount = maxFileCount - currentFileCount;
|
|
if (newFiles.length > availableCount) {
|
|
newUploadError(fileMaxWarning(intl, maxFileCount));
|
|
return;
|
|
}
|
|
|
|
const largeFile = newFiles.find((file) => file.size > maxFileSize);
|
|
if (largeFile) {
|
|
newUploadError(fileSizeWarning(intl, maxFileSize));
|
|
return;
|
|
}
|
|
|
|
addFilesToDraft(serverUrl, channelId, rootId, newFiles);
|
|
|
|
for (const file of newFiles) {
|
|
DraftEditPostUploadManager.prepareUpload(serverUrl, file, channelId, rootId);
|
|
uploadErrorHandlers.current[file.clientId!] = DraftEditPostUploadManager.registerErrorHandler(file.clientId!, handleUploadError);
|
|
}
|
|
|
|
newUploadError(null);
|
|
}, [canUploadFiles, files?.length, maxFileCount, serverUrl, channelId, rootId, newUploadError, intl, maxFileSize, handleUploadError]);
|
|
|
|
// This effect mainly handles keeping clean the uploadErrorHandlers, and
|
|
// reinstantiate them on component mount and file retry.
|
|
useEffect(() => {
|
|
let loadingFiles: FileInfo[] = [];
|
|
if (files) {
|
|
loadingFiles = files.filter((v) => v.clientId && DraftEditPostUploadManager.isUploading(v.clientId));
|
|
}
|
|
|
|
for (const key of Object.keys(uploadErrorHandlers.current)) {
|
|
if (!loadingFiles.find((v) => v.clientId === key)) {
|
|
uploadErrorHandlers.current[key]?.();
|
|
delete (uploadErrorHandlers.current[key]);
|
|
}
|
|
}
|
|
|
|
for (const file of loadingFiles) {
|
|
if (!uploadErrorHandlers.current[file.clientId!]) {
|
|
uploadErrorHandlers.current[file.clientId!] = DraftEditPostUploadManager.registerErrorHandler(file.clientId!, handleUploadError);
|
|
}
|
|
}
|
|
}, [files, newUploadError, handleUploadError]);
|
|
|
|
return (
|
|
<SendHandler
|
|
testID={testID}
|
|
channelId={channelId}
|
|
rootId={rootId}
|
|
canShowPostPriority={canShowPostPriority}
|
|
|
|
// From draft handler
|
|
cursorPosition={cursorPosition}
|
|
value={value}
|
|
files={files || emptyFileList}
|
|
clearDraft={clearDraft}
|
|
addFiles={addFiles}
|
|
uploadFileError={uploadError}
|
|
updateCursorPosition={updateCursorPosition}
|
|
updatePostInputTop={updatePostInputTop}
|
|
updateValue={updateValue}
|
|
setIsFocused={setIsFocused}
|
|
onPostCreated={onPostCreated}
|
|
location={location}
|
|
/>
|
|
);
|
|
}
|