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,35 +23,26 @@ type Props = {
|
||||
views?: number,
|
||||
};
|
||||
|
||||
class PublishingInfo extends React.Component<Props> {
|
||||
render() {
|
||||
const { collection, document } = this.props;
|
||||
const {
|
||||
modifiedSinceViewed,
|
||||
createdAt,
|
||||
updatedAt,
|
||||
createdBy,
|
||||
updatedBy,
|
||||
publishedAt,
|
||||
} = document;
|
||||
|
||||
const timeAgo = `${distanceInWordsToNow(new Date(createdAt))} ago`;
|
||||
function PublishingInfo({ collection, document }: Props) {
|
||||
const { modifiedSinceViewed, updatedAt, updatedBy, publishedAt } = document;
|
||||
|
||||
return (
|
||||
<Container align="center">
|
||||
{publishedAt === updatedAt ? (
|
||||
{publishedAt && publishedAt === updatedAt ? (
|
||||
<span>
|
||||
{createdBy.name} published {timeAgo}
|
||||
{updatedBy.name} published <Time dateTime={publishedAt} /> ago
|
||||
</span>
|
||||
) : (
|
||||
<React.Fragment>
|
||||
{updatedBy.name}
|
||||
{publishedAt ? (
|
||||
<Modified highlight={modifiedSinceViewed}>
|
||||
modified {timeAgo}
|
||||
modified <Time dateTime={updatedAt} /> ago
|
||||
</Modified>
|
||||
) : (
|
||||
<span> saved {timeAgo}</span>
|
||||
<span>
|
||||
saved <Time dateTime={updatedAt} /> ago
|
||||
</span>
|
||||
)}
|
||||
</React.Fragment>
|
||||
)}
|
||||
@ -63,6 +54,5 @@ class PublishingInfo extends React.Component<Props> {
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default PublishingInfo;
|
||||
|
@ -28,7 +28,7 @@ const Breadcrumb = observer(({ document, collections }: Props) => {
|
||||
<span>{collection.name}</span>
|
||||
</CollectionName>
|
||||
{path.map(n => (
|
||||
<React.Fragment>
|
||||
<React.Fragment key={n.id}>
|
||||
<Slash /> <Crumb to={n.url}>{n.title}</Crumb>
|
||||
</React.Fragment>
|
||||
))}
|
||||
|
@ -1,8 +1,8 @@
|
||||
// @flow
|
||||
import * as React from 'react';
|
||||
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now';
|
||||
import ShareMenu from 'menus/ShareMenu';
|
||||
import ListItem from 'components/List/Item';
|
||||
import Time from 'shared/components/Time';
|
||||
import type { Share } from '../../../types';
|
||||
|
||||
type Props = {
|
||||
@ -16,11 +16,8 @@ const ShareListItem = ({ share }: Props) => {
|
||||
title={share.documentTitle}
|
||||
subtitle={
|
||||
<React.Fragment>
|
||||
Shared{' '}
|
||||
<time dateTime={share.createdAt}>
|
||||
{distanceInWordsToNow(new Date(share.createdAt))}
|
||||
</time>{' '}
|
||||
ago by {share.createdBy.name}
|
||||
Shared <Time dateTime={share.createdAt} /> ago by{' '}
|
||||
{share.createdBy.name}
|
||||
</React.Fragment>
|
||||
}
|
||||
actions={<ShareMenu share={share} />}
|
||||
|
@ -1,11 +1,11 @@
|
||||
// @flow
|
||||
import * as React from 'react';
|
||||
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import UserMenu from 'menus/UserMenu';
|
||||
import Avatar from 'components/Avatar';
|
||||
import ListItem from 'components/List/Item';
|
||||
import Time from 'shared/components/Time';
|
||||
import type { User } from '../../../types';
|
||||
|
||||
type Props = {
|
||||
@ -22,7 +22,7 @@ const UserListItem = ({ user, showMenu }: Props) => {
|
||||
subtitle={
|
||||
<React.Fragment>
|
||||
{user.email ? `${user.email} · ` : undefined}
|
||||
{`Joined ${distanceInWordsToNow(user.createdAt)} ago`}
|
||||
Joined <Time dateTime={user.createdAt} /> ago
|
||||
{user.isAdmin && <Badge admin={user.isAdmin}>Admin</Badge>}
|
||||
{user.isSuspended && <Badge>Suspended</Badge>}
|
||||
</React.Fragment>
|
||||
|
20
shared/components/Time.js
Normal file
20
shared/components/Time.js
Normal file
@ -0,0 +1,20 @@
|
||||
// @flow
|
||||
import * as React from 'react';
|
||||
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now';
|
||||
import format from 'date-fns/format';
|
||||
|
||||
type Props = {
|
||||
dateTime: string,
|
||||
children?: React.Node,
|
||||
};
|
||||
|
||||
function Time({ dateTime, children }: Props) {
|
||||
const date = new Date(dateTime);
|
||||
return (
|
||||
<time dateTime={dateTime} title={format(date, 'MMMM Do, YYYY h:mm a')}>
|
||||
{children || distanceInWordsToNow(date)}
|
||||
</time>
|
||||
);
|
||||
}
|
||||
|
||||
export default Time;
|
Reference in New Issue
Block a user