From 8efc0a90063b098766fdd348345143ced6272a4e Mon Sep 17 00:00:00 2001 From: Hunter Miller Date: Tue, 11 Jan 2022 16:43:57 -0600 Subject: [PATCH] dms: hiding delete for dms and hiding dropdown if only reply --- .../src/views/apps/chat/DmResource.tsx | 9 +- .../apps/chat/components/ChatMessage.tsx | 194 ++++-------------- 2 files changed, 45 insertions(+), 158 deletions(-) diff --git a/pkg/interface/src/views/apps/chat/DmResource.tsx b/pkg/interface/src/views/apps/chat/DmResource.tsx index 4c56d32fd5..6673f26df6 100644 --- a/pkg/interface/src/views/apps/chat/DmResource.tsx +++ b/pkg/interface/src/views/apps/chat/DmResource.tsx @@ -1,4 +1,4 @@ -import { acceptDm, cite, Content, declineDm, deSig, Post, removeDmMessage } from '@urbit/api'; +import { acceptDm, cite, Content, declineDm, deSig, Post } from '@urbit/api'; import React, { useCallback, useEffect } from 'react'; import _ from 'lodash'; import bigInt from 'big-integer'; @@ -77,7 +77,7 @@ export function DmResource(props: DmResourceProps) { ); useEffect(() => { - if(!dm) { + if(dm.size === 0) { getNewest(`~${window.ship}`, 'dm-inbox', 100, `/${patp2dec(ship)}`); } }, [ship, dm]); @@ -127,10 +127,6 @@ export function DmResource(props: DmResourceProps) { [ship, addDmMessage] ); - const onDelete = useCallback((msg: Post) => { - airlock.poke(removeDmMessage(`~${window.ship}`, msg.index)); - }, []); - const onAccept = async () => { await airlock.poke(acceptDm(ship)); }; @@ -208,7 +204,6 @@ export function DmResource(props: DmResourceProps) { onReply={quoteReply} fetchMessages={fetchMessages} dismissUnread={dismissUnread} - onDelete={onDelete} getPermalink={() => undefined} isAdmin={false} onSubmit={onSubmit} diff --git a/pkg/interface/src/views/apps/chat/components/ChatMessage.tsx b/pkg/interface/src/views/apps/chat/components/ChatMessage.tsx index 5e59b19d23..8fb25e7747 100644 --- a/pkg/interface/src/views/apps/chat/components/ChatMessage.tsx +++ b/pkg/interface/src/views/apps/chat/components/ChatMessage.tsx @@ -284,6 +284,9 @@ const MessageActionItem = (props) => { const MessageActions = ({ onReply, onDelete, msg, isAdmin, permalink }) => { const isOwn = () => msg.author === window.ship; const { doCopy, copyDisplay } = useCopy(permalink, 'Copy Message Link'); + const showCopyMessageLink = Boolean(permalink); + const showDelete = (isAdmin || isOwn()) && onDelete; + const showDropdown = showCopyMessageLink || showDelete; return ( { > - - onReply(msg)}> - Reply - - {permalink ? ( - - {copyDisplay} + {showDropdown && ( + + onReply(msg)}> + Reply - ) : null } - {(isAdmin || isOwn()) ? ( - onDelete(msg)} color='red'> - Delete Message - - ) : null} - {false && ( - console.log(e)}> - View Signature - - )} - - } - > - - - - + {showCopyMessageLink && ( + + {copyDisplay} + + )} + {showDelete && ( + onDelete(msg)} color='red'> + Delete Message + + )} + + } + > + + + + + )} ); @@ -418,7 +418,7 @@ function ChatMessage(props: ChatMessageProps) { } const onReply = props?.onReply || emptyCallback; - const onDelete = props?.onDelete || emptyCallback; + const onDelete = props?.onDelete; // If missing hide delete action const transcluded = props?.transcluded || 0; const renderSigil = props.renderSigil || (Boolean(nextMsg && msg.author !== nextMsg.author) || !nextMsg @@ -513,111 +513,3 @@ function ChatMessage(props: ChatMessageProps) { export default React.memo(React.forwardRef((props: Omit, ref: any) => ( ))); - -export const MessagePlaceholder = ({ - height, - index, - className = '', - style = {}, - ...props -}) => ( - - - - - - - - - - - - - - - - - - - - - -);