Skip to content

Commit

Permalink
refactor(chat): reuse message component inside of message replies
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonwoodland committed Aug 2, 2022
1 parent fdd80f4 commit ebcdd7f
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 186 deletions.
2 changes: 1 addition & 1 deletion components/views/chat/message/Message.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</div>
<div class="footer">
<MessageReactions :message="message" :emojiReaction="emojiReaction" />
<MessageReply :replies="replies" />
<MessageReplies :replies="replies" />
</div>
</div>
</UiContextMenu>
8 changes: 4 additions & 4 deletions components/views/chat/message/Message.less
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@
'timestamp footer';
grid-template-columns: 52px;

.timestamp {
> .timestamp {
opacity: 0;
}

&:hover,
&:focus-within {
.timestamp {
> .timestamp {
opacity: 1;
}
}

.timestamp {
> .timestamp {
line-height: 24px;
}
}
Expand Down Expand Up @@ -98,7 +98,7 @@
&:extend(.background-semitransparent-light);
}

.message-actions {
> .body > .message-actions {
opacity: 1;
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/views/chat/message/Message.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default Vue.extend({
},
replies: {
type: Array as PropType<(ConversationMessage & { id: string })[]>,
required: true,
default: [] as (ConversationMessage & { id: string })[],
},
showHeader: {
type: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
{{ makeReplyText }}
</div>
<template v-else>
<MessageReplyItem
v-for="reply in replies"
:key="reply.id"
:message="message"
:reply="reply"
/>
<div class="message-replies">
<Message
v-for="item in replyItems"
:message="item.message"
:key="item.message.id"
:showHeader="!item.isSameAuthor"
/>
</div>
<div @click="toggleReplies" class="toggle-button" data-cy="reply-close">
<minus-square-icon size="1.1x" />
{{ $t('conversation.collapse') }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.replies-container {
margin: @light-spacing 0;
padding: @xlight-spacing @light-spacing;
word-break: break-word;
&:extend(.bordered);
&:extend(.round-corners);
Expand All @@ -11,10 +10,23 @@
align-items: center;
cursor: pointer;
padding: @xlight-spacing;
gap: @xlight-spacing;
gap: @light-spacing;
font-size: @text-size;
font-family: @secondary-font;
padding: @light-spacing @normal-spacing;
&:extend(.font-secondary);

&:hover {
&:extend(.background-semitransparent-light);
}
}

.message-replies {
padding: @light-spacing;

.chat-message-container:first-child .chat-message {
margin-top: @light-spacing;
}
}
}
.is-chatbar-reply {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<template src="./Reply.html"></template>
<template src="./Replies.html"></template>
<script lang="ts">
import Vue, { PropType } from 'vue'
import { mapState } from 'vuex'
Expand All @@ -7,6 +7,11 @@ import { getUsernameFromState } from '~/utilities/Messaging'
import { toHTML } from '~/libraries/ui/Markdown'
import { ConversationMessage } from '~/libraries/Iridium/chat/types'
interface ReplyItem {
message: ConversationMessage & { id: string }
isSameAuthor: boolean
}
export default Vue.extend({
components: {
PlusSquareIcon,
Expand All @@ -25,6 +30,18 @@ export default Vue.extend({
},
computed: {
...mapState(['ui', 'chat']),
replyItems(): ReplyItem[] {
return this.replies.map((message, index) => {
const prevMessage = index >= 0 ? this.replies[index - 1] : undefined
const isSameAuthor = prevMessage
? message.from === prevMessage.from
: false
return {
message,
isSameAuthor,
}
})
},
setChatReply: {
set(state) {
this.$store.commit('chat/setChatReply', state)
Expand Down Expand Up @@ -132,4 +149,4 @@ export default Vue.extend({
},
})
</script>
<style lang="less" src="./Reply.less"></style>
<style lang="less" src="./Replies.less"></style>
47 changes: 0 additions & 47 deletions components/views/chat/message/reply/Item/Item.html

This file was deleted.

47 changes: 0 additions & 47 deletions components/views/chat/message/reply/Item/Item.less

This file was deleted.

76 changes: 0 additions & 76 deletions components/views/chat/message/reply/Item/Item.vue

This file was deleted.

0 comments on commit ebcdd7f

Please sign in to comment.