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

feat: Add Mentions to draft messages #WPB-12062 #3687

Merged
merged 6 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,6 @@ fun rememberMessageComposerStateHolder(

val messageTextFieldValue = remember { mutableStateOf(TextFieldValue()) }

LaunchedEffect(draftMessageComposition.draftText) {
if (draftMessageComposition.draftText.isNotBlank()) {
messageTextFieldValue.value = messageTextFieldValue.value.copy(
text = draftMessageComposition.draftText,
selection = TextRange(draftMessageComposition.draftText.length) // Place cursor at the end of the new text
)
}
}

val messageCompositionHolder = remember {
mutableStateOf(
MessageCompositionHolder(
Expand All @@ -77,6 +68,23 @@ fun rememberMessageComposerStateHolder(
)
)
}

LaunchedEffect(draftMessageComposition.draftText) {
if (draftMessageComposition.draftText.isNotBlank()) {
messageTextFieldValue.value = messageTextFieldValue.value.copy(
text = draftMessageComposition.draftText,
selection = TextRange(draftMessageComposition.draftText.length) // Place cursor at the end of the new text
)
}

if (draftMessageComposition.selectedMentions.isNotEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

question: shouldn't that have its own LaunchedEffect to be executed every time when draftMessageComposition.selectedMentions changes? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that is not necessary so far, as selectedMentions is updated only with draftText (in MessageDraftViewModel.loadMessageDraft())

messageCompositionHolder.value.setMentions(
draftMessageComposition.draftText,
draftMessageComposition.selectedMentions.map { it.intoMessageMention() }
)
}
}

LaunchedEffect(Unit) {
messageCompositionHolder.value.handleMessageTextUpdates()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,20 @@ class MessageCompositionHolder(
)
messageComposition.update {
it.copy(
selectedMentions = mentions.mapNotNull { it.toUiMention(editMessageText) },
selectedMentions = mentions.mapNotNull { mention -> mention.toUiMention(editMessageText) },
editMessageId = messageId
)
}
onSaveDraft(messageComposition.value.toDraft(editMessageText))
}

fun setMentions(editMessageText: String, mentions: List<MessageMention>) {
messageComposition.update {
it.copy(selectedMentions = mentions.mapNotNull { mention -> mention.toUiMention(editMessageText) })
}
onSaveDraft(messageComposition.value.toDraft(editMessageText))
}

fun addOrRemoveMessageMarkdown(
markdown: RichTextMarkdown,
) {
Expand Down
Loading