cj-upload
cj-upload copied to clipboard
Reset uploader state
Is there a way to reset the uploader state?
More specifically what I mean, is how can I reset progress and complete?
I don't see this implemented. but it would be really helpful IMO.
BTW thank you for this lib :)
In my apps I am navigating to a new page so the component becomes unmounted. It seems like you’d remove the upload component from the page on success and render a download box or something. I’m up for coming up with a better solution though. Maybe a prop called reset that will immediately reset the state on complete?
In my case I do not want to unmount the component.
I have a single input which the user can use to add files to different contexts, It would be extra helpful to have a method for resetting that we could call at will.
Would adding a prop that resets the state the moment an upload finishes solve the problem?
That would solve it, yes!
Cool, I’ll add this tomorrow On Thu, Oct 5, 2017 at 00:56 Kyriakos Z. [email protected] wrote:
Thar would solve it, yes!
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/navjobs/upload/issues/21#issuecomment-334359027, or mute the thread https://github.com/notifications/unsubscribe-auth/AAbacPpNeFDwNMBvspxH5_oYObiTMqYVks5spGFhgaJpZM4Pt6eH .
Try @navjobs/[email protected] and add reset
to the uploader. It's times like these where I wish I was a better dev 6 months ago, could have made this better code-wise haha
Nice thanks!
I was wondering though, wouldn't it be possible to add a method reset
just like startUpload
so we can call it a will?
The main reason I am asking this is that complete
never becomes true the way it is implemented right now.
sure, ill do that instead and make a new release.
I'm actually not sure of a good way to do this, calling reset will cause a state change inside the render, kind of the reason I wish i didnt have this component be a child as function. Feel free to post some ideal code and I'll see if i can do it that way
I was thinking something more like https://github.com/koox00/upload/commit/013cb7b300db5a53551ecb35a108241c0848d9e2
this way we can reset in the UploadField
:
componentWillReceiveProps(props) {
if (props.complete) {
props.onReset();
}
}
what do you think?
Checking componentWillReceiveProps to do an action is a really bad paradigm, and the way I built this component kind of forces you into bad habits like this. I want to rewrite the uploader so that the state is exposed in your component onUploaderState
prop where you set the state and pass it into the component. this way you can do whatever you want inside that function, so if onUploaderState returns complete:true, you could just set the state to complete:false and reset everything. It would be much more extensible.
Actually isn't possible to reset the uploader's state ?
@bionicvapourboy when upload is complete, reload the page for now (push to the upload page in react router or something), I have this on my list to rewrite this component but it's in the back of it sadly :(
Adding "reset" (bool true) in Uploader props solves the issue. It is not mentioned in readme.md but i found it in your source code. Very useful, maybe an hack like refresh page/remount component would made me move to another component.
I forgot I did add that a month or so back. "maybe an hack like refresh page/remount component would made me move to another component" sorry, i want to remake this way better than it currently is, but i don't have the time right now.