@@ -15,14 +15,14 @@ import { ReactComponent as PlaySVG } from '@icons/play.svg';
15
15
import { ReactComponent as VideoSVG } from '@icons/video.svg' ;
16
16
import { ReactComponent as MicrophoneSvg } from '@icons/voice.svg' ;
17
17
import { removeAttachmentAction } from '@store/chats/actions' ;
18
- import { IAttachmentToSend , IAttachmentCreation } from '@store/chats/models' ;
18
+ import { IAttachmentCreation , IAttachmentToSend } from '@store/chats/models' ;
19
19
import { INamedAttachment } from '@store/chats/models/named-attachment' ;
20
20
import { getRawAttachmentSizeUnit } from '@utils/get-file-size-unit' ;
21
21
22
22
import './message-input-attachment.scss' ;
23
23
24
24
interface IMessageInputAttachmentProps {
25
- attachment : IAttachmentToSend < IAttachmentBase > ;
25
+ attachment : IAttachmentToSend | IAttachmentBase ;
26
26
isFromEdit ?: boolean ;
27
27
removeSelectedAttachment ?: ( attachmentToRemove : IAttachmentCreation ) => void ;
28
28
}
@@ -33,93 +33,87 @@ export const MessageInputAttachment: React.FC<IMessageInputAttachmentProps> = ({
33
33
removeSelectedAttachment,
34
34
} ) => {
35
35
const removeAttachment = useActionWithDispatch ( removeAttachmentAction ) ;
36
-
36
+ const newAttachment = attachment as IAttachmentToSend ;
37
37
const [ previewUrl , setPreviewUr ] = useState < string > ( '' ) ;
38
38
39
39
const removeThisAttachment = useCallback ( ( ) => {
40
40
if ( removeSelectedAttachment ) {
41
41
removeSelectedAttachment ( {
42
- type : attachment . attachment . type ,
43
- id : attachment . attachment . id ,
42
+ type : attachment . type ,
43
+ id : attachment . id ,
44
44
} ) ;
45
45
} else {
46
46
removeAttachment ( {
47
- attachmentId : attachment . attachment . id ,
47
+ attachmentId : attachment . id ,
48
48
} ) ;
49
49
}
50
- } , [
51
- attachment . attachment . id ,
52
- attachment . attachment . type ,
53
- removeAttachment ,
54
- removeSelectedAttachment ,
55
- ] ) ;
50
+ } , [ attachment . id , attachment . type , removeAttachment , removeSelectedAttachment ] ) ;
56
51
57
52
useEffect ( ( ) => {
58
- if ( attachment . attachment . type === AttachmentType . Picture && ! isFromEdit ) {
53
+ if ( attachment . type === AttachmentType . Picture && ! isFromEdit ) {
59
54
const reader = new FileReader ( ) ;
60
55
61
56
reader . onload = ( e ) => {
62
57
setPreviewUr ( e . target ?. result as string ) ;
63
58
} ;
64
59
65
- reader . readAsDataURL ( attachment . file ) ;
60
+ reader . readAsDataURL ( newAttachment . file ) ;
66
61
}
67
- } , [ setPreviewUr , isFromEdit , attachment . attachment . type , attachment . file ] ) ;
62
+ } , [ setPreviewUr , isFromEdit , attachment . type , newAttachment . file ] ) ;
68
63
69
64
return (
70
65
< div className = "message-input-attachment" >
71
- { attachment . attachment . type === AttachmentType . Raw && (
66
+ { attachment . type === AttachmentType . Raw && (
72
67
< FileSVG className = "message-input-attachment__type-icon" />
73
68
) }
74
- { attachment . attachment . type === AttachmentType . Video && (
69
+ { attachment . type === AttachmentType . Video && (
75
70
< >
76
- { ( attachment . attachment as IVideoAttachment ) . firstFrameUrl && (
71
+ { ( attachment as unknown as IVideoAttachment ) . firstFrameUrl && (
77
72
< img
78
- src = { ( attachment . attachment as IVideoAttachment ) . firstFrameUrl }
73
+ src = { ( attachment as unknown as IVideoAttachment ) . firstFrameUrl }
79
74
alt = ""
80
75
className = "message-input-attachment__bg"
81
76
/>
82
77
) }
83
78
< VideoSVG className = "message-input-attachment__type-icon" />
84
79
</ >
85
80
) }
86
- { attachment . attachment . type === AttachmentType . Picture && (
81
+ { attachment . type === AttachmentType . Picture && (
87
82
< >
88
- { ( ( attachment . attachment as IPictureAttachment ) . previewUrl || previewUrl ) && (
83
+ { ( ( attachment as unknown as IPictureAttachment ) . previewUrl || previewUrl ) && (
89
84
< img
90
- src = { ( attachment . attachment as IPictureAttachment ) . previewUrl || previewUrl }
85
+ src = { ( attachment as unknown as IPictureAttachment ) . previewUrl || previewUrl }
91
86
alt = ""
92
87
className = "message-input-attachment__bg"
93
88
/>
94
89
) }
95
90
< PhotoSVG className = "message-input-attachment__type-icon" />
96
91
</ >
97
92
) }
98
- { attachment . attachment . type === AttachmentType . Audio && (
93
+ { attachment . type === AttachmentType . Audio && (
99
94
< PlaySVG className = "message-input-attachment__type-icon" />
100
95
) }
101
96
102
- { attachment . attachment . type === AttachmentType . Voice && (
97
+ { attachment . type === AttachmentType . Voice && (
103
98
< MicrophoneSvg className = "message-input-attachment__type-icon" />
104
99
) }
105
100
106
101
< div
107
- style = { { width : `${ attachment . progress } %` } }
102
+ style = { { width : `${ newAttachment . progress } %` } }
108
103
className = { `message-input-attachment__progress ${
109
- attachment . attachment . type === AttachmentType . Picture ||
110
- attachment . attachment . type === AttachmentType . Video
104
+ attachment . type === AttachmentType . Picture || attachment . type === AttachmentType . Video
111
105
? 'message-input-attachment__progress--photo'
112
106
: ''
113
107
} `}
114
108
/>
115
109
116
110
< div className = "message-input-attachment__data" >
117
111
< div className = "message-input-attachment__title" >
118
- { ( attachment . attachment as INamedAttachment ) . fileName }
112
+ { ( attachment as unknown as INamedAttachment ) . fileName }
119
113
</ div >
120
114
< div className = "message-input-attachment__size" > { `${ getRawAttachmentSizeUnit (
121
- attachment . uploadedBytes || attachment . attachment . byteSize ,
122
- ) } /${ getRawAttachmentSizeUnit ( attachment . attachment . byteSize ) } }`} </ div >
115
+ newAttachment . uploadedBytes || attachment . byteSize ,
116
+ ) } /${ getRawAttachmentSizeUnit ( attachment . byteSize ) } }`} </ div >
123
117
</ div >
124
118
125
119
< button
0 commit comments