duolicious / duolicious-frontend

The frontend of the Duolicious dating app
https://duolicious.app/
GNU Affero General Public License v3.0
32 stars 12 forks source link

Remember last tab #274

Closed gc closed 2 months ago

gc commented 2 months ago

Remembers the last tab, works pretty simply - store the nav state after each navigation, load it as the initial state on mount. I went through mostly everything and don't see any issues. I did not test it on android/mobile, only on web (chrome).

Test cases: Test each screen, being in menus, chats, refreshing a new/empty chat, profiles, options (e.g. editing search filter), etc, logging in/out, or any other screens/things not mentioned. Refresh in each and observe no errors.

There was an issue with the chat screen, as it kind of assumed the home page would be loaded first, so it has time to connect before you go to chats. If you loaded directly into a chat, it would instantly try to fetch messages, but at that point its not connected yet, and it would break the page. So I've added a xmpp.ready promise so anything can make sure its ready before it tries to use the connection.

If the navigation state is invalid (e.g. a screen that doesnt exist), it seems to not cause any issues, and just goes to the home page.

stale:true is always set on the stored state, because:

If you want React Navigation to fix invalid state, you need to make sure that you don't have stale: false in the state object. State objects with stale: false are assumed to be valid state objects and React Navigation won't attempt to fix them.

one more caveat:

Warning: Serializable State Each param, route, and navigation state must be fully serializable for this feature to work. Typically, you would serialize the state as a JSON string. This means that your routes and params must contain no functions, class instances, or recursive data structures. React Navigation already warns you during development if it encounters non-serializable data, so watch out for the warning if you plan to persist navigation state.

I haven't seen this warning.

Closes https://github.com/duolicious/duolicious-frontend/issues/162

gc commented 2 months ago

@duogenesis This is ready now. I recommend to test this thoroughly yourself though.