Skip to content
This repository has been archived by the owner on Apr 26, 2022. It is now read-only.

Reset uploader state #21

Open
koox00 opened this issue Oct 4, 2017 · 15 comments
Open

Reset uploader state #21

koox00 opened this issue Oct 4, 2017 · 15 comments

Comments

@koox00
Copy link

koox00 commented Oct 4, 2017

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

@zackify
Copy link
Contributor

zackify commented Oct 4, 2017

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?

@koox00
Copy link
Author

koox00 commented Oct 4, 2017

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.

@zackify
Copy link
Contributor

zackify commented Oct 4, 2017

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

@koox00
Copy link
Author

koox00 commented Oct 5, 2017

That would solve it, yes!

@zackify
Copy link
Contributor

zackify commented Oct 5, 2017 via email

@zackify
Copy link
Contributor

zackify commented Oct 5, 2017

Try @navjobs/upload@3.0.10 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

@koox00
Copy link
Author

koox00 commented Oct 9, 2017

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.

@zackify
Copy link
Contributor

zackify commented Oct 9, 2017

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

@zackify
Copy link
Contributor

zackify commented Oct 9, 2017

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

koox00 added a commit to koox00/upload that referenced this issue Oct 12, 2017
@koox00
Copy link
Author

koox00 commented Oct 12, 2017

I was thinking something more like koox00@013cb7b

this way we can reset in the UploadField:

componentWillReceiveProps(props) {
  if (props.complete) {
    props.onReset();
  }
}

what do you think?

koox00 added a commit to koox00/upload that referenced this issue Oct 12, 2017
@zackify
Copy link
Contributor

zackify commented Oct 12, 2017

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.

@bionicvapourboy
Copy link

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

@zackify
Copy link
Contributor

zackify commented Dec 6, 2017

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

@bionicvapourboy
Copy link

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.

@zackify
Copy link
Contributor

zackify commented Dec 6, 2017

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants