0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Renamed CommentsBox to ContentBox and splitted Title component

refs https://github.com/TryGhost/Team/issues/1858
This commit is contained in:
Simon Backx 2022-08-31 15:25:49 +02:00
parent a28ee5c133
commit bea90b0922
4 changed files with 60 additions and 58 deletions

View file

@ -5,7 +5,7 @@ import {createPopupNotification} from './utils/helpers';
import AppContext from './AppContext';
import {hasMode} from './utils/check-mode';
import setupGhostApi from './utils/api';
import CommentsBox from './components/CommentsBox';
import ContentBox from './components/ContentBox';
import PopupModal from './components/PopupModal';
function AuthFrame({adminUrl, onLoad}) {
@ -302,7 +302,7 @@ export default class App extends React.Component {
<SentryErrorBoundary dsn={this.props.sentryDsn}>
<AppContext.Provider value={this.getContextFromState()}>
<CommentsFrame>
<CommentsBox done={done} />
<ContentBox done={done} />
</CommentsFrame>
<AuthFrame adminUrl={this.props.adminUrl} onLoad={this.initAdminAuth.bind(this)}/>
<PopupModal />

View file

@ -115,15 +115,15 @@ describe('Dark mode', () => {
const {iframeDocument} = renderApp({documentStyles: {
color: '#FFFFFF'
}});
const darkModeCommentsBox = await within(iframeDocument).findByTestId('comments-box');
expect(darkModeCommentsBox.classList).toContain('dark');
const darkModeContentBox = await within(iframeDocument).findByTestId('content-box');
expect(darkModeContentBox.classList).toContain('dark');
});
it('uses dark mode when container has a dark text color', async () => {
const {iframeDocument} = renderApp({documentStyles: {
color: '#000000'
}});
const darkModeCommentsBox = await within(iframeDocument).findByTestId('comments-box');
expect(darkModeCommentsBox.classList).not.toContain('dark');
const darkModeContentBox = await within(iframeDocument).findByTestId('content-box');
expect(darkModeContentBox.classList).not.toContain('dark');
});
it('uses dark mode when custom mode has been passed as a property', async () => {
const {iframeDocument} = renderApp({
@ -131,8 +131,8 @@ describe('Dark mode', () => {
colorScheme: 'dark'
}
});
const darkModeCommentsBox = await within(iframeDocument).findByTestId('comments-box');
expect(darkModeCommentsBox.classList).toContain('dark');
const darkModeContentBox = await within(iframeDocument).findByTestId('content-box');
expect(darkModeContentBox.classList).toContain('dark');
});
it('uses light mode when custom mode has been passed as a property', async () => {
const {iframeDocument} = renderApp({
@ -141,8 +141,8 @@ describe('Dark mode', () => {
},
color: '#FFFFFF'
});
const darkModeCommentsBox = await within(iframeDocument).findByTestId('comments-box');
expect(darkModeCommentsBox.classList).not.toContain('dark');
const darkModeContentBox = await within(iframeDocument).findByTestId('content-box');
expect(darkModeContentBox.classList).not.toContain('dark');
});
});

View file

@ -6,50 +6,9 @@ import Comment from './content/Comment';
import Pagination from './content/Pagination';
import Loading from './content/Loading';
import {ROOT_DIV_ID} from '../utils/constants';
import ContentTitle from './content/ContentTitle';
const CommentsBoxTitle = ({title, showCount, count}) => {
// We have to check for null for title because null means default, wheras empty string means empty
if (!title && !showCount && title !== null) {
return null;
}
const Title = () => {
if (title === null) {
return (
<><span className="hidden sm:inline">Member </span><span className="capitalize sm:normal-case">discussion</span></>
);
}
return title;
};
const Count = () => {
if (!showCount) {
return null;
}
if (count === 1) {
return (
<div className="text-[1.6rem] text-neutral-400">1 comment</div>
);
}
return (
<div className="text-[1.6rem] text-neutral-400">{count} comments</div>
);
};
return (
<div className="mb-10 flex w-full items-baseline justify-between font-sans">
<h2 className="text-[2.8rem] font-bold tracking-tight dark:text-[rgba(255,255,255,0.85)]">
<Title />
</h2>
<Count />
</div>
);
};
const CommentsBoxContent = (props) => {
const Content = (props) => {
const {pagination, member, comments, commentCount, commentsEnabled, title, showCount, secundaryFormCount} = useContext(AppContext);
const commentsElements = comments.slice().reverse().map(comment => <Comment comment={comment} key={comment.id} />);
@ -78,7 +37,7 @@ const CommentsBoxContent = (props) => {
return (
<>
<CommentsBoxTitle title={title} showCount={showCount} count={commentCount}/>
<ContentTitle title={title} showCount={showCount} count={commentCount}/>
<Pagination />
<div className={!pagination ? 'mt-4' : ''} data-test="comment-elements">
{commentsElements}
@ -93,7 +52,7 @@ const CommentsBoxContent = (props) => {
);
};
const CommentsBox = (props) => {
const ContentBox = (props) => {
const luminance = (r, g, b) => {
var a = [r, g, b].map(function (v) {
v /= 255;
@ -136,12 +95,12 @@ const CommentsBox = (props) => {
};
return (
<section className={'ghost-display ' + containerClass} style={style} data-testid="comments-box">
<section className={'ghost-display ' + containerClass} style={style} data-testid="content-box">
{props.done ? <>
<CommentsBoxContent />
<Content />
</> : <Loading />}
</section>
);
};
export default CommentsBox;
export default ContentBox;

View file

@ -0,0 +1,43 @@
const Count = ({showCount, count}) => {
if (!showCount) {
return null;
}
if (count === 1) {
return (
<div className="text-[1.6rem] text-neutral-400">1 comment</div>
);
}
return (
<div className="text-[1.6rem] text-neutral-400">{count} comments</div>
);
};
const Title = ({title}) => {
if (title === null) {
return (
<><span className="hidden sm:inline">Member </span><span className="capitalize sm:normal-case">discussion</span></>
);
}
return title;
};
const ContentTitle = ({title, showCount, count}) => {
// We have to check for null for title because null means default, wheras empty string means empty
if (!title && !showCount && title !== null) {
return null;
}
return (
<div className="mb-10 flex w-full items-baseline justify-between font-sans">
<h2 className="text-[2.8rem] font-bold tracking-tight dark:text-[rgba(255,255,255,0.85)]">
<Title title={title}/>
</h2>
<Count count={count} showCount={showCount} />
</div>
);
};
export default ContentTitle;