Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replies: add hide/show to replies #3004

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions ui/src/replies/ReplyMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
/* eslint-disable react/no-unused-prop-types */
import React, { useCallback, useEffect, useRef, useState } from 'react';
import React, {
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from 'react';
import cn from 'classnames';
import debounce from 'lodash/debounce';
import { BigInteger } from 'big-integer';
Expand All @@ -14,6 +20,7 @@ import ChatContent from '@/chat/ChatContent/ChatContent';
import DateDivider from '@/chat/ChatMessage/DateDivider';
import {
useChatState,
useMessageToggler,
useTrackedMessageStatus,
// useIsMessageDelivered,
// useIsMessagePosted,
Expand All @@ -24,9 +31,10 @@ import { useIsMobile } from '@/logic/useMedia';
import useLongPress from '@/logic/useLongPress';
import {
useMarkReadMutation,
usePostToggler,
useTrackedPostStatus,
} from '@/state/channel/channel';
import { emptyReply, Reply } from '@/types/channel';
import { emptyReply, Reply, Story } from '@/types/channel';
import { useIsDmOrMultiDm } from '@/logic/utils';
import {
useChatDialog,
Expand Down Expand Up @@ -68,6 +76,17 @@ const mergeRefs =
});
};

const hiddenMessage: Story = [
{
inline: [
{
italics: [
'You have hidden this message. You can unhide it from the options menu.',
],
},
],
},
];
const ReplyMessage = React.memo<
ReplyMessageProps & React.RefAttributes<HTMLDivElement>
>(
Expand Down Expand Up @@ -99,6 +118,12 @@ const ReplyMessage = React.memo<
const { open: pickerOpen } = useChatDialog(whom, seal.id, 'picker');
const isDMOrMultiDM = useIsDmOrMultiDm(whom);
const { mutate: markChatRead } = useMarkReadMutation();
const { isHidden: isMessageHidden } = useMessageToggler(seal.id);
const { isHidden: isPostHidden } = usePostToggler(seal.id);
const isHidden = useMemo(
() => isMessageHidden || isPostHidden,
[isMessageHidden, isPostHidden]
);
const { ref: viewRef } = useInView({
threshold: 1,
onChange: useCallback(
Expand Down Expand Up @@ -282,7 +307,13 @@ const ReplyMessage = React.memo<
isLinked && 'bg-blue-softer'
)}
>
{memo.content ? (
{isHidden ? (
<ChatContent
story={hiddenMessage}
isScrolling={isScrolling}
writId={seal.id}
/>
) : memo.content ? (
<ChatContent
story={memo.content}
isScrolling={isScrolling}
Expand Down
50 changes: 49 additions & 1 deletion ui/src/replies/ReplyMessageOptions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect } from 'react';
import React, { useCallback, useEffect, useMemo } from 'react';
import { useLocation, useNavigate, useParams } from 'react-router';
import { useSearchParams } from 'react-router-dom';
import { decToUd } from '@urbit/api';
Expand All @@ -8,6 +8,7 @@ import { useAmAdmin, useGroup, useRouteGroup, useVessel } from '@/state/groups';
import {
useAddDMReplyReactMutation,
useDeleteDMReplyMutation,
useMessageToggler,
} from '@/state/chat';
import IconButton from '@/components/IconButton';
import useEmoji from '@/state/emoji';
Expand All @@ -31,8 +32,11 @@ import {
useDeletePostMutation,
useDeleteReplyMutation,
usePerms,
usePostToggler,
} from '@/state/channel/channel';
import { emptyReply, Reply } from '@/types/channel';
import VisibleIcon from '@/components/icons/VisibleIcon';
import HiddenIcon from '@/components/icons/HiddenIcon';

export default function ReplyMessageOptions(props: {
open: boolean;
Expand Down Expand Up @@ -85,6 +89,20 @@ export default function ReplyMessageOptions(props: {
const { mutate: addFeelToChat } = useAddPostReactMutation();
const { mutate: addFeelToReply } = useAddReplyReactMutation();
const { mutate: addDMReplyFeel } = useAddDMReplyReactMutation();
const {
show: showPost,
hide: hidePost,
isHidden: isPostHidden,
} = usePostToggler(seal.id);
const {
show: showChatMessage,
hide: hideChatMessage,
isHidden: isMessageHidden,
} = useMessageToggler(seal.id);
const isHidden = useMemo(
() => isMessageHidden || isPostHidden,
[isMessageHidden, isPostHidden]
);

const onDelete = async () => {
if (isMobile) {
Expand Down Expand Up @@ -188,6 +206,16 @@ export default function ReplyMessageOptions(props: {
}
}, [isMobile, loadEmoji]);

const toggleMsg = useCallback(
() => (isMessageHidden ? showChatMessage() : hideChatMessage()),
[isMessageHidden, showChatMessage, hideChatMessage]
);

const togglePost = useCallback(
() => (isPostHidden ? showPost() : hidePost()),
[isPostHidden, showPost, hidePost]
);

const showReactAction = canWrite;
// TODO handle reply replies
const showCopyAction = !!groupFlag;
Expand Down Expand Up @@ -258,6 +286,26 @@ export default function ReplyMessageOptions(props: {
});
}

actions.push({
key: 'hide',
onClick: isDMorMultiDM ? toggleMsg : togglePost,
content: (
<div className="flex items-center">
{isHidden ? (
<>
<VisibleIcon className="mr-2 h-6 w-6" />
Show Message
</>
) : (
<>
<HiddenIcon className="mr-2 h-6 w-6" />
Hide Message
</>
)}
</div>
),
});

if (showDeleteAction) {
actions.push({
key: 'delete',
Expand Down
Loading