NattapongSiri / covid_cb

MIT License
2 stars 1 forks source link

Make covid-client support history #5

Open NattapongSiri opened 4 years ago

NattapongSiri commented 4 years ago

Main question

Shall user able to resend a failed message ?

It's quite simple to add a button for resend but it need a mechanism to trigger it parent to resend this failed message. There's multiple ways to do this.

  1. Attach a function to resend to the message itself. When user click the button we can directly call this function.
  2. Propagate event back with failed message so the ancestor container that responsible for sending message know that user want to send this message again.

Both of it will need some mechanism to update a failed message status. For the first approach, this will be easy as message itself know when the resend is requested and the status of current request.

The second approach will be a bit troublesome. It need almost entire message object back to ancestor so it can update the object status. However, by React architecture, ancestor object need to be the one to update the state, otherwise, the state/props will be out of sync. This can be inefficient to scan through ancestor message array.

Shall user able to hit up/down button to navigate through the recent user input ?

The current design is to have single array contains both user side and response from server side. If user hit up arrow, it need to scan back in array to find one previous user message. If user hit down, it shall find next user message in array. This will require one extra state variable to track where user is navigating in history. Whenever use edit the message, what shall this state be ? If user choose to edit one old message before send then user hit up/down to drop the editing message, would it make more sense to continue from previous navigating state ? If user hit send, shall the state reset ?

Potential affected code

For resend failed message approach 1:

  1. Make retry button in https://github.com/NattapongSiri/covid_cb/blob/468811f9b80c5749739928995b26516463b69b29/covid-client/react/src/components/ChatMessage/index.tsx#L101-L105
  2. Pass callback down to message in https://github.com/NattapongSiri/covid_cb/blob/468811f9b80c5749739928995b26516463b69b29/covid-client/react/src/components/ChatDialog.tsx#L40-L80
  3. Add callback for retry action in https://github.com/NattapongSiri/covid_cb/blob/468811f9b80c5749739928995b26516463b69b29/covid-client/react/src/components/commons/Message.ts#L35-L59
  4. Make a callback for retry in https://github.com/NattapongSiri/covid_cb/blob/468811f9b80c5749739928995b26516463b69b29/covid-client/react/src/pages/ChatPage/index.tsx#L32

For resend failed message approach 2: ???

For history navigation:

  1. Find a message to show in in put in https://github.com/NattapongSiri/covid_cb/blob/468811f9b80c5749739928995b26516463b69b29/covid-client/react/src/pages/ChatPage/index.tsx#L26
  2. Config component to propagate up/down event back to this component in https://github.com/NattapongSiri/covid_cb/blob/468811f9b80c5749739928995b26516463b69b29/covid-client/react/src/pages/ChatPage/index.tsx#L177
  3. Register up/down key event listener in https://github.com/NattapongSiri/covid_cb/blob/468811f9b80c5749739928995b26516463b69b29/covid-client/react/src/components/ChatInput/index.tsx#L44-L49