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

Fix mentions rendering in comment editor #35187

Merged
merged 1 commit into from
Nov 21, 2022
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
1 change: 1 addition & 0 deletions apps/comments/src/components/Comment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
:auto-complete="autoComplete"
:contenteditable="!loading"
:value="localMessage"
:user-data="userData"
@update:value="updateLocalMessage"
@submit="onSubmit" />
<NcButton class="comment__submit"
Expand Down
39 changes: 22 additions & 17 deletions apps/comments/src/views/Comments.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<!-- Editor -->
<Comment v-bind="editorData"
:auto-complete="autoComplete"
:user-data="userData"
:editor="true"
:ressource-id="ressourceId"
class="comments__writer"
Expand Down Expand Up @@ -91,9 +92,9 @@ import RefreshIcon from 'vue-material-design-icons/Refresh'
import MessageReplyTextIcon from 'vue-material-design-icons/MessageReplyText'
import AlertCircleOutlineIcon from 'vue-material-design-icons/AlertCircleOutline'

import Comment from '../components/Comment'
import getComments, { DEFAULT_LIMIT } from '../services/GetComments'
import cancelableRequest from '../utils/cancelableRequest'
import Comment from '../components/Comment.vue'
import getComments, { DEFAULT_LIMIT } from '../services/GetComments.js'
import cancelableRequest from '../utils/cancelableRequest.js'
danxuliu marked this conversation as resolved.
Show resolved Hide resolved

Vue.use(VTooltip)

Expand Down Expand Up @@ -129,6 +130,7 @@ export default {
},

Comment,
userData: {},
}
},

Expand Down Expand Up @@ -173,21 +175,22 @@ export default {
* Make sure we have all mentions as Array of objects
*
* @param {Array} mentions the mentions list
* @return {object[]}
* @return {Object<string, object>}
*/
genMentionsData(mentions) {
const list = Object.values(mentions).flat()
return list.reduce((mentions, mention) => {
mentions[mention.mentionId] = {
// TODO: support groups
icon: 'icon-user',
id: mention.mentionId,
label: mention.mentionDisplayName,
source: 'users',
primary: getCurrentUser().uid === mention.mentionId,
}
return mentions
}, {})
Object.values(mentions)
.flat()
.forEach(mention => {
this.userData[mention.mentionId] = {
// TODO: support groups
icon: 'icon-user',
id: mention.mentionId,
label: mention.mentionDisplayName,
source: 'users',
primary: getCurrentUser().uid === mention.mentionId,
}
})
return this.userData
},

/**
Expand Down Expand Up @@ -251,7 +254,9 @@ export default {
limit: loadState('comments', 'maxAutoCompleteResults'),
},
})
return callback(results.data.ocs.data)
// Save user data so it can be used by the editor to replace mentions
results.data.ocs.data.forEach(user => { this.userData[user.id] = user })
return callback(Object.values(this.userData))
},

/**
Expand Down
4 changes: 2 additions & 2 deletions dist/comments-comments-app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/comments-comments-app.js.map

Large diffs are not rendered by default.