mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(post flags): show flags on directory candidate boards
This commit is contained in:
@@ -19,6 +19,7 @@ type TestComment = {
|
||||
communityAddress?: string;
|
||||
content?: string;
|
||||
deleted?: boolean;
|
||||
flairs?: Array<{ code?: string; text?: string; type?: string }>;
|
||||
index?: number;
|
||||
link?: string;
|
||||
linkHeight?: number;
|
||||
@@ -48,6 +49,7 @@ type TestComment = {
|
||||
const testState = vi.hoisted(() => ({
|
||||
addChallengeMock: vi.fn(),
|
||||
accountCommentsByCid: {} as Record<string, TestComment | undefined>,
|
||||
directoryEntryByAddress: {} as Record<string, { address: string; directoryCode?: string; features?: Record<string, unknown>; title?: string } | undefined>,
|
||||
hasMoreReplies: false,
|
||||
openReplyModalMock: vi.fn(),
|
||||
pseudonymityMode: 'none',
|
||||
@@ -212,6 +214,10 @@ vi.mock('../../hooks/use-directories', () => ({
|
||||
useDirectories: () => [{ address: 'music-posting.eth', title: '/mu/ - Music' }],
|
||||
}));
|
||||
|
||||
vi.mock('../../hooks/use-directory-entry', () => ({
|
||||
useDirectoryEntry: (address?: string) => (address ? testState.directoryEntryByAddress[address] : undefined),
|
||||
}));
|
||||
|
||||
vi.mock('../../lib/utils/route-utils', () => ({
|
||||
getBoardPath: (address?: string) => (address ? 'mu' : undefined),
|
||||
}));
|
||||
@@ -458,6 +464,9 @@ describe('post community address compatibility', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
testState.accountCommentsByCid = {};
|
||||
testState.directoryEntryByAddress = {
|
||||
'music-posting.eth': { address: 'music-posting.eth', features: {} },
|
||||
};
|
||||
testState.hasMoreReplies = false;
|
||||
testState.pseudonymityMode = 'none';
|
||||
testState.replyComments = [];
|
||||
@@ -533,6 +542,26 @@ describe('post community address compatibility', () => {
|
||||
expect(container.querySelector('.capcodeAdminIcon')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('renders author flags for raw-address posts on non-primary directory candidate boards', async () => {
|
||||
testState.directoryEntryByAddress['nothing-is-beyond-our-reach.bso'] = {
|
||||
address: 'nothing-is-beyond-our-reach.bso',
|
||||
directoryCode: 'pol',
|
||||
features: { hasFlags: true },
|
||||
title: '/pol/ - Politically Incorrect',
|
||||
};
|
||||
const post = {
|
||||
...makeLegacyThreadWithoutReplies(),
|
||||
communityAddress: 'nothing-is-beyond-our-reach.bso',
|
||||
flairs: [{ text: 'flag:pol:AC' }],
|
||||
};
|
||||
|
||||
await renderWithRoute(createElement(PostDesktop, { post } as any), '/nothing-is-beyond-our-reach.bso/thread/post-1');
|
||||
expect(container.querySelector('img[title="Anarcho-Capitalist"]')).toBeTruthy();
|
||||
|
||||
await renderWithRoute(createElement(PostMobile, { post } as any), '/nothing-is-beyond-our-reach.bso/thread/post-1');
|
||||
expect(container.querySelector('img[title="Anarcho-Capitalist"]')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('falls back to author shortAddress when the full author address cannot be shortened', async () => {
|
||||
testState.pseudonymityMode = 'per-post';
|
||||
const post = {
|
||||
|
||||
@@ -14,6 +14,7 @@ import { isAllView, isModQueueView, isModView, isPendingPostView, isPostPageView
|
||||
import { formatUserIDForDisplay, truncateWithEllipsisInMiddle } from '../../lib/utils/string-utils';
|
||||
import useModQueueStore from '../../stores/use-mod-queue-store';
|
||||
import { findDirectoryByAddress, useDirectories } from '../../hooks/use-directories';
|
||||
import { useDirectoryEntry } from '../../hooks/use-directory-entry';
|
||||
import { getBoardPath } from '../../lib/utils/route-utils';
|
||||
import useAuthorAddressClick from '../../hooks/use-author-address-click';
|
||||
import { useCommentMediaInfo } from '../../hooks/use-comment-media-info';
|
||||
@@ -173,8 +174,8 @@ const PostInfo = ({
|
||||
const isReply = parentCid;
|
||||
const { showOmittedReplies } = useShowOmittedReplies();
|
||||
const directories = useDirectories();
|
||||
const directoryEntry = communityAddress ? findDirectoryByAddress(directories, communityAddress) : undefined;
|
||||
const boardPath = communityAddress ? getBoardPath(communityAddress, directories) : undefined;
|
||||
const directoryEntry = useDirectoryEntry(communityAddress);
|
||||
const showAuthorFlags = hasCommentFlagsForDirectory(directoryEntry) && !(deleted || removed || purged);
|
||||
const postMenuProps = selectPostMenuProps(post);
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import { isAllView, isModQueueView, isModView, isPendingPostView, isPostPageView
|
||||
import { formatUserIDForDisplay } from '../../lib/utils/string-utils';
|
||||
import useModQueueStore from '../../stores/use-mod-queue-store';
|
||||
import { findDirectoryByAddress, useDirectories } from '../../hooks/use-directories';
|
||||
import { useDirectoryEntry } from '../../hooks/use-directory-entry';
|
||||
import { getBoardPath } from '../../lib/utils/route-utils';
|
||||
import useAuthorAddressClick from '../../hooks/use-author-address-click';
|
||||
import { useCommentMediaInfo } from '../../hooks/use-comment-media-info';
|
||||
@@ -88,7 +89,7 @@ const PostInfoAndMedia = ({
|
||||
const archived = isCommentArchived(resolvedPost);
|
||||
const purged = resolvedPost?.commentModeration?.purged;
|
||||
const boardPath = communityAddress ? getBoardPath(communityAddress, directories) : undefined;
|
||||
const directoryEntry = communityAddress ? findDirectoryByAddress(directories, communityAddress) : undefined;
|
||||
const directoryEntry = useDirectoryEntry(communityAddress);
|
||||
const showAuthorFlags = hasCommentFlagsForDirectory(directoryEntry) && !(deleted || removed || purged);
|
||||
const displayBoardPath =
|
||||
boardPath && communityAddress
|
||||
|
||||
Reference in New Issue
Block a user