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:
parent
a28ee5c133
commit
bea90b0922
4 changed files with 60 additions and 58 deletions
|
@ -5,7 +5,7 @@ import {createPopupNotification} from './utils/helpers';
|
||||||
import AppContext from './AppContext';
|
import AppContext from './AppContext';
|
||||||
import {hasMode} from './utils/check-mode';
|
import {hasMode} from './utils/check-mode';
|
||||||
import setupGhostApi from './utils/api';
|
import setupGhostApi from './utils/api';
|
||||||
import CommentsBox from './components/CommentsBox';
|
import ContentBox from './components/ContentBox';
|
||||||
import PopupModal from './components/PopupModal';
|
import PopupModal from './components/PopupModal';
|
||||||
|
|
||||||
function AuthFrame({adminUrl, onLoad}) {
|
function AuthFrame({adminUrl, onLoad}) {
|
||||||
|
@ -302,7 +302,7 @@ export default class App extends React.Component {
|
||||||
<SentryErrorBoundary dsn={this.props.sentryDsn}>
|
<SentryErrorBoundary dsn={this.props.sentryDsn}>
|
||||||
<AppContext.Provider value={this.getContextFromState()}>
|
<AppContext.Provider value={this.getContextFromState()}>
|
||||||
<CommentsFrame>
|
<CommentsFrame>
|
||||||
<CommentsBox done={done} />
|
<ContentBox done={done} />
|
||||||
</CommentsFrame>
|
</CommentsFrame>
|
||||||
<AuthFrame adminUrl={this.props.adminUrl} onLoad={this.initAdminAuth.bind(this)}/>
|
<AuthFrame adminUrl={this.props.adminUrl} onLoad={this.initAdminAuth.bind(this)}/>
|
||||||
<PopupModal />
|
<PopupModal />
|
||||||
|
|
|
@ -115,15 +115,15 @@ describe('Dark mode', () => {
|
||||||
const {iframeDocument} = renderApp({documentStyles: {
|
const {iframeDocument} = renderApp({documentStyles: {
|
||||||
color: '#FFFFFF'
|
color: '#FFFFFF'
|
||||||
}});
|
}});
|
||||||
const darkModeCommentsBox = await within(iframeDocument).findByTestId('comments-box');
|
const darkModeContentBox = await within(iframeDocument).findByTestId('content-box');
|
||||||
expect(darkModeCommentsBox.classList).toContain('dark');
|
expect(darkModeContentBox.classList).toContain('dark');
|
||||||
});
|
});
|
||||||
it('uses dark mode when container has a dark text color', async () => {
|
it('uses dark mode when container has a dark text color', async () => {
|
||||||
const {iframeDocument} = renderApp({documentStyles: {
|
const {iframeDocument} = renderApp({documentStyles: {
|
||||||
color: '#000000'
|
color: '#000000'
|
||||||
}});
|
}});
|
||||||
const darkModeCommentsBox = await within(iframeDocument).findByTestId('comments-box');
|
const darkModeContentBox = await within(iframeDocument).findByTestId('content-box');
|
||||||
expect(darkModeCommentsBox.classList).not.toContain('dark');
|
expect(darkModeContentBox.classList).not.toContain('dark');
|
||||||
});
|
});
|
||||||
it('uses dark mode when custom mode has been passed as a property', async () => {
|
it('uses dark mode when custom mode has been passed as a property', async () => {
|
||||||
const {iframeDocument} = renderApp({
|
const {iframeDocument} = renderApp({
|
||||||
|
@ -131,8 +131,8 @@ describe('Dark mode', () => {
|
||||||
colorScheme: 'dark'
|
colorScheme: 'dark'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const darkModeCommentsBox = await within(iframeDocument).findByTestId('comments-box');
|
const darkModeContentBox = await within(iframeDocument).findByTestId('content-box');
|
||||||
expect(darkModeCommentsBox.classList).toContain('dark');
|
expect(darkModeContentBox.classList).toContain('dark');
|
||||||
});
|
});
|
||||||
it('uses light mode when custom mode has been passed as a property', async () => {
|
it('uses light mode when custom mode has been passed as a property', async () => {
|
||||||
const {iframeDocument} = renderApp({
|
const {iframeDocument} = renderApp({
|
||||||
|
@ -141,8 +141,8 @@ describe('Dark mode', () => {
|
||||||
},
|
},
|
||||||
color: '#FFFFFF'
|
color: '#FFFFFF'
|
||||||
});
|
});
|
||||||
const darkModeCommentsBox = await within(iframeDocument).findByTestId('comments-box');
|
const darkModeContentBox = await within(iframeDocument).findByTestId('content-box');
|
||||||
expect(darkModeCommentsBox.classList).not.toContain('dark');
|
expect(darkModeContentBox.classList).not.toContain('dark');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -6,50 +6,9 @@ import Comment from './content/Comment';
|
||||||
import Pagination from './content/Pagination';
|
import Pagination from './content/Pagination';
|
||||||
import Loading from './content/Loading';
|
import Loading from './content/Loading';
|
||||||
import {ROOT_DIV_ID} from '../utils/constants';
|
import {ROOT_DIV_ID} from '../utils/constants';
|
||||||
|
import ContentTitle from './content/ContentTitle';
|
||||||
|
|
||||||
const CommentsBoxTitle = ({title, showCount, count}) => {
|
const Content = (props) => {
|
||||||
// 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 {pagination, member, comments, commentCount, commentsEnabled, title, showCount, secundaryFormCount} = useContext(AppContext);
|
const {pagination, member, comments, commentCount, commentsEnabled, title, showCount, secundaryFormCount} = useContext(AppContext);
|
||||||
const commentsElements = comments.slice().reverse().map(comment => <Comment comment={comment} key={comment.id} />);
|
const commentsElements = comments.slice().reverse().map(comment => <Comment comment={comment} key={comment.id} />);
|
||||||
|
|
||||||
|
@ -78,7 +37,7 @@ const CommentsBoxContent = (props) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<CommentsBoxTitle title={title} showCount={showCount} count={commentCount}/>
|
<ContentTitle title={title} showCount={showCount} count={commentCount}/>
|
||||||
<Pagination />
|
<Pagination />
|
||||||
<div className={!pagination ? 'mt-4' : ''} data-test="comment-elements">
|
<div className={!pagination ? 'mt-4' : ''} data-test="comment-elements">
|
||||||
{commentsElements}
|
{commentsElements}
|
||||||
|
@ -93,7 +52,7 @@ const CommentsBoxContent = (props) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const CommentsBox = (props) => {
|
const ContentBox = (props) => {
|
||||||
const luminance = (r, g, b) => {
|
const luminance = (r, g, b) => {
|
||||||
var a = [r, g, b].map(function (v) {
|
var a = [r, g, b].map(function (v) {
|
||||||
v /= 255;
|
v /= 255;
|
||||||
|
@ -136,12 +95,12 @@ const CommentsBox = (props) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
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 ? <>
|
{props.done ? <>
|
||||||
<CommentsBoxContent />
|
<Content />
|
||||||
</> : <Loading />}
|
</> : <Loading />}
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default CommentsBox;
|
export default ContentBox;
|
43
apps/comments-ui/src/components/content/ContentTitle.js
Normal file
43
apps/comments-ui/src/components/content/ContentTitle.js
Normal 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;
|
Loading…
Reference in a new issue