Add confirm dialog for uploading long lines as a file

This commit is contained in:
Max Leiter 2021-11-15 23:55:20 -08:00
parent b6819b6dfc
commit 2b0beac1d9
No known key found for this signature in database
GPG key ID: A3512F2F2F17EBDA

View file

@ -267,22 +267,7 @@ export default {
this.setInputSize();
};
if (this.$store.state.serverConfiguration.fileUpload) {
const lines = 1 + (text.match(/\n/g) || "").length;
// TODO: Offer a confirmation to user whether they want to upload
if (lines > 3 || text.length > 700) {
resetInput();
const file = new File([text], "paste.txt", {
type: "text/plain",
});
upload.triggerUpload([file]);
return false;
}
}
const sendMessage = () => {
resetInput();
// Store new message in history if last message isn't already equal
@ -308,6 +293,39 @@ export default {
}
socket.emit("input", {target, text});
};
if (this.$store.state.serverConfiguration.fileUpload) {
const lines = 1 + (text.match(/\n/g) || "").length;
if (lines > 3 || text.length > 700) {
eventbus.emit(
"confirm-dialog",
{
title: "Upload as file?",
text: `You're trying to send a lot of text. Would you like to upload it?`,
button: "Upload",
},
(result) => {
if (!result) {
sendMessage();
return;
}
resetInput();
const file = new File([text], "paste.txt", {
type: "text/plain",
});
upload.triggerUpload([file]);
}
);
return false;
}
}
sendMessage();
},
onUploadInputChange() {
const files = Array.from(this.$refs.uploadInput.files);