Skip to content
This repository was archived by the owner on Jan 21, 2023. It is now read-only.

Comments

Add button that removes an image#134

Merged
styfle merged 4 commits intovercel:mainfrom
spinks:feat-remove-image
Aug 27, 2020
Merged

Add button that removes an image#134
styfle merged 4 commits intovercel:mainfrom
spinks:feat-remove-image

Conversation

@spinks
Copy link
Contributor

@spinks spinks commented Aug 22, 2020

Hi this adds the ability to remove images after they are added, this would close #129.

Have done a good amount of testing and works correctly consistently, including cases where there may be empty width/height arrays.

@spinks spinks requested a review from styfle as a code owner August 22, 2020 22:57
@vercel
Copy link

vercel bot commented Aug 22, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/vercel/og-image/jmit3yucz
✅ Preview: https://og-image-git-fork-spinks-feat-remove-image.vercel.vercel.app

Copy link

@rfoel rfoel left a comment

Choose a reason for hiding this comment

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

You might want to make the button wider in this case
image

The calc + 2px is to account for inconsistency with the other inputs
and selectors which appear to be 2px wider than 100% (presumably from
border)
Copy link
Member

@styfle styfle left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! 🎉

I left a small suggestion

The array has to be spread before filtering.
This is for the case where only a later image has a defined width/height
In those cases the width/height array would be defined as [4: 350]
for example.
Filtering on that array would give unexpected result.
The spreading creates the full array and then filters correctly.
label: `Remove Image ${i + 2}`,
onclick: (e: MouseEvent) => {
e.preventDefault();
const filter = (arr: any[]) => [...arr].filter((_, n) => n !== i + 1);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const filter = (arr: any[]) => [...arr].filter((_, n) => n !== i + 1);
const filter = (arr: string[]) => arr.filter((_, n) => n !== i + 1);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Happy to correct the type.

The spreading of the array is needed however; if for example a user only sets the width/height of the 4th image it will make those arrays defined as [4: 350]. The suggested method leads to the width/height arrays being filtered incorrectly, as the leading undefineds are not created .

See https://codepen.io/spinks_/pen/xxVdPBN for how the two filters apply would apply in this case.

At least this is what I found testing it, doing it with the suggested method leads to the widths/heights being moved around incorrectly due to that behaviour.

Copy link
Member

Choose a reason for hiding this comment

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

Nice catch, sounds good 👍

@styfle styfle merged commit 9b185b0 into vercel:main Aug 27, 2020
noahflk pushed a commit to noahflk/og-image that referenced this pull request Apr 15, 2021
* Add button that removes an image

* Make remove button 100% width

The calc + 2px is to account for inconsistency with the other inputs
and selectors which appear to be 2px wider than 100% (presumably from
border)

* Make splice/filter operation clearer

The array has to be spread before filtering.
This is for the case where only a later image has a defined width/height
In those cases the width/height array would be defined as [4: 350]
for example.
Filtering on that array would give unexpected result.
The spreading creates the full array and then filters correctly.

Co-authored-by: Steven <steven@ceriously.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Frontend should be able to remove an extra image

3 participants