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

Add delete button to Lightbox #41

Merged
merged 15 commits into from
May 6, 2024

Conversation

jonathan-waarneming-nl
Copy link
Collaborator

@jonathan-waarneming-nl jonathan-waarneming-nl commented May 2, 2024

Displays a delete button in Lightbox. If there is also content, the button is displayed below this content.

Part of: https://github.com/observation/app/issues/349

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Zoals ook gezegd in de andere PR voor dit issue: ik weet niet hoe ik deze test moet implementeren:
"Swiping to the left and pressing the delete button, will delete the second photo".

Dit omdat ik niet goed inzie hoe het swipen kan gesimuleerd worden.

Copy link
Member

Choose a reason for hiding this comment

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

Een swipe doen kan zo te zien niet via testing library, maar second best is om een onImageIndexChange call te triggeren vanuit ImageView. Zou dat kunnen?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Je kunt zo'n onImageIndexChange triggeren als je met een testID erbij kan, maar dat was nu niet 't geval.
Wat ik nu heb gedaan is een mock met requireActual, die de mock inject. Dus 't is uiteindelijk gelukt.

@@ -52,6 +60,15 @@ const getLightboxFooterComponent =
)}
{content && <View style={styles.footerItem}>{content}</View>}
</View>
{onPressDelete && (
Copy link
Collaborator Author

@jonathan-waarneming-nl jonathan-waarneming-nl May 2, 2024

Choose a reason for hiding this comment

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

@SjaakSchilperoort we hadden het eerst over om de button(s) om de mogelijk aanwezige content te plaatsen, maar ik zag dat de buttons in het design een redelijk grote margin hebben en dus heb ik dit maar onderaan gezet.
Een voordeel is wel dat er geen snapshot changes zijn voor componenten die de onPressDelete niet meegeven.

Copy link
Member

@SjaakSchilperoort SjaakSchilperoort left a comment

Choose a reason for hiding this comment

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

Paar opmerkingen.

Terzijde: ik zie drie commits met de beschrijving "WIP". Kun je de commits waar een PR uit bestaat begrijpelijk maken door altijd te beschrijven wat het doel van een commit is? Ik doe het zelf ook altijd. Het is dan tijdens een code review gemakkelijker om te achterhalen waar een bepaalde code-wijziging voor nodig is. Als je enkel wat vergeten bent in een vorige commit kun je natuurlijk ook commits samenvoegen. Of als dat voor de begrijpelijkheid beter is, kun je ook de volgorde van commits aanpassen. Kost weinig moeite, maar is voor een reviewer erg fijn.

Copy link
Member

Choose a reason for hiding this comment

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

Een swipe doen kan zo te zien niet via testing library, maar second best is om een onImageIndexChange call te triggeren vanuit ImageView. Zou dat kunnen?

const [imageIndexAfterSwipe, setImageIndexAfterSwipe] = useState<number>()

const imageIndex = index ?? 0
Copy link
Member

Choose a reason for hiding this comment

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

Ik zou swipe niet in de naam van deze velden gebruiken. Dit is te specifiek en swipe-support is ook niet de verantwoordelijkheid van deze component maar van ImageView. Hier een suggestie:

Suggested change
const [imageIndexAfterSwipe, setImageIndexAfterSwipe] = useState<number>()
const imageIndex = index ?? 0
const [currentImageIndex, setCurrentImageIndex] = useState<number>()
const initialImageIndex = index ?? 0

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ja, die is wel elegant


const imageIndex = index ?? 0

const onPressDelete = onDelete ? () => onDelete(imageIndexAfterSwipe ?? imageIndex) : undefined
Copy link
Member

Choose a reason for hiding this comment

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

Zou de default imageIndex naar de state kunnen? Dus:

  const initialImageIndex = index ?? 0
  const [currentImageIndex, setCurrentImageIndex] = useState<number>(initialImageIndex)

Dan wordt het hier simpeler:

  const onPressDelete = onDelete ? () => onDelete(currentImageIndex) : undefined

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nee.
Het component is altijd aanwezig. Dus de state die je aanmaakt met useState is altijd hetzelfde object.

Als je 3 foto's hebt en je opent de eerste en slide naar de laatste, is de waarde van currentImageIndex 2.
Je sluit de Lightbox en opent weer de eerste. Op dit moment is de waarde currentImageIndex nog steeds 2 (ipv 0).

Ik dacht dat mijn methode dit afving, maar ik zie dat ik hetzelfde probleem heb...

Wat wel zou kunnen werken is alleen de Lightbox tonen als er een foto is geselecteerd. Dan kunnen we jouw methode gebruiken en is 't wat makkelijker. Dus in de Observation app:

{photoIndex && 
  <Lightbox 
    index={photoIndex} 
    onClose={() => setPhotoIndex(undefined)} 
    photos={uris} 
    onDelete={onDelete} /> 
}

Wat vind je hiervan?

@jonathan-waarneming-nl
Copy link
Collaborator Author

Kun je de commits waar een PR uit bestaat begrijpelijk maken door altijd te beschrijven wat het doel van een commit is?

Ik begrijp 't doel, maar nieuwe code in de RN components is niet bepaald fijn om te maken. Je moet een commit maken, pushen, ophalen in de andere repo, en dan kom je erachter dat 't niet klopt. Dus na een tijdje ben je 't wel zat. Dus als er "WIP" staat (wat ik volgens mij zelden doe in andere branches) moet je lezen als "Weer fout, nu dan?".

@SjaakSchilperoort
Copy link
Member

Kun je de commits waar een PR uit bestaat begrijpelijk maken door altijd te beschrijven wat het doel van een commit is?

Ik begrijp 't doel, maar nieuwe code in de RN components is niet bepaald fijn om te maken. Je moet een commit maken, pushen, ophalen in de andere repo, en dan kom je erachter dat 't niet klopt. Dus na een tijdje ben je 't wel zat. Dus als er "WIP" staat (wat ik volgens mij zelden doe in andere branches) moet je lezen als "Weer fout, nu dan?".

Die werkwijze levert dus rommel op in de commits, maar dat kun je toch opruimen voordat je een review opent?

Ik dacht dat je in package.json ook naar een directory op je file system kon verwijzen. Dan kun je wijzigingen in de componenten uitproberen zonder de components-lib steeds te moeten pushen. Als dat niet goed werkt dan kun je ook de component naar de observation app kopiëren, daar ontwikkelen, en als alles werkt de nieuwe versie weer terug te kopiëren.

@jonathan-waarneming-nl
Copy link
Collaborator Author

Die werkwijze levert dus rommel op in de commits, maar dat kun je toch opruimen voordat je een review opent?

Ik dacht niet dat dit erg was, maar zal er voortaan aan denken.

Ik dacht dat je in package.json ook naar een directory op je file system kon verwijzen.

Dit zal 't leven veel gemakkelijker maken, zal eens kijken

@jonathan-waarneming-nl jonathan-waarneming-nl force-pushed the feature/add-delete-button branch from eba0817 to 83e699c Compare May 6, 2024 09:16
/>
)
const Lightbox = ({ index, onClose, onDelete, photos, title, description, content, style }: Props) => {
const initialIndex = index ?? 0
Copy link
Member

Choose a reason for hiding this comment

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

Of dit om consistent te blijven?

Suggested change
const initialIndex = index ?? 0
const initialImageIndex = index ?? 0

marginHorizontal: theme.margin.common,
},
buttonContainer: {
width: '50%',
Copy link
Member

Choose a reason for hiding this comment

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

Dit gaat mis als we drie buttons hebben. Ik denk dat het beter is om dit te vervangen door flex: 0.5, dat gaat wel goed bij >2 buttons.

Copy link
Member

@SjaakSchilperoort SjaakSchilperoort left a comment

Choose a reason for hiding this comment

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

👌🏻

Copy link
Contributor

@anoukdriessen anoukdriessen left a comment

Choose a reason for hiding this comment

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

Wat mij betreft prima zo 👍

@jonathan-waarneming-nl jonathan-waarneming-nl merged commit 54e9a75 into develop May 6, 2024
2 checks passed
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.

3 participants