Skip to content

Commit

Permalink
Improving appearance of date time, adding full time in overlay for co…
Browse files Browse the repository at this point in the history
…mment times.
  • Loading branch information
krulis-martin committed Jul 21, 2022
1 parent 261f278 commit d2adff0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/components/widgets/Comments/Comment/Comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const Comment = ({
})}>
<Link to={USER_URI_FACTORY(user.id)}>{user.name}</Link>
</span>
{status === 'posted' && <Posted right={!right} postedAt={postedAt} />}
{status === 'posted' && <Posted id={id} right={!right} postedAt={postedAt} />}
{status === 'failed' && <Failed right={!right} repost={() => repost && repost(id)} />}
{status === 'pending' && <Posting right={!right} />}
</div>
Expand Down
19 changes: 16 additions & 3 deletions src/components/widgets/Comments/Comment/Status/Posted.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { FormattedRelativeTime } from 'react-intl';
import DateTime from '../../../DateTime';

const Posted = ({ right, postedAt }) => (
const OVERLAY_PROPS = {
showRelative: false,
};

const Posted = ({ id, right, postedAt }) => (
<span
className={classnames({
'direct-chat-timestamp': true,
'float-right': right,
'float-left': !right,
})}>
<FormattedRelativeTime value={postedAt - Date.now() / 1000} numeric="auto" updateIntervalInSeconds={1000000} />
<DateTime
unixts={postedAt}
showRelative
showDate={false}
showTime={false}
showOverlay={true}
overlayTooltipId={`postedAt-${id}`}
overlayProps={OVERLAY_PROPS}
/>
</span>
);

Posted.propTypes = {
id: PropTypes.string.isRequired,
right: PropTypes.bool.isRequired,
postedAt: PropTypes.number.isRequired,
};
Expand Down
13 changes: 8 additions & 5 deletions src/components/widgets/DateTime/DateTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { FormattedDate, FormattedTime, FormattedRelativeTime } from 'react-intl'
import classnames from 'classnames';

import Icon from '../../icons';
import { EMPTY_OBJ } from '../../../helpers/common';

import styles from './DateTime.less';

Expand Down Expand Up @@ -40,28 +41,27 @@ const dateTime = ({
<span
className={classnames({
'text-nowrap': true,
'halfem-margin-right': showTime || showRelative,
})}>
<FormattedDate value={unixts * 1000} />
{(showTime || showRelative) && <span className="px-1"> </span>}
</span>
)}
&#8203;

{showTime && (
<span
className={classnames({
'text-nowrap': true,
'halfem-margin-right': showRelative,
})}>
<FormattedTime value={unixts * 1000} format={showSeconds ? '24hourWithSeconds' : '24hour'} />
{showRelative && <span className="px-1"> </span>}
</span>
)}
&#8203;

{showRelative && (
<span
className={classnames({
'text-nowrap': true,
[styles.trailingRelative]: showDate || showTime,
[styles.standaloneRelative]: !showDate && !showTime,
})}>
<FormattedRelativeTime value={unixts - Date.now() / 1000} numeric="auto" updateIntervalInSeconds={1000000} />
</span>
Expand All @@ -76,6 +76,7 @@ const DateTime = ({
showTime = true,
showRelative = false,
showOverlay = false,
overlayProps = EMPTY_OBJ,
overlayTooltipId = 'datetime',
customTooltip = null,
...props
Expand All @@ -96,6 +97,7 @@ const DateTime = ({
showSeconds: true,
isDeadline: false,
noWrap: false,
...overlayProps,
})}
</Tooltip>
}>
Expand Down Expand Up @@ -133,6 +135,7 @@ DateTime.propTypes = {
showOverlay: PropTypes.bool,
overlayTooltipId: PropTypes.string,
customTooltip: PropTypes.any,
overlayProps: PropTypes.object,
};

export default DateTime;
4 changes: 0 additions & 4 deletions src/components/widgets/DateTime/DateTime.less
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,3 @@
.trailingRelative::after {
content: ')';
}

.standaloneRelative {
font-style: italic;
}

0 comments on commit d2adff0

Please sign in to comment.