Page MenuHomePhabricator

[web] Keyboard support for typeahead [13/13] - Freeze users list when typeahead is visible.
ClosedPublic

Authored by przemek on Dec 27 2022, 5:28 AM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Nov 21, 4:28 AM
Unknown Object (File)
Wed, Nov 13, 5:26 AM
Unknown Object (File)
Wed, Nov 13, 5:26 AM
Unknown Object (File)
Wed, Nov 13, 5:26 AM
Unknown Object (File)
Wed, Nov 13, 5:26 AM
Unknown Object (File)
Mon, Nov 4, 3:21 AM
Unknown Object (File)
Mon, Oct 28, 8:11 AM
Unknown Object (File)
Oct 23 2024, 8:42 PM

Details

Summary

One weird edge case was deleting/adding user to chat/thread when other user had overlay displayed.
Normally overlay is rerendered with newly fetched fresh user list, but it may cause weird shifts in chosen button.
We could solve it by using some extra state to save currently chosen button and then going back to it after list of users change, but I decided to go with simpler solution: when overlay is displayed list of users is frozen until it disappears.
It may result in tries to @ users that were deleted from channel, but it doesn't seem like a huge issue.
In future we may react to it by displaying modal asking if we want to sent invite to such user (or any user that we tried to @, but who was not in out channel).

Test Plan

Added and deleted users using another account and incognito browser.
Freezing worked fine.

Diff Detail

Repository
rCOMM Comm
Branch
feat/typeahead-keyboard-support-2
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

Spotted uncaught bug while testing later on - it caused to freeze users list in wrong situations. Moved frozen users to state in context. It works now.

Fixed problems. Took wrong aproach in the beginning.

web/chat/chat-input-bar.react.js
598–611

We save users currently in thread.

618

We use frozen users instead of threadMembers

web/chat/typeahead-tooltip.react.js
49–56

We clear frozen members only when tooltip is unmounted.

tomek requested changes to this revision.Jan 4 2023, 6:49 AM
tomek added inline comments.
web/input/input-state.js
39

I don't think it is a good idea that input state knows about internal implementation of a tooltip. We shouldn't keep frozenThreadMembers here.

When we show a typeahead, it should save the list (probably in state) and update it only when it becomes invisible.

This revision now requires changes to proceed.Jan 4 2023, 6:49 AM
web/chat/chat-input-bar.react.js
598–610

Is this code correct? What happens when a typeahead is hidden and users list is updated a couple of times? It seems like we probably need an additional flag instead of using frozenThreadMembers for two purposes: storing members and as a flag.

web/chat/typeahead-tooltip.react.js
51–53

We should avoid a magic value (empty array) that has a special meaning. Instead we should have a function that resets frozen members.

przemek added inline comments.
web/input/input-state.js
39

I feel like there's no better place for it. We can't keep it inside tooltip component as it's rendered based on SuggestedUsers (that are chosen from ThreadMembers - now frozen). ConnectedChatInputbar selects threadMembers so its state feels like natural place for keeping frozen copy.

przemek marked 2 inline comments as done.

Added flag keepUpdatingThreadMembers which is set false on mounting tooltip. It causes users to threadMemebrs to get frozen.

tomek requested changes to this revision.Jan 9 2023, 3:11 AM

We're really close!

web/chat/chat-input-bar.react.js
591–602 ↗(On Diff #20627)

This is correct but can be made more efficient. Currently, we always have to rely on an effect to update the members, but the effect isn't necessary at all.

To avoid the effect, we can do two things:

  1. Every time a function that updates threadMembers is called, we can check if keepUpdatingThreadMembers and update frozenThreadMembers if appropriate
  2. Every time keepUpdatingThreadMembers is set to true, update frozenThreadMembers

These two changes can be made in setTypeaheadState which will make it more performant and easier to use.

592 ↗(On Diff #20627)

Maybe rename to areThreadMembersFrozen?

This revision now requires changes to proceed.Jan 9 2023, 3:11 AM

We've talked about that issue with Tomek. We've tried to find better solution, but it seems hard and we don't get huge benefits here.
Tomek has brought up issue, that calling useEffect that changes state will cause rerender of component. It's single rerender and every value above is memoised, so it shouldn't be huge overhead.
We've decided to go with current solution then.

Please don't forget to update the name (if you agree) before landing

This revision is now accepted and ready to land.Jan 11 2023, 8:47 AM