jpuri / react-draft-wysiwyg

A Wysiwyg editor build on top of ReactJS and DraftJS. https://jpuri.github.io/react-draft-wysiwyg
MIT License
6.41k stars 1.16k forks source link

Cancel button call back of upload image model ? #975

Open Ekta968 opened 4 years ago

Ekta968 commented 4 years ago

How to handle cancel button callback to delete uploaded image from database....uploadCallback is used to upload image and then with the help of add button we can add preview image into editor...but how we can delete image from database when click on cancel.

here my code :

`const [editorState ,seteditorState]= useState(EditorState.createEmpty());

  const onEditorStateChange=(editorState)=>{
    console.log("HTML View",editorState.getCurrentContent());
    seteditorState(editorState)
    var val = draftToHtml(convertToRaw(editorState.getCurrentContent()))
    console.log("val>>", val);
  };

  const uploadImageCallBack= (file) =>{
    return new Promise(
        (resolve, reject) => {
          var uploadTask =   storage().ref(`/editor_images/${new Date()}`) .put(file);

uploadTask.on('state_changed', function(snapshot){

  var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
  console.log('Upload is ' + progress + '% done');
  switch (snapshot.state) {
    case storage.TaskState.PAUSED: // or 'paused'
      console.log('Upload is paused');
      break;
    case storage.TaskState.RUNNING: // or 'running'
      console.log('Upload is running');
      break;
  }
}, function(error) {
  reject(error)
}, function() {
  uploadTask.snapshot.ref.getDownloadURL().then(function(downloadURL) {
    console.log('File available at', downloadURL);
    resolve({data: {link: downloadURL}})
  });
});
      }
    );
}
const doCollapseCall = ()=>{
 alert("run")
}

  const toolbar = {
    inline: {
        inDropdown: false,
    },
    list: { inDropdown: true },
    textAlign: { inDropdown: true },
    link: { inDropdown: true },
    history: { inDropdown: true },
    emoji  :  {inDropdown: false},
    image: { uploadCallback: uploadImageCallBack, previewImage: true, 
       alt: { present: true, mandatory: false },
       inputAccept: 'image/gif,image/jpeg,image/jpg,image/png,image/svg',},
};
    `
`<Editor
              editorState={editorState}
              editorClassName="editorClassName"
              toolbarClassName="toolbar-class"
              wrapperClassName="wrapperClassName"
              wrapperStyle={{
                  minHeight: 500,
              }}
              editorStyle={{
                  minHeight: 376,
                  border: "1px solid #F1F1F1",
                  padding: 5,
                  borderRadius: 2,
                  height: "auto",
              }}
              toolbar={toolbar}
              onEditorStateChange={onEditorStateChange}
          />`

Thank you.

NishargShah commented 3 years ago

Any Solution @jpuri?

I check the code but it's used the doCollapse function but it's for a new component, can you accept PR or you will do it yourself?

https://github.com/jpuri/react-draft-wysiwyg/blob/705f518fa516f2839394d706e8b11bfd99734abd/src/controls/Image/Component/index.js#L317