cj-upload icon indicating copy to clipboard operation
cj-upload copied to clipboard

Reset uploader state

Open koox00 opened this issue 7 years ago • 15 comments

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 :)

koox00 avatar Oct 04 '17 16:10 koox00

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?

zackify avatar Oct 04 '17 16:10 zackify

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.

koox00 avatar Oct 04 '17 18:10 koox00

Would adding a prop that resets the state the moment an upload finishes solve the problem?

zackify avatar Oct 04 '17 18:10 zackify

That would solve it, yes!

koox00 avatar Oct 05 '17 04:10 koox00

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 .

zackify avatar Oct 05 '17 05:10 zackify

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

zackify avatar Oct 05 '17 18:10 zackify

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.

koox00 avatar Oct 09 '17 18:10 koox00

sure, ill do that instead and make a new release.

zackify avatar Oct 09 '17 20:10 zackify

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

zackify avatar Oct 09 '17 20:10 zackify

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?

koox00 avatar Oct 12 '17 07:10 koox00

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.

zackify avatar Oct 12 '17 13:10 zackify

Actually isn't possible to reset the uploader's state ?

bionicvapourboy avatar Dec 06 '17 09:12 bionicvapourboy

@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 :(

zackify avatar Dec 06 '17 14:12 zackify

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.

bionicvapourboy avatar Dec 06 '17 14:12 bionicvapourboy

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.

zackify avatar Dec 06 '17 15:12 zackify