Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate CSS of PostTime and PostStatus blocks to CSS, plus a few tweaks #30963

Merged
merged 3 commits into from
Feb 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions assets/stylesheets/_components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
@import 'blocks/post-item/style';
@import 'blocks/post-likes/style';
@import 'blocks/post-share/style';
@import 'blocks/post-status/style';
@import 'blocks/post-time/style';
@import 'blocks/privacy-policy-banner/style';
@import 'blocks/sharing-preview-pane/style';
@import 'blocks/site-address-changer/style';
Expand Down
24 changes: 14 additions & 10 deletions client/blocks/post-status/docs/example.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,27 @@ function PostStatusExample( { queries, primarySiteId, primarySiteUrl, globalIdBy
);
}

const queries = {
Scheduled: { status: 'future', number: 1, type: 'any' },
Trashed: { status: 'trash', number: 1, type: 'any' },
'Pending Review': { status: 'pending', number: 1, type: 'any' },
Sticky: { sticky: 'require', number: 1, type: 'any' },
};

const getFirstGlobalIdByQueryLabel = ( state, siteId ) =>
mapValues( queries, query => {
const postsForQuery = getPostsForQuery( state, siteId, query );
return get( postsForQuery, [ 0, 'global_ID' ] );
} );

const ConnectedPostStatusExample = connect( state => {
const user = getCurrentUser( state );
const primarySiteId = get( user, 'primary_blog' );
const queries = {
Scheduled: { status: 'future', number: 1, type: 'any' },
Trashed: { status: 'trash', number: 1, type: 'any' },
'Pending Review': { status: 'pending', number: 1, type: 'any' },
Sticky: { sticky: 'require', number: 1, type: 'any' },
};

return {
queries,
primarySiteId,
primarySiteUrl: get( user, 'primary_blog_url' ),
globalIdByQueryLabel: mapValues( queries, query => {
return get( getPostsForQuery( state, primarySiteId, query ), [ 0, 'global_ID' ] );
} ),
globalIdByQueryLabel: getFirstGlobalIdByQueryLabel( state, primarySiteId ),
};
} )( PostStatusExample );

Expand Down
13 changes: 8 additions & 5 deletions client/blocks/post-status/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ import Gridicon from 'gridicons';
*/
import { getNormalizedPost } from 'state/posts/selectors';

/**
* Style dependencies
*/
import './style.scss';

export function PostStatus( { translate, post, showAll, showIcon = true } ) {
if ( ! post ) {
return null;
Expand Down Expand Up @@ -73,8 +78,6 @@ PostStatus.propTypes = {
showIcon: PropTypes.bool,
};

export default connect( ( state, { globalId } ) => {
return {
post: getNormalizedPost( state, globalId ),
};
} )( localize( PostStatus ) );
export default connect( ( state, { globalId } ) => ( {
post: getNormalizedPost( state, globalId ),
} ) )( localize( PostStatus ) );
28 changes: 16 additions & 12 deletions client/blocks/post-time/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,29 @@ import PropTypes from 'prop-types';
import classNames from 'classnames';
import { connect } from 'react-redux';
import { includes } from 'lodash';
import { localize } from 'i18n-calypso';

/**
* Internal dependencies
*/
import { getNormalizedPost } from 'state/posts/selectors';
import withLocalizedMoment from 'components/with-localized-moment';

/**
* Style dependencies
*/
import './style.scss';

function getDisplayedTimeFromPost( moment, post ) {
const now = moment();

if ( ! post ) {
// Placeholder text: "a few seconds ago" in English locale
return moment().fromNow();
return now.fromNow();
}

const { status, modified, date } = post;
const time = moment( includes( [ 'draft', 'pending' ], status ) ? modified : date );
if ( time.isBefore( moment().subtract( 7, 'days' ) ) ) {
if ( now.diff( time, 'days' ) >= 7 ) {
// Like "Mar 15, 2013 6:23 PM" in English locale
return time.format( 'lll' );
}
Expand All @@ -34,11 +41,10 @@ function getDisplayedTimeFromPost( moment, post ) {
}

export function PostTime( { moment, post } ) {
const classes = classNames( 'post-time', {
'is-placeholder': ! post,
} );
const classes = classNames( 'post-time', { 'is-placeholder': ! post } );
const displayedTime = getDisplayedTimeFromPost( moment, post );

return <span className={ classes }>{ getDisplayedTimeFromPost( moment, post ) }</span>;
return <span className={ classes }>{ displayedTime }</span>;
}

PostTime.propTypes = {
Expand All @@ -47,8 +53,6 @@ PostTime.propTypes = {
post: PropTypes.object,
};

export default connect( ( state, { globalId } ) => {
return {
post: getNormalizedPost( state, globalId ),
};
} )( localize( PostTime ) );
export default connect( ( state, { globalId } ) => ( {
post: getNormalizedPost( state, globalId ),
} ) )( withLocalizedMoment( PostTime ) );
19 changes: 8 additions & 11 deletions client/post-editor/editor-post-type/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@ import { localize } from 'i18n-calypso';
* Internal dependencies
*/
import { getEditedPost } from 'state/posts/selectors';
import { getSelectedSite } from 'state/ui/selectors';
import { getSelectedSiteId } from 'state/ui/selectors';
import { getEditorPostId } from 'state/ui/editor/selectors';
import { getPostType } from 'state/post-types/selectors';
import QueryPostTypes from 'components/data/query-post-types';
import { decodeEntities } from 'lib/formatting';
import PostStatus from 'blocks/post-status';

/**
* Style dependencies
*/
import './style.scss';

function EditorPostType( { translate, siteId, typeSlug, type, globalId, isSettings } ) {
function EditorPostType( { translate, siteId, typeSlug, type, isSettings } ) {
let label;
if ( 'page' === typeSlug ) {
if ( isSettings ) {
Expand Down Expand Up @@ -64,7 +63,7 @@ function EditorPostType( { translate, siteId, typeSlug, type, globalId, isSettin
{ siteId && 'page' !== typeSlug && 'post' !== typeSlug && (
<QueryPostTypes siteId={ siteId } />
) }
{ label } <PostStatus globalId={ globalId } showAll showIcon={ false } />
{ label }
</span>
);
}
Expand All @@ -74,26 +73,24 @@ EditorPostType.propTypes = {
siteId: PropTypes.number,
typeSlug: PropTypes.string,
type: PropTypes.object,
globalId: PropTypes.string,
isSettings: PropTypes.bool,
};

export default connect( state => {
const props = {};
const site = getSelectedSite( state );
if ( ! site ) {
const siteId = getSelectedSiteId( state );
if ( ! siteId ) {
return props;
}

props.siteId = site.ID;
const post = getEditedPost( state, site.ID, getEditorPostId( state ) );
props.siteId = siteId;
const post = getEditedPost( state, siteId, getEditorPostId( state ) );
if ( ! post ) {
return props;
}

return Object.assign( props, {
typeSlug: post.type,
type: getPostType( state, site.ID, post.type ),
globalId: post.global_ID,
type: getPostType( state, siteId, post.type ),
} );
} )( localize( EditorPostType ) );
7 changes: 0 additions & 7 deletions client/post-editor/editor-post-type/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,4 @@
&.is-loading {
@include placeholder;
}

.post-status__text {
display: none;
color: var( --color-neutral-400 );
margin-left: 4px;
vertical-align: baseline;
}
}