Skip to content

Commit

Permalink
Merge pull request #11586 from nextcloud/fix/11585/follow-up-all-reac…
Browse files Browse the repository at this point in the history
…tions-button

Fix/11585/follow up all reactions button
  • Loading branch information
DorraJaouad authored Feb 14, 2024
2 parents db77116 + 6edead4 commit 6eb02c5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
:id="id"
:token="token"
:can-react="canReact"
:show-controls="isHovered || isFollowUpEmojiPickerOpen"
@emoji-picker-toggled="toggleFollowUpEmojiPicker" />
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ describe('Reactions.vue', () => {
// Assert
expect(showError).toHaveBeenCalled()
expect(emojiPicker).toHaveLength(0)
expect(reactionButtons).toHaveLength(4) // "All" + "🎄" + "🔥" + "🔒" buttons
expect(reactionButtons.at(1).text()).toBe('🎄 2')
expect(reactionButtons.at(2).text()).toBe('🔥 2')
expect(reactionButtons.at(3).text()).toBe('🔒 2')
expect(reactionButtons).toHaveLength(3) // "🎄" + "🔥" + "🔒" buttons
expect(reactionButtons.at(0).text()).toBe('🎄 2')
expect(reactionButtons.at(1).text()).toBe('🔥 2')
expect(reactionButtons.at(2).text()).toBe('🔒 2')
})

test('doesn\'t mount emoji picker when there are no reactions', () => {
Expand Down Expand Up @@ -203,7 +203,10 @@ describe('Reactions.vue', () => {
vuexStore.dispatch('processMessage', { token, message })

const wrapper = shallowMount(Reactions, {
propsData: reactionsProps,
propsData: {
...reactionsProps,
showControls: true,
},
localVue,
store,
stubs: {
Expand Down Expand Up @@ -255,8 +258,8 @@ describe('Reactions.vue', () => {

// Act
const reactionButtons = wrapper.findAllComponents(NcButton)
reactionButtons.at(1).vm.$emit('click') // 🎄
reactionButtons.at(2).vm.$emit('click') // 🔥
reactionButtons.at(0).vm.$emit('click') // 🎄
reactionButtons.at(1).vm.$emit('click') // 🔥

// Assert
expect(reactionsStore.addReactionToMessage).toHaveBeenCalledWith({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@
<template>
<!-- reactions buttons and popover with details -->
<div class="reactions-wrapper">
<!-- all reactions button -->
<NcButton class="reaction-button"
:title="t('spreed', 'Show all reactions')"
@click="showAllReactions = true">
<HeartOutlineIcon :size="15" />
</NcButton>
<NcPopover v-for="reaction in reactionsSorted"
:key="reaction"
:delay="200"
Expand All @@ -44,7 +38,7 @@
</NcButton>
</template>

<div v-if="hasReactions" class="reaction-details">
<div v-if="hasReactionsLoaded" class="reaction-details">
<span>{{ getReactionSummary(reaction) }}</span>
<NcButton v-if="reactionsCount(reaction) > 3"
type="tertiary-no-background"
Expand All @@ -57,8 +51,16 @@
</div>
</NcPopover>

<!-- all reactions button -->
<NcButton v-if="showControls"
class="reaction-button"
:title="t('spreed', 'Show all reactions')"
@click="showAllReactions = true">
<HeartOutlineIcon :size="15" />
</NcButton>

<!-- More reactions picker -->
<NcEmojiPicker v-if="canReact && hasReactions"
<NcEmojiPicker v-if="canReact && showControls"
:per-line="5"
:container="`#message_${id}`"
@select="handleReactionClick"
Expand All @@ -73,7 +75,7 @@
</NcButton>
</NcEmojiPicker>

<!-- all reactions -->
<!-- all reactions modal-->
<ReactionsList v-if="showAllReactions"
:token="token"
:detailed-reactions="detailedReactions"
Expand Down Expand Up @@ -131,6 +133,11 @@ export default {
type: [String, Number],
required: true,
},

showControls: {
type: Boolean,
default: false,
},
},

emits: ['emoji-picker-toggled'],
Expand All @@ -151,7 +158,7 @@ export default {
},

computed: {
hasReactions() {
hasReactionsLoaded() {
return Object.keys(Object(this.detailedReactions)).length !== 0
},

Expand Down Expand Up @@ -184,14 +191,14 @@ export default {
.sort() // Plain reactions come sorted
.map(([key, value]) => [key, value.length])
)
return this.hasReactions
return this.hasReactionsLoaded
&& JSON.stringify(this.plainReactions) !== JSON.stringify(detailedReactionsSimplified)
},
},

methods: {
fetchReactions() {
if (!this.hasReactions || this.hasOutdatedDetails) {
if (!this.hasReactionsLoaded || this.hasOutdatedDetails) {
this.reactionsStore.fetchReactions(this.token, this.id)
}
},
Expand Down Expand Up @@ -243,7 +250,7 @@ export default {

getReactionSummary(reaction) {
// Check if the reaction details are loaded
if (!this.hasReactions) {
if (!this.hasReactionsLoaded) {
return ''
}
const list = this.detailedReactions[reaction].slice(0, 3)
Expand Down

0 comments on commit 6eb02c5

Please sign in to comment.