Youtube VideoPreview component with proper view count formatting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*...*/ | |
import {getShortNumberString} from '../../services/number/number-format'; | |
TimeAgo.locale(en); | |
const timeAgo = new TimeAgo('en-US'); | |
export class VideoPreview extends React.Component { | |
render() { | |
{/* unchanged */} | |
} | |
static getFormattedViewAndTime(video) { | |
const publicationDate = new Date(video.snippet.publishedAt); | |
const viewCount = video.statistics ? video.statistics.viewCount : null; | |
if(viewCount) { | |
const viewCountShort = getShortNumberString(video.statistics.viewCount); | |
return `${viewCountShort} views • ${timeAgo.format(publicationDate)}`; | |
} | |
return ''; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment