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

Remove pictrsDeleteToast usage from PostForm #1284

Conversation

alectrocute
Copy link
Contributor

@alectrocute alectrocute commented Jun 14, 2023

This PR stores an uploaded image's delete_url in state instead and makes visible a "delete" button which fetches the delete_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 in MarkdownTextarea, so maybe let's save that for last. 😅

Screenshot 2023-06-14 at 4 36 01 PM Screenshot 2023-06-14 at 4 45 13 PM

Thanks, Lemmy team!

…, 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 });
Copy link
Contributor Author

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.

Copy link
Member

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: "",
Copy link
Contributor Author

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: "",
Copy link
Contributor Author

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.

@alectrocute alectrocute changed the title Remove pictrsDeleteToast(...) usage from PostForm, handle delete_url in state, add button Remove pictrsDeleteToast usage from PostForm Jun 14, 2023
@@ -269,6 +270,17 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
{url && isImage(url) && (
<img src={url} className="img-fluid" alt="" />
)}
{this.state.imageDeleteUrl && (
Copy link
Contributor Author

@alectrocute alectrocute Jun 14, 2023

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.

Copy link
Member

@SleeplessOne1917 SleeplessOne1917 left a 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.

@SleeplessOne1917 SleeplessOne1917 merged commit 148c795 into LemmyNet:main Jun 15, 2023
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.

[Bug]: Clicking on "delete image" alert didnt remove image from form
2 participants