Fixed: Modified time display on dashboard
New Time component for relative time formatting with accessibility
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
// @flow
|
||||
import * as React from 'react';
|
||||
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now';
|
||||
import styled from 'styled-components';
|
||||
import Collection from 'models/Collection';
|
||||
import Document from 'models/Document';
|
||||
import Flex from 'shared/components/Flex';
|
||||
import Time from 'shared/components/Time';
|
||||
|
||||
const Container = styled(Flex)`
|
||||
color: ${props => props.theme.slate};
|
||||
@@ -23,46 +23,36 @@ type Props = {
|
||||
views?: number,
|
||||
};
|
||||
|
||||
class PublishingInfo extends React.Component<Props> {
|
||||
render() {
|
||||
const { collection, document } = this.props;
|
||||
const {
|
||||
modifiedSinceViewed,
|
||||
createdAt,
|
||||
updatedAt,
|
||||
createdBy,
|
||||
updatedBy,
|
||||
publishedAt,
|
||||
} = document;
|
||||
function PublishingInfo({ collection, document }: Props) {
|
||||
const { modifiedSinceViewed, updatedAt, updatedBy, publishedAt } = document;
|
||||
|
||||
const timeAgo = `${distanceInWordsToNow(new Date(createdAt))} ago`;
|
||||
|
||||
return (
|
||||
<Container align="center">
|
||||
{publishedAt === updatedAt ? (
|
||||
<span>
|
||||
{createdBy.name} published {timeAgo}
|
||||
</span>
|
||||
) : (
|
||||
<React.Fragment>
|
||||
{updatedBy.name}
|
||||
{publishedAt ? (
|
||||
<Modified highlight={modifiedSinceViewed}>
|
||||
modified {timeAgo}
|
||||
</Modified>
|
||||
) : (
|
||||
<span> saved {timeAgo}</span>
|
||||
)}
|
||||
</React.Fragment>
|
||||
)}
|
||||
{collection && (
|
||||
<span>
|
||||
in <strong>{collection.name}</strong>
|
||||
</span>
|
||||
)}
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<Container align="center">
|
||||
{publishedAt && publishedAt === updatedAt ? (
|
||||
<span>
|
||||
{updatedBy.name} published <Time dateTime={publishedAt} /> ago
|
||||
</span>
|
||||
) : (
|
||||
<React.Fragment>
|
||||
{updatedBy.name}
|
||||
{publishedAt ? (
|
||||
<Modified highlight={modifiedSinceViewed}>
|
||||
modified <Time dateTime={updatedAt} /> ago
|
||||
</Modified>
|
||||
) : (
|
||||
<span>
|
||||
saved <Time dateTime={updatedAt} /> ago
|
||||
</span>
|
||||
)}
|
||||
</React.Fragment>
|
||||
)}
|
||||
{collection && (
|
||||
<span>
|
||||
in <strong>{collection.name}</strong>
|
||||
</span>
|
||||
)}
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
export default PublishingInfo;
|
||||
|
||||
Reference in New Issue
Block a user