Timestamp: Eliminate 'Invalid date' from potential output

This commit is contained in:
Scott Nonnenberg 2018-07-18 08:14:34 -07:00
parent 60f61c804b
commit 95976b10e7
2 changed files with 30 additions and 1 deletions

View file

@ -184,3 +184,28 @@ We only show one line.
/>
</div>
```
#### Missing data
```jsx
<div>
<ConversationListItem
name="John"
lastUpdated={null}
lastMessage={{
text: 'Missing last updated',
}}
onClick={() => console.log('onClick')}
i18n={util.i18n}
/>
<ConversationListItem
name="Missing message"
lastUpdated={Date.now() - 5 * 60 * 1000}
lastMessage={{
text: null,
}}
onClick={() => console.log('onClick')}
i18n={util.i18n}
/>
</div>
```

View file

@ -7,7 +7,7 @@ import { formatRelativeTime } from '../../util/formatRelativeTime';
import { Localizer } from '../../types/Util';
interface Props {
timestamp: number;
timestamp: number | null;
extended: boolean;
module?: string;
withImageNoCaption?: boolean;
@ -52,6 +52,10 @@ export class Timestamp extends React.Component<Props> {
} = this.props;
const moduleName = module || 'module-timestamp';
if (timestamp === null || timestamp === undefined) {
return null;
}
return (
<span
className={classNames(