Skip to content

Implement MessageList using react-query to get messages instead of having local react state. #194

@AlexShukel

Description

@AlexShukel

Suggested implementation

Fetch messages with useQuery from @tanstack/react-query. Always store single cache entry (set cacheTime to 0). As parameter for query use room identifier and object anchors which has 2 fields: before and after. Depending on type of user event, different anchors will be required:

  1. Handle top reached: set before to first item and after to undefined
  2. Handle bottom reached: set after to last item and before to undefined
  3. Search message X OR next result OR previous result: set both after and before to X

In each case we will have an array of previous messages and array of new messages. New messages are constructed accordingly to the type of user event.

As an alternative to useBoundedArray we will just need one function getClippedArray in order to get resulting messages.

What to do on receiving message?

  1. If noMessagesAfter then clip previous array with new message and directly set cache of currently rendered query.
  2. Else, do nothing

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions