HD-4 added eventlistener for pasteevent

This commit is contained in:
audmaxwell 2019-11-19 17:01:19 -05:00
parent aedb332f68
commit 86c0b151b8
3 changed files with 37 additions and 31 deletions

View File

@ -45,7 +45,7 @@
},
"main": "public/electron.js",
"scripts": {
"start": "HTTPS=true react-scripts start",
"start": "react-scripts start",
"electrify": "npm run build; electron .",
"electrify-nobuild": "electron .",
"build": "react-scripts build",

View File

@ -1,3 +1,3 @@
import AudioPlayer from "./AudioPlayer";
export default AudioPlayer;
export default AudioPlayer;

View File

@ -106,6 +106,10 @@ class Composer extends Component<any, IComposerState> {
: 99999999
});
});
window.addEventListener("paste", (evt: Event) => {
let thePasteEvent = evt as ClipboardEvent;
});
}
componentWillReceiveProps(props: any) {
@ -176,35 +180,7 @@ class Composer extends Component<any, IComposerState> {
multiple: false,
accept: ".jpeg,.jpg,.png,.gif,.webm,.mp4,.mov,.ogg,.wav,.mp3,.flac"
})
.then((media: FileList) => {
let mediaForm = new FormData();
mediaForm.append("file", media[0]);
this.props.enqueueSnackbar("Uploading media...", {
persist: true,
key: "media-upload"
});
this.client
.post("/media", mediaForm)
.then((resp: any) => {
let attachment: Attachment = resp.data;
let attachments = this.state.attachments;
if (attachments) {
attachments.push(attachment);
} else {
attachments = [attachment];
}
this.setState({ attachments });
this.props.closeSnackbar("media-upload");
this.props.enqueueSnackbar("Media uploaded.");
})
.catch((err: Error) => {
this.props.closeSnackbar("media-upload");
this.props.enqueueSnackbar(
"Couldn't upload media: " + err.name,
{ variant: "error" }
);
});
})
.then((media: FileList) => this.actuallyUploadMedia(media))
.catch((err: Error) => {
this.props.enqueueSnackbar("Couldn't get media: " + err.name, {
variant: "error"
@ -213,6 +189,36 @@ class Composer extends Component<any, IComposerState> {
});
}
actuallyUploadMedia(media: FileList) {
let mediaForm = new FormData();
mediaForm.append("file", media[0]);
this.props.enqueueSnackbar("Uploading media...", {
persist: true,
key: "media-upload"
});
this.client
.post("/media", mediaForm)
.then((resp: any) => {
let attachment: Attachment = resp.data;
let attachments = this.state.attachments;
if (attachments) {
attachments.push(attachment);
} else {
attachments = [attachment];
}
this.setState({ attachments });
this.props.closeSnackbar("media-upload");
this.props.enqueueSnackbar("Media uploaded.");
})
.catch((err: Error) => {
this.props.closeSnackbar("media-upload");
this.props.enqueueSnackbar(
"Couldn't upload media: " + err.name,
{ variant: "error" }
);
});
}
getOnlyMediaIds() {
let ids: string[] = [];
if (this.state.attachments) {