updatedTime.tsx
TLDR
This file contains a React component called UpdatedTime
that displays the updated time of a given card.
Classes
UpdatedTime
The UpdatedTime
class is a React component that takes in a PropertyProps
object as a parameter. It renders a <div>
element that displays the updated time of a card. The updated time is obtained by retrieving the last updated content or comment associated with the card, and then displaying the date and time using the Utils.displayDateTime
function.
END
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react'
import {useIntl} from 'react-intl'
import {Block} from '../../blocks/block'
import {Utils} from '../../utils'
import {useAppSelector} from '../../store/hooks'
import {getLastCardContent} from '../../store/contents'
import {getLastCardComment} from '../../store/comments'
import './updatedTime.scss'
import {PropertyProps} from '../types'
const UpdatedTime = (props: PropertyProps): JSX.Element => {
const intl = useIntl()
const lastContent = useAppSelector(getLastCardContent(props.card.id || '')) as Block
const lastComment = useAppSelector(getLastCardComment(props.card.id)) as Block
let latestBlock: Block = props.card
if (props.card) {
const allBlocks = [props.card, lastContent, lastComment]
const sortedBlocks = allBlocks.sort((a, b) => b.updateAt - a.updateAt)
latestBlock = sortedBlocks.length > 0 ? sortedBlocks[0] : latestBlock
}
return (
<div className={`UpdatedTime ${props.property.valueClassName(true)}`}>
{Utils.displayDateTime(new Date(latestBlock.updateAt), intl)}
</div>
)
}
export default UpdatedTime