Chats: allow files to be removed before sending
This commit is contained in:
parent
49d2121017
commit
a02155846d
2 changed files with 35 additions and 3 deletions
|
@ -13,6 +13,8 @@ import ChatMessageList from './chat_message_list';
|
||||||
import UploadButton from 'soapbox/features/compose/components/upload_button';
|
import UploadButton from 'soapbox/features/compose/components/upload_button';
|
||||||
import { uploadMedia } from 'soapbox/actions/media';
|
import { uploadMedia } from 'soapbox/actions/media';
|
||||||
import UploadProgress from 'soapbox/features/compose/components/upload_progress';
|
import UploadProgress from 'soapbox/features/compose/components/upload_progress';
|
||||||
|
import { truncateFilename } from 'soapbox/utils/media';
|
||||||
|
import IconButton from 'soapbox/components/icon_button';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
placeholder: { id: 'chat_box.input.placeholder', defaultMessage: 'Send a message…' },
|
placeholder: { id: 'chat_box.input.placeholder', defaultMessage: 'Send a message…' },
|
||||||
|
@ -24,6 +26,8 @@ const mapStateToProps = (state, { chatId }) => ({
|
||||||
chatMessageIds: state.getIn(['chat_message_lists', chatId], ImmutableOrderedSet()),
|
chatMessageIds: state.getIn(['chat_message_lists', chatId], ImmutableOrderedSet()),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const fileKeyGen = () => Math.floor((Math.random() * 0x10000));
|
||||||
|
|
||||||
export default @connect(mapStateToProps)
|
export default @connect(mapStateToProps)
|
||||||
@injectIntl
|
@injectIntl
|
||||||
class ChatBox extends ImmutablePureComponent {
|
class ChatBox extends ImmutablePureComponent {
|
||||||
|
@ -43,6 +47,7 @@ class ChatBox extends ImmutablePureComponent {
|
||||||
attachment: undefined,
|
attachment: undefined,
|
||||||
isUploading: false,
|
isUploading: false,
|
||||||
uploadProgress: 0,
|
uploadProgress: 0,
|
||||||
|
resetFileKey: fileKeyGen(),
|
||||||
})
|
})
|
||||||
|
|
||||||
state = this.initialState()
|
state = this.initialState()
|
||||||
|
@ -122,6 +127,10 @@ class ChatBox extends ImmutablePureComponent {
|
||||||
this.markRead();
|
this.markRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleRemoveFile = (e) => {
|
||||||
|
this.setState({ attachment: undefined, resetFileKey: fileKeyGen() });
|
||||||
|
}
|
||||||
|
|
||||||
onUploadProgress = (e) => {
|
onUploadProgress = (e) => {
|
||||||
const { loaded, total } = e;
|
const { loaded, total } = e;
|
||||||
this.setState({ uploadProgress: loaded/total });
|
this.setState({ uploadProgress: loaded/total });
|
||||||
|
@ -148,14 +157,19 @@ class ChatBox extends ImmutablePureComponent {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='chat-box__attachment'>
|
<div className='chat-box__attachment'>
|
||||||
{attachment.preview_url}
|
<div className='chat-box__filename'>
|
||||||
|
{truncateFilename(attachment.preview_url, 20)}
|
||||||
|
</div>
|
||||||
|
<div class='chat-box__remove-attachment'>
|
||||||
|
<IconButton icon='remove' onClick={this.handleRemoveFile} />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { chatMessageIds, chatId, intl } = this.props;
|
const { chatMessageIds, chatId, intl } = this.props;
|
||||||
const { content, isUploading, uploadProgress } = this.state;
|
const { content, isUploading, uploadProgress, resetFileKey } = this.state;
|
||||||
if (!chatMessageIds) return null;
|
if (!chatMessageIds) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -164,7 +178,7 @@ class ChatBox extends ImmutablePureComponent {
|
||||||
{this.renderAttachment()}
|
{this.renderAttachment()}
|
||||||
<UploadProgress active={isUploading} progress={uploadProgress*100} />
|
<UploadProgress active={isUploading} progress={uploadProgress*100} />
|
||||||
<div className='chat-box__actions simple_form'>
|
<div className='chat-box__actions simple_form'>
|
||||||
<UploadButton onSelectFile={this.handleFiles} />
|
<UploadButton onSelectFile={this.handleFiles} resetFileKey={resetFileKey} />
|
||||||
<textarea
|
<textarea
|
||||||
rows={1}
|
rows={1}
|
||||||
placeholder={intl.formatMessage(messages.placeholder)}
|
placeholder={intl.formatMessage(messages.placeholder)}
|
||||||
|
|
|
@ -184,6 +184,7 @@
|
||||||
.upload-progress {
|
.upload-progress {
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
height: 25px;
|
||||||
|
|
||||||
.fa {
|
.fa {
|
||||||
font-size: 22px;
|
font-size: 22px;
|
||||||
|
@ -200,6 +201,23 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&__attachment {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
font-size: 13px;
|
||||||
|
padding: 0 10px;
|
||||||
|
height: 25px;
|
||||||
|
|
||||||
|
.chat-box__remove-attachment {
|
||||||
|
margin-left: auto;
|
||||||
|
|
||||||
|
.icon-button > div {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&__actions {
|
&__actions {
|
||||||
background: var(--foreground-color);
|
background: var(--foreground-color);
|
||||||
margin-top: auto;
|
margin-top: auto;
|
||||||
|
|
Loading…
Reference in a new issue