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
|
// @flow
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now';
|
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import Collection from 'models/Collection';
|
import Collection from 'models/Collection';
|
||||||
import Document from 'models/Document';
|
import Document from 'models/Document';
|
||||||
import Flex from 'shared/components/Flex';
|
import Flex from 'shared/components/Flex';
|
||||||
|
import Time from 'shared/components/Time';
|
||||||
|
|
||||||
const Container = styled(Flex)`
|
const Container = styled(Flex)`
|
||||||
color: ${props => props.theme.slate};
|
color: ${props => props.theme.slate};
|
||||||
@ -23,46 +23,36 @@ type Props = {
|
|||||||
views?: number,
|
views?: number,
|
||||||
};
|
};
|
||||||
|
|
||||||
class PublishingInfo extends React.Component<Props> {
|
function PublishingInfo({ collection, document }: Props) {
|
||||||
render() {
|
const { modifiedSinceViewed, updatedAt, updatedBy, publishedAt } = document;
|
||||||
const { collection, document } = this.props;
|
|
||||||
const {
|
|
||||||
modifiedSinceViewed,
|
|
||||||
createdAt,
|
|
||||||
updatedAt,
|
|
||||||
createdBy,
|
|
||||||
updatedBy,
|
|
||||||
publishedAt,
|
|
||||||
} = document;
|
|
||||||
|
|
||||||
const timeAgo = `${distanceInWordsToNow(new Date(createdAt))} ago`;
|
return (
|
||||||
|
<Container align="center">
|
||||||
return (
|
{publishedAt && publishedAt === updatedAt ? (
|
||||||
<Container align="center">
|
<span>
|
||||||
{publishedAt === updatedAt ? (
|
{updatedBy.name} published <Time dateTime={publishedAt} /> ago
|
||||||
<span>
|
</span>
|
||||||
{createdBy.name} published {timeAgo}
|
) : (
|
||||||
</span>
|
<React.Fragment>
|
||||||
) : (
|
{updatedBy.name}
|
||||||
<React.Fragment>
|
{publishedAt ? (
|
||||||
{updatedBy.name}
|
<Modified highlight={modifiedSinceViewed}>
|
||||||
{publishedAt ? (
|
modified <Time dateTime={updatedAt} /> ago
|
||||||
<Modified highlight={modifiedSinceViewed}>
|
</Modified>
|
||||||
modified {timeAgo}
|
) : (
|
||||||
</Modified>
|
<span>
|
||||||
) : (
|
saved <Time dateTime={updatedAt} /> ago
|
||||||
<span> saved {timeAgo}</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
)}
|
)}
|
||||||
{collection && (
|
{collection && (
|
||||||
<span>
|
<span>
|
||||||
in <strong>{collection.name}</strong>
|
in <strong>{collection.name}</strong>
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default PublishingInfo;
|
export default PublishingInfo;
|
||||||
|
@ -28,7 +28,7 @@ const Breadcrumb = observer(({ document, collections }: Props) => {
|
|||||||
<span>{collection.name}</span>
|
<span>{collection.name}</span>
|
||||||
</CollectionName>
|
</CollectionName>
|
||||||
{path.map(n => (
|
{path.map(n => (
|
||||||
<React.Fragment>
|
<React.Fragment key={n.id}>
|
||||||
<Slash /> <Crumb to={n.url}>{n.title}</Crumb>
|
<Slash /> <Crumb to={n.url}>{n.title}</Crumb>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
))}
|
))}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now';
|
|
||||||
import ShareMenu from 'menus/ShareMenu';
|
import ShareMenu from 'menus/ShareMenu';
|
||||||
import ListItem from 'components/List/Item';
|
import ListItem from 'components/List/Item';
|
||||||
|
import Time from 'shared/components/Time';
|
||||||
import type { Share } from '../../../types';
|
import type { Share } from '../../../types';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@ -16,11 +16,8 @@ const ShareListItem = ({ share }: Props) => {
|
|||||||
title={share.documentTitle}
|
title={share.documentTitle}
|
||||||
subtitle={
|
subtitle={
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
Shared{' '}
|
Shared <Time dateTime={share.createdAt} /> ago by{' '}
|
||||||
<time dateTime={share.createdAt}>
|
{share.createdBy.name}
|
||||||
{distanceInWordsToNow(new Date(share.createdAt))}
|
|
||||||
</time>{' '}
|
|
||||||
ago by {share.createdBy.name}
|
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
}
|
}
|
||||||
actions={<ShareMenu share={share} />}
|
actions={<ShareMenu share={share} />}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now';
|
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
|
|
||||||
import UserMenu from 'menus/UserMenu';
|
import UserMenu from 'menus/UserMenu';
|
||||||
import Avatar from 'components/Avatar';
|
import Avatar from 'components/Avatar';
|
||||||
import ListItem from 'components/List/Item';
|
import ListItem from 'components/List/Item';
|
||||||
|
import Time from 'shared/components/Time';
|
||||||
import type { User } from '../../../types';
|
import type { User } from '../../../types';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@ -22,7 +22,7 @@ const UserListItem = ({ user, showMenu }: Props) => {
|
|||||||
subtitle={
|
subtitle={
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
{user.email ? `${user.email} · ` : undefined}
|
{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.isAdmin && <Badge admin={user.isAdmin}>Admin</Badge>}
|
||||||
{user.isSuspended && <Badge>Suspended</Badge>}
|
{user.isSuspended && <Badge>Suspended</Badge>}
|
||||||
</React.Fragment>
|
</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