From 7e46bef92b3b541f262146ec8d18b44a105f8b9c Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Fri, 8 Jan 2021 12:16:37 -0300 Subject: [PATCH] Rewrite Discussion Metric --- app/discussion/client/index.js | 3 -- .../client/public/stylesheets/discussion.css | 45 ------------------- app/ui-message/client/message.html | 21 ++------- app/ui-utils/client/lib/messageContext.js | 9 ++++ app/ui/client/views/app/room.js | 5 --- client/adapters.js | 3 +- client/components/Message/Message.stories.js | 12 ++++- .../components/Message/Metrics/Discussion.tsx | 30 +++++++++++++ client/components/Message/Metrics/Thread.tsx | 8 ++-- client/components/Message/index.tsx | 9 +--- 10 files changed, 61 insertions(+), 84 deletions(-) delete mode 100644 app/discussion/client/public/stylesheets/discussion.css create mode 100644 client/components/Message/Metrics/Discussion.tsx diff --git a/app/discussion/client/index.js b/app/discussion/client/index.js index fcd3eb9a9d84..d48455ac350e 100644 --- a/app/discussion/client/index.js +++ b/app/discussion/client/index.js @@ -8,6 +8,3 @@ import './discussionFromMessageBox'; import './tabBar'; import '../lib/discussionRoomType'; - -// Style -import './public/stylesheets/discussion.css'; diff --git a/app/discussion/client/public/stylesheets/discussion.css b/app/discussion/client/public/stylesheets/discussion.css deleted file mode 100644 index 812ec0727c33..000000000000 --- a/app/discussion/client/public/stylesheets/discussion.css +++ /dev/null @@ -1,45 +0,0 @@ -.message-thread, -.message-discussion { - display: flex; - - padding: 0.5rem 0; - align-items: center; - - flex-wrap: wrap; -} - -.message-thread { - .reply-counter { - color: var(--color-gray); - } -} - -.discussion-reply-lm, -.reply-counter { - color: var(--color-white); - - font-size: 12px; - font-style: italic; - - flex-grow: 0; - flex-shrink: 0; -} - -.reply-counter { - font-weight: 600; - margin-inline-start: 8px; -} - -.discussion-reply-lm { - padding: 4px 8px; - - color: var(--color-gray); -} - -.discussions-list .load-more { - text-align: center; - text-transform: lowercase; - - font-style: italic; - line-height: 40px; -} diff --git a/app/ui-message/client/message.html b/app/ui-message/client/message.html index ffdef76c626a..350b2ba949d4 100644 --- a/app/ui-message/client/message.html +++ b/app/ui-message/client/message.html @@ -123,26 +123,11 @@ {{/each}} {{#if msg.drid}} -
- {{#if $gt msg.dcount 0}} - - {{else}} - - {{/if}} - {{ formatDateAndTime msg.dlm }} - {{# if unread }} -
- {{/if}} -
+ {{> DiscussionMetric count=msg.dcount drid=msg.drid lm=msg.dlm openDiscussion=actions.openDiscussion }} {{/if}} + {{#if $and settings.showReplyButton msg.tcount}} - {{> ThreadReply counter=msg.tcount following=following lm=msg.tlm rid=msg.rid mid=msg._id unread=unread mention=mention all=all openThread=actions.openThread }} - + {{> ThreadMetric counter=msg.tcount following=following lm=msg.tlm rid=msg.rid mid=msg._id unread=unread mention=mention all=all openThread=actions.openThread }} {{/if}} {{#with readReceipt}} diff --git a/app/ui-utils/client/lib/messageContext.js b/app/ui-utils/client/lib/messageContext.js index a445073b5e52..aea913f577be 100644 --- a/app/ui-utils/client/lib/messageContext.js +++ b/app/ui-utils/client/lib/messageContext.js @@ -27,6 +27,12 @@ export function messageContext({ rid } = Template.instance()) { }); }; + const openDiscussion = (e) => { + e.preventDefault(); + const { drid } = e.currentTarget.dataset; + FlowRouter.goToRoomById(drid); + }; + return { u: user, room: Rooms.findOne({ _id: rid }, { @@ -50,6 +56,9 @@ export function messageContext({ rid } = Template.instance()) { openThread() { return openThread; }, + openDiscussion() { + return openDiscussion; + }, }, settings: { translateLanguage: AutoTranslate.getLanguage(rid), diff --git a/app/ui/client/views/app/room.js b/app/ui/client/views/app/room.js index d45b3b503dc2..c53e781560e9 100644 --- a/app/ui/client/views/app/room.js +++ b/app/ui/client/views/app/room.js @@ -570,11 +570,6 @@ Meteor.startup(() => { 'rendered .js-block-wrapper'(e, template) { template.sendToBottomIfNecessaryDebounced(); }, - 'click .js-navigate-to-discussion'(event) { - event.preventDefault(); - const { msg: { drid } } = messageArgs(this); - FlowRouter.goToRoomById(drid); - }, 'click .new-message'(event, instance) { instance.atBottom = true; instance.sendToBottomIfNecessaryDebounced(); diff --git a/client/adapters.js b/client/adapters.js index 475c69af6152..252ef77a9019 100644 --- a/client/adapters.js +++ b/client/adapters.js @@ -1,3 +1,4 @@ const { createTemplateForComponent } = require('./reactAdapters'); -createTemplateForComponent('ThreadReply', () => import('./components/Message/Metrics/Thread')); +createTemplateForComponent('ThreadMetric', () => import('./components/Message/Metrics/Thread')); +createTemplateForComponent('DiscussionMetric', () => import('./components/Message/Metrics/Discussion')); diff --git a/client/components/Message/Message.stories.js b/client/components/Message/Message.stories.js index 0c831035cf43..9a5beee8595b 100644 --- a/client/components/Message/Message.stories.js +++ b/client/components/Message/Message.stories.js @@ -7,7 +7,7 @@ export default { component: Metrics, }; -export const Default = () => +export const Thread = () => @@ -28,3 +28,13 @@ export const Default = () => ; + + +export const Discussion = () => + + + + sunday + + +; diff --git a/client/components/Message/Metrics/Discussion.tsx b/client/components/Message/Metrics/Discussion.tsx new file mode 100644 index 000000000000..630e7138151b --- /dev/null +++ b/client/components/Message/Metrics/Discussion.tsx @@ -0,0 +1,30 @@ +import React, { FC } from 'react'; + +import { useTranslation } from '../../../contexts/TranslationContext'; +import { useTimeAgo } from '../../../hooks/useTimeAgo'; +import Metrics, { Reply, Content } from '..'; + + +type DicussionOptions = { + drid: string; + rid: string; + count: number; + lm: Date; + openDiscussion: () => void; +}; + +const DiscussionMetric: FC = ({ lm, count, rid, drid, openDiscussion }) => { + const t = useTranslation(); + const format = useTimeAgo(); + return + {count ? t('message_counter', { counter: count, count }) : t('Reply')} + + + + {lm ? format(lm) : t('No_messages_yet')} + + + ; +}; + +export default DiscussionMetric; diff --git a/client/components/Message/Metrics/Thread.tsx b/client/components/Message/Metrics/Thread.tsx index f68b3008ea82..73e3d2218219 100644 --- a/client/components/Message/Metrics/Thread.tsx +++ b/client/components/Message/Metrics/Thread.tsx @@ -21,7 +21,7 @@ type ThreadReplyOptions = { openThread: () => any; }; -const ReplyBlock: FC = ({ unread, mention, all, rid, mid, counter, participants, following, lm, openThread }) => { +const ThreadMetric: FC = ({ unread, mention, all, rid, mid, counter, participants, following, lm, openThread }) => { const t = useTranslation(); const followMessage = useEndpoint('POST', 'chat.followMessage'); @@ -31,7 +31,7 @@ const ReplyBlock: FC = ({ unread, mention, all, rid, mid, co const handleFollow = useCallback(() => (following ? unfollowMessage({ mid }) : followMessage({ mid })), [followMessage, following, mid, unfollowMessage]); return - + {t('Reply')} @@ -41,7 +41,7 @@ const ReplyBlock: FC = ({ unread, mention, all, rid, mid, co {participants} } - + {format(lm)} @@ -57,4 +57,4 @@ const ReplyBlock: FC = ({ unread, mention, all, rid, mid, co ; }; -export default ReplyBlock; +export default ThreadMetric; diff --git a/client/components/Message/index.tsx b/client/components/Message/index.tsx index bf566a1dc369..304e8245bee7 100644 --- a/client/components/Message/index.tsx +++ b/client/components/Message/index.tsx @@ -1,15 +1,10 @@ import React, { FC } from 'react'; import { ActionButton, Box, BoxProps, Button, ButtonProps, Icon } from '@rocket.chat/fuselage'; -import { useTranslation } from '../../contexts/TranslationContext'; - export const Content: FC = (props) => ; const ContentItem: FC = (props) => ; -export const Reply: FC = (props) => { - const t = useTranslation(); - return ; -}; +export const Reply: FC = (props) =>