digidem / comapeo-mobile

The next version of Mapeo mobile
GNU General Public License v3.0
5 stars 0 forks source link

chore: Re-useable edit observation/track screen #416

Closed ErikSin closed 1 week ago

ErikSin commented 3 weeks ago

Create a new reusable component that holds the UI for the observation edit/observation create (and eventually track edit and track create) screens.

Previously the observation Edit and Observation create screen were the same screen. While they shared the same UI, their functionalities were quite different (eg, different API calls, different back button behaviour). This difference in functionality was handled by detecting the presence of an observationId (the presence of an observationId implied that the observation had already been created, and therefore the user was editing, not creating, it). This meant quite a lot of overhead with trying to determine which actions to take in the screen.

With the introduction of tracks, the same screens would also be used for editing and creating a track. Having 1 component, with 4 different states was going to be difficult to maintain.

This PR introduces a shared UI component. This is designed to be imported and used within a screen, but all the functionality is separated and taken as props, and therefore is controlled by the parent screen. This allows us to have the same UI between several different screens, but have the functionality be modularized and controlled by the parent screen.

In order to keep this PR small, I have only used this shared UI component in a new CreateObservation screen. The previous implementation of the observationEdit screen is still intact and untouched, and that will be refactored in a follow up PR.

image
achou11 commented 1 week ago

@ErikSin can you rebase your PR? it's needs to pull in changes from main branch for the PermissionAudio component that prevents the weird UI i ran into in my PR review earlier.

turns out the issue is in the ThumbnailAndActionTab component, which this PR doesn't really touch too much, but is affected by the issue, which makes it hard to test changes for me (fixed on main)

ErikSin commented 1 week ago

Ran into a strange bug that seems to be introduced by this PR but I can't quite figure out why:

1. Create observation. For the sake of reproducibility, choose the "Animal" category.

2. On editor screen, press the "Details" button.

3. On observation fields screen, press either the header back button or the save button.

After (3), I end up navigating to the map screen instead of back to the editor screen. I would think the bug lives in the ObservationField component, but this PR doesn't touch that 🤔

Interesting, I am unable to reproduce this:

https://github.com/digidem/comapeo-mobile/assets/67773827/02783adf-1c44-4e7f-a034-5a882a7b030a

achou11 commented 1 week ago

hm let me try again - possible that i ran into some weird app state when switching branches and whatnot

ErikSin commented 1 week ago

On another note, the screen is glitchy when moving from observationFields back to the observationCreate.... You can see it jumping up/down slightly

achou11 commented 1 week ago

hm yeah i can't seem to reproduce that issue anymore - must've ran into some edge case related to switching between various branches