You show the modal according to the value of the showModal property in the UploadModal component:
Click the Upload button for the modal:
Upload an Image or a Video
On a click of each of the Upload buttons on the modal, the startUpload method is called but with different arguments. Create that method as follows:
startUpload launches the upload widget, which enables you to upload images or videos. After the upload, depending on which button was clicked, set the value to reflect the banner or trailer model.
Besides cloud_name, you must also create upload_preset, unsigned, to enable uploads. To do so, fill in the fields on Cloudinary's Upload settings page under the upload prest section.
The upload widget uses another library for modularity. Add the following code below the scripts in the public/index.html file:
Clicking the Upload button on the modal displays this widget:
Generate an Upload Event
The form contains an attached handleUpload event, which ensures that on a click of the Submit button, the titles and IDs of the media content are displayed. handleUpload checks if those values are available before generating an event to the parent component for an upload.
Add this code to the methods object:
Upload to the Server
Recall that the element for UploadModal reads like this:
The uploadToServer method is the handler for the event generated in the child component. Create uploadToServer in the methods object:
uploadToServer pushes to the server and updates the list with the new entry. It also hides the modal.