Giter Club home page Giter Club logo

Comments (3)

 avatar commented on September 7, 2024 2

To complete my previous post, I did find a workaround to make my component works:

I added a componentWillUnmount to nullify the dropzone instance var:

    componentWillUnmount() {
        console.log('componentWillUnmount dropzone  out', dropzone);
        dropzone = null;
    }

Then I added a test on this dropzone instance var in removedfile handler:

removedfile: (fileObj) => {
        if (!dropzone) {
            console.log('dzRemovedFile dropzone  out', dropzone);
            return;
        }
        console.log('dzRemovedFile', fileObj, dzConfig.params.uploadTimestamp);
        if (fileObj.status === 'success') {
            $.ajax({
                url: '/upload',
...

from react-dropzone-component.

felixrieseberg avatar felixrieseberg commented on September 7, 2024

Hey, thanks for reporting! I think that I fixed your issue with the just released 0.6. Let me know if that helps!

from react-dropzone-component.

 avatar commented on September 7, 2024

Hi Felix,

I have the issue with 0.6.0 .

My understanding of your hack is that you check some files are still in process to be uploaded. In my tests, all files are already uploaded.

The issue occurs only when this.dropzone.destroy() is called which will trigger the removedfile handler. I don't see the reason to call the removedfile handler at this stage.

Below the code of my component that uses react-dropzone-component:

import React from 'react';
import _ from 'lodash';

import DropzoneComponent from 'react-dropzone-component';
// https://www.npmjs.com/package/react-dropzone-component

import growl from '../UI/growl';

var dropzone;

var dzComponentConfig = {
    allowedFiletypes: [
        '.doc', '.jpg', '.mp3', '.pdf', '.txt'
    ],
    showFiletypeIcon: true,
    postUrl: '/upload'
};

var dzConfig = {
    autoProcessQueue: true,
    addRemoveLinks: true,
    uploadMultiple: true,
    maxFileSize: 10,
    maxFiles: 10,
    params: {
        uploadTimestamp: ''
    },
    accept: (file, done) => {
        var doneMessage = null;
        _.find(dropzone.files, (value, key) => {
            if (value.name === file.name && _.contains([
                'success', 'queued'
            ], value.status)) {
                doneMessage = 'Duplicated file, it won\'t be imported';
                growl(doneMessage, {
                    type: 'danger'
                });
                return true;
            }
        });
        done(doneMessage);
    }
};

var dzEventHandlers = {

    // Init callback to retrieve Dropzone instance
    init: (DzObject) => {
        dropzone = DzObject;
        // console.log('dzInit', DzObject);
    },
    // All of these receive the event as first parameter:
    drop: null,
    dragstart: null,
    dragend: null,
    dragenter: null,
    dragover: null,
    dragleave: null,
    // All of these receive the file as first parameter:
    addedfile: null,
    removedfile: (fileObj) => {
        console.log('dzRemovedFile', fileObj, dzConfig.params.uploadTimestamp);
        if (fileObj.status === 'success') {
            $.ajax({
                url: '/upload',
                dataType: 'json',
                type: 'DELETE',
                data: {
                    fileName: fileObj.name,
                    uploadTimestamp: dzConfig.params.uploadTimestamp
                },
                success: (data) => {
                    // console.log('dzRemovedFile', 'success', data);
                },
                error: (xhr, status, err) => {
                    // console.error('dzRemovedFile', status, err.toString());
                }
            });
        }
    },
    thumbnail: null,
    error: null,
    processing: null,
    uploadprogress: null,
    sending: null,
    success: null,
    complete: null,
    canceled: null,
    maxfilesreached: null,
    maxfilesexceeded: null,
    // All of these receive a list of files as first parameter
    // and are only called if the uploadMultiple option
    // in djsConfig is true:
    processingmultiple: null,
    sendingmultiple: null,
    successmultiple: null,
    completemultiple: null,
    canceledmultiple: null,
    // Special Events
    totaluploadprogress: null,
    reset: null,
    queuecompleted: null
};

export default class InputDropzone extends React.Component {
    constructor(props) {
        super(props);

        this.state = {
            className: '',
            errorMessage: '',
            isValid: false
        };
    }

    componentWillMount() {
        dzConfig.params.uploadTimestamp = this.props.inputParams.uploadTimestamp;
        dzComponentConfig.postUrl = '/upload?uploadTimestamp=' + this.props.inputParams.uploadTimestamp;
        // console.log('componentWillMount',  this.props.inputParams.uploadTimestamp, dzComponentConfig);
    }

    render() {
        return (
            <div className={'form-group ' + this.state.className}>
                <label className='control-label' htmlFor={this.props.name.toLowerCase()}>{this.props.label}</label>
                <span className='text-warning pull-right'>{this.state.errorMessage}</span>
                <DropzoneComponent
                    config={dzComponentConfig}
                    djsConfig={dzConfig}
                    eventHandlers={dzEventHandlers}
                    name={this.props.name.toLowerCase()}
                    {...this.props}
                />
            </div>
        )
    }
};

InputDropzone.propTypes = {
    label: React.PropTypes.string,
    name: React.PropTypes.string,
    placeholder: React.PropTypes.string
};

InputDropzone.defaultProps = {
    label: '',
    name: '',
    placeholder: ''
};

from react-dropzone-component.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.