Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve and Extend Input classes for Mentions and Drafts. #42

Merged
merged 3 commits into from
Jul 1, 2024

Conversation

jpauloruschel
Copy link
Collaborator

@jpauloruschel jpauloruschel commented Jun 27, 2024

Description

Linear: https://linear.app/gather-town/issue/APP-7842/implement-fork-changes

This PR follows up on #41 in supporting Mentions on the Gather App. It provides the necessary support for https://github.com/gathertown/gather-town/pull/25766

The changes are around 2 components:

  • MessageInput: Adds support for all functionalities Gather App needs to make this the main message input component
    • Add support for custom DraftMessage (also a new type), which is the data required for an unsent message
    • Add customization for attachments (custom onPaste and renderers)
  • SuggestedMentionListView: UX improvements and made extensible (custom rendering)

Test Plan

  • Test these fork changes without new mentions logic, nothing breaks
  • Test these fork changes with new mentions logic, validate that UI works as expected:

Mentions in input with custom rendering

Screenshot 2024-06-27 at 19 44 55

Mentions in edit with custom rendering

Screenshot 2024-06-27 at 19 48 04

Attachment preview

Screenshot 2024-06-27 at 19 44 36

CC

@gathertown/chat

@jpauloruschel jpauloruschel marked this pull request as ready for review June 27, 2024 18:48
Comment on lines +27 to +30
if (customOnPaste && customOnPaste(e)) {
// custom logic already handled input, exit here
return;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is customOnPaste conditionally passed in?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or else it would early execute every time even if there isn't anything to paste right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

customOnPaste from our flows is always defined. This entire function usePaste is hooked into the onPaste of the input div component, so our callback gets called every time there's a paste event in the div. The idea here is that we have a nice way of getting the callback first and handling it ourselves before letting UIKit do its thing.

src/ui/MessageInput/index.tsx Show resolved Hide resolved
src/ui/MessageInput/index.tsx Show resolved Hide resolved
Copy link
Collaborator

@karenying karenying left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think just need to remove customOnPaste cuz it's unused?

src/types.ts Outdated
// fork note: the minimum amount of information needed to save and restore
// an *unsent* message as a draft
export interface DraftMessage {
messageId: number | null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why we need a special DraftMessage type?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! DraftMessage is used to support save/load of draft messages that have mentions with minimal code changes and maximum compatibility with UIKit. UIKit already has all code related to extracting, displaying, sending, et, of messages with mentions, and it only requires the data present in the DraftMessage interface. This is the code that is also used for "editing" messages.

The DraftMessage interface is also handy as the interface between Gather-Browser <-> UIKIt, and the draft code.

The alternative would be us implementing additional custom code which handles extracting, saving, and re-loading draft messages that have mentions.

@jpauloruschel
Copy link
Collaborator Author

i think just need to remove customOnPaste cuz it's unused?

customOnPaste is used as the handleFilePaste callback, we cannot remove the code without removing the feature of pasting files

@jpauloruschel jpauloruschel merged commit 70783bf into main Jul 1, 2024
mtdurling pushed a commit that referenced this pull request Jul 10, 2024
* Improve and Extend Input classes for Mentions and Drafts.

* Add fork note comment.

* Improve types.
mtdurling pushed a commit that referenced this pull request Jul 11, 2024
* Improve and Extend Input classes for Mentions and Drafts.

* Add fork note comment.

* Improve types.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants