From 10c81f1ccd538a77d5801ff39bc48274bbea470c Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 22 Jan 2023 22:55:18 +0300 Subject: Message: subscribe/unsubscribe --- vnext/src/ui/Message.js | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) (limited to 'vnext/src/ui/Message.js') diff --git a/vnext/src/ui/Message.js b/vnext/src/ui/Message.js index d45395bb..3bb59a4a 100644 --- a/vnext/src/ui/Message.js +++ b/vnext/src/ui/Message.js @@ -14,9 +14,16 @@ import { UserLink } from './UserInfo'; import { format, embedUrls } from '../utils/embed'; import { useVisitor } from './VisitorContext'; +/** + * @callback ToggleSubscriptionCallback + * @param { import('../client').Message } message + */ + /** * @typedef {object} MessageProps * @property { import('../client').Message } data data + * @property {boolean} isThread + * @property {ToggleSubscriptionCallback} onToggleSubscription */ /** @@ -24,7 +31,7 @@ import { useVisitor } from './VisitorContext'; * * @param {React.PropsWithChildren<{}> & MessageProps} props props */ -export default function Message({ data, children }) { +export default function Message({ data, isThread = false, onToggleSubscription, children }) { const [visitor] = useVisitor(); const isCode = (data.tags || []).indexOf('code') >= 0; const likesSummary = data.likes ? `${data.likes}` : 'Recommend'; @@ -68,7 +75,7 @@ export default function Message({ data, children }) {  ·  Edit + }} state={{ data: data }}>Edit } @@ -109,16 +116,31 @@ export default function Message({ data, children }) { {likesSummary} )} - {data.user && canComment && ( - - - {commentsSummary} - - )} + { + data.user && canComment && (( + isThread ? ( + { onToggleSubscription(data); }}> + { + data.subscribed ? (<> + + Subscribed + ) : (<> + + Subscribe + )} + + ) : ( + + + {commentsSummary} + + ) + )) + } {children} - + ); } -- cgit v1.2.3