Архитектура
This commit is contained in:
@@ -155,10 +155,12 @@ export default function MessageInput({ chatId }: MessageInputProps) {
|
||||
|
||||
// Cleanup preview URLs
|
||||
useEffect(() => {
|
||||
(window as any).hasUnsavedAttachments = attachments.length > 0;
|
||||
return () => {
|
||||
attachments.forEach(a => {
|
||||
if (a.preview) URL.revokeObjectURL(a.preview);
|
||||
});
|
||||
(window as any).hasUnsavedAttachments = false;
|
||||
};
|
||||
}, [attachments]);
|
||||
|
||||
@@ -848,6 +850,37 @@ export default function MessageInput({ chatId }: MessageInputProps) {
|
||||
}
|
||||
}
|
||||
}}
|
||||
onPaste={(e) => {
|
||||
if (e.clipboardData.files && e.clipboardData.files.length > 0) {
|
||||
e.preventDefault();
|
||||
const files = Array.from(e.clipboardData.files);
|
||||
const { addNotification } = useNotificationStore.getState();
|
||||
const newAttachments: Attachment[] = [];
|
||||
let tooLarge = false;
|
||||
let limitExceeded = false;
|
||||
|
||||
for (const file of files) {
|
||||
if (attachments.length + newAttachments.length >= 20) {
|
||||
limitExceeded = true;
|
||||
break;
|
||||
}
|
||||
if (file.size > MAX_FILE_SIZE) {
|
||||
tooLarge = true; continue;
|
||||
}
|
||||
const isVideo = file.type.startsWith('video/');
|
||||
const isImage = file.type.startsWith('image/');
|
||||
const isAudio = file.type.startsWith('audio/') || AUDIO_EXTENSIONS.some(ext => file.name.toLowerCase().endsWith(ext));
|
||||
const type = isImage ? 'image' : isVideo ? 'video' : isAudio ? 'audio' : 'file';
|
||||
const preview = isImage ? URL.createObjectURL(file) : undefined;
|
||||
newAttachments.push({ file, type, preview });
|
||||
}
|
||||
|
||||
if (tooLarge) addNotification('warning', t('fileTooLarge') || 'Файлы слишком большие');
|
||||
if (limitExceeded) addNotification('warning', 'Максимум 20 файлов');
|
||||
|
||||
setAttachments(prev => [...prev, ...newAttachments]);
|
||||
}
|
||||
}}
|
||||
onKeyDown={handleKeyDown}
|
||||
onContextMenu={handleInputContextMenu}
|
||||
placeholder={attachments.length > 0 ? t('addCaption') : t('message')}
|
||||
|
||||
Reference in New Issue
Block a user