mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(reply-quote-preview): restore (You) for pseudonymous quotes (#1084)
* fix(reply-quote-preview): restore (You) for pseudonymous quotes * test(reply-quote-preview): mock account comments hook
This commit is contained in:
@@ -23,6 +23,7 @@ const testState = vi.hoisted(() => ({
|
||||
address: '0xme',
|
||||
},
|
||||
},
|
||||
accountComments: [] as Array<{ cid?: string }>,
|
||||
directories: [{ address: 'music-posting.eth', title: '/mu/ - Music' }] as Array<{ address: string; title?: string }>,
|
||||
isMobile: false,
|
||||
locationPath: '/mu/thread/thread-cid',
|
||||
@@ -58,6 +59,7 @@ vi.mock('react-router-dom', async () => {
|
||||
|
||||
vi.mock('@bitsocialnet/bitsocial-react-hooks', () => ({
|
||||
useAccount: () => testState.account,
|
||||
useAccountComments: () => ({ accountComments: testState.accountComments }),
|
||||
}));
|
||||
|
||||
vi.mock('@floating-ui/react', () => ({
|
||||
@@ -173,6 +175,7 @@ describe('ReplyQuotePreview', () => {
|
||||
address: '0xme',
|
||||
},
|
||||
};
|
||||
testState.accountComments = [];
|
||||
testState.directories = [{ address: 'music-posting.eth', title: '/mu/ - Music' }];
|
||||
testState.isMobile = false;
|
||||
testState.locationPath = '/mu/thread/thread-cid';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { Link, useLocation, useNavigate } from 'react-router-dom';
|
||||
import { Comment, useAccount } from '@bitsocialnet/bitsocial-react-hooks';
|
||||
import { Comment, useAccount, useAccountComments } from '@bitsocialnet/bitsocial-react-hooks';
|
||||
import { useFloating, offset, shift, size, autoUpdate, Placement } from '@floating-ui/react';
|
||||
import { useDirectories } from '../../hooks/use-directories';
|
||||
import { getBoardPath } from '../../lib/utils/route-utils';
|
||||
@@ -206,6 +206,7 @@ const DesktopQuotePreview = ({
|
||||
);
|
||||
|
||||
const account = useAccount();
|
||||
const { accountComments } = useAccountComments();
|
||||
|
||||
const resolvedQuotelinkNumber = normalizedQuotelinkReply?.number ?? quotelinkNumber;
|
||||
const resolvedQuotelinkCid = normalizedQuotelinkReply?.cid;
|
||||
@@ -226,11 +227,14 @@ const DesktopQuotePreview = ({
|
||||
quoteCid: resolvedQuotelinkCid,
|
||||
isUnavailable: quotelinkUnavailable,
|
||||
});
|
||||
const isOwnQuotelink =
|
||||
(resolvedQuotelinkCid ? accountComments.some((comment) => comment.cid === resolvedQuotelinkCid) : false) ||
|
||||
normalizedQuotelinkReply?.author?.address === account?.author?.address;
|
||||
const quotelinkLabel = (
|
||||
<>
|
||||
{formatQuoteNumber(resolvedQuotelinkNumber)}
|
||||
{isOP && ' (OP)'}
|
||||
{normalizedQuotelinkReply?.author?.address === account?.author?.address && ' (You)'}
|
||||
{isOwnQuotelink && ' (You)'}
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -372,6 +376,7 @@ const MobileQuotePreview = ({
|
||||
);
|
||||
|
||||
const account = useAccount();
|
||||
const { accountComments } = useAccountComments();
|
||||
const resolvedQuotelinkNumber = normalizedQuotelinkReply?.number ?? quotelinkNumber;
|
||||
const resolvedQuotelinkCid = normalizedQuotelinkReply?.cid;
|
||||
const resolvedQuotelinkCommunityAddress = getCommentCommunityAddress(normalizedQuotelinkReply);
|
||||
@@ -385,6 +390,9 @@ const MobileQuotePreview = ({
|
||||
quoteCid: resolvedQuotelinkCid,
|
||||
isUnavailable: quotelinkUnavailable,
|
||||
});
|
||||
const isOwnQuotelink =
|
||||
(resolvedQuotelinkCid ? accountComments.some((comment) => comment.cid === resolvedQuotelinkCid) : false) ||
|
||||
normalizedQuotelinkReply?.author?.address === account?.author?.address;
|
||||
|
||||
const replyQuotelink = (
|
||||
<>
|
||||
@@ -396,7 +404,7 @@ const MobileQuotePreview = ({
|
||||
>
|
||||
{formatQuoteNumber(resolvedQuotelinkNumber)}
|
||||
{isOP && ' (OP)'}
|
||||
{normalizedQuotelinkReply?.author?.address === account?.author?.address && ' (You)'}
|
||||
{isOwnQuotelink && ' (You)'}
|
||||
</span>
|
||||
{!quotelinkUnavailable &&
|
||||
!quotelinkPendingResolution &&
|
||||
|
||||
Reference in New Issue
Block a user