Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement to toast.promise #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

winston0410
Copy link

This PR aims to solve the following issues for toast.promise

  • support dynamic toast message based on promise's result, fallback to the static message provided initially

  • handle edge case where toast.loading has been set with {duration: Infinity}, and toast.success and toast.error will not go away as well

The only thing that I am not sure is why is resolveValue function used there previously.

@vercel
Copy link

vercel bot commented Feb 8, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
svelte-french-toast ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 8, 2023 at 9:38PM (UTC)

@winston0410
Copy link
Author

@kbrgl what do you think about this?

})
.catch((e) => {
toast.remove(id)
toast.error(msgs.error ?? e, {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p can be an object, right? what if I want to use from the p a specific property?

Example:
p = { errorMessage: "Something went wrong" } - in this case, I want to use p.errorMessage.

Copy link

@arthurparaschiv arthurparaschiv Mar 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already possible - that is the purpose of resolveValue

toast.promise(
  new Promise((resolve) => resolve({
    successMsg: 'Success from promise'
  })),
  {
    loading: 'Laoding',
    success: function(result) {
      return result.successMsg;
    },
    error: 'Error',
  }
)

You can pass a function instead of a string

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

Successfully merging this pull request may close these issues.

2 participants