mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(transfer): hide transferred label on trash board posts
Posts moved to /trash/ should not show the transferred tag since the move is the intended outcome.
This commit is contained in:
@@ -2,6 +2,7 @@ import * as React from 'react';
|
|||||||
import { createElement } from 'react';
|
import { createElement } from 'react';
|
||||||
import { createRoot, type Root } from 'react-dom/client';
|
import { createRoot, type Root } from 'react-dom/client';
|
||||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||||
|
import { TRASH_BOARD_ADDRESS } from '../../lib/special-boards';
|
||||||
import PostTransferredTag from '../post-transferred-tag';
|
import PostTransferredTag from '../post-transferred-tag';
|
||||||
|
|
||||||
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
||||||
@@ -36,6 +37,22 @@ describe('PostTransferredTag', () => {
|
|||||||
expect(container.textContent).toBe('[Transferred] ');
|
expect(container.textContent).toBe('[Transferred] ');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('does not render the transferred label for posts moved to trash', async () => {
|
||||||
|
await act(async () => {
|
||||||
|
root.render(
|
||||||
|
createElement(PostTransferredTag, {
|
||||||
|
comment: {
|
||||||
|
commentModeration: { flairs: [{ text: '5chan:transferred' }] },
|
||||||
|
communityAddress: TRASH_BOARD_ADDRESS,
|
||||||
|
title: 'Original title',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(container.textContent).toBe('');
|
||||||
|
});
|
||||||
|
|
||||||
it('ignores user-authored transferred-looking flairs', async () => {
|
it('ignores user-authored transferred-looking flairs', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
root.render(createElement(PostTransferredTag, { comment: { flairs: [{ text: '5chan:transferred' }] } }));
|
root.render(createElement(PostTransferredTag, { comment: { flairs: [{ text: '5chan:transferred' }] } }));
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { hasTransferredCommentMarker } from '../lib/comment-transfer';
|
import { hasTransferredCommentMarker } from '../lib/comment-transfer';
|
||||||
|
import { getSpecialBoardByAddress, TRASH_BOARD_CODE } from '../lib/special-boards';
|
||||||
|
import { getCommentCommunityAddress } from '../lib/utils/comment-utils';
|
||||||
import styles from './post-transferred-tag.module.css';
|
import styles from './post-transferred-tag.module.css';
|
||||||
|
|
||||||
interface PostTransferredTagProps {
|
interface PostTransferredTagProps {
|
||||||
@@ -10,6 +12,9 @@ const PostTransferredTag = ({ comment }: PostTransferredTagProps) => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
if (!hasTransferredCommentMarker(comment)) return null;
|
if (!hasTransferredCommentMarker(comment)) return null;
|
||||||
|
if (getSpecialBoardByAddress(getCommentCommunityAddress(comment))?.directoryCode === TRASH_BOARD_CODE) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span className={styles.transferredTag} title={t('transferred')}>
|
<span className={styles.transferredTag} title={t('transferred')}>
|
||||||
|
|||||||
Reference in New Issue
Block a user