-
Notifications
You must be signed in to change notification settings - Fork 338
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
Remove pictrsDeleteToast
usage from PostForm
#1284
Remove pictrsDeleteToast
usage from PostForm
#1284
Conversation
…, fix infinite loading bug if upload error occured
} else { | ||
toast(JSON.stringify(res), "danger"); | ||
} | ||
} else if (res.state === "failed") { | ||
console.error(res.msg); | ||
toast(res.msg, "danger"); | ||
i.setState({ imageLoading: false }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Caught an infinite loading bug here, this resolves it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
form: { | ||
url, | ||
}, | ||
imageDeleteUrl: "", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If form.url
is changed, we can assume user wants to abandon image – so imageDeleteUrl
should be cleared.
imageDeleteUrl: "", | ||
imageLoading: false, | ||
form: { | ||
url: "", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clearing the form.url
is important here to remove the now-deleted image.
pictrsDeleteToast(...)
usage from PostForm
, handle delete_url
in state, add buttonpictrsDeleteToast
usage from PostForm
…ithub.com/alectrocute/lemmy-ui into AA/remove-pictrsdeletetoast-from-postform
@@ -269,6 +270,17 @@ export class PostForm extends Component<PostFormProps, PostFormState> { | |||
{url && isImage(url) && ( | |||
<img src={url} className="img-fluid" alt="" /> | |||
)} | |||
{this.state.imageDeleteUrl && ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using this.state.imageDeleteUrl
for visibility of this button ensures it only appears alongside uploaded images. It's cleared upon change of form.url
, so should be safe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is definitely easier to work with than the toast.
This PR stores an uploaded image's
delete_url
in state instead and makes visible a "delete" button which fetches thedelete_url
and removes the image/url. Also fixes infinite loading bug as mentioned in this PR's comments. Resolves #1255.Future thought: It would be really nice to move away from
pictrsDeleteToast
entirely.EmojisForm
is an easy candidate for a similar treatment to this PR. We'll need to add some more complicated functionality/UI for multiple image uploads, like inMarkdownTextarea
, so maybe let's save that for last. 😅Thanks, Lemmy team!