Skip to content
This repository has been archived by the owner on Aug 5, 2023. It is now read-only.

Commit

Permalink
Fixed bug causing time received on recent message card to be displaye…
Browse files Browse the repository at this point in the history
…d incorrectly
  • Loading branch information
jusexton committed Mar 11, 2021
1 parent b676f3e commit 83ca6cf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.1.3

- Fixed bug causing the time received on the recent message card to be displayed incorrectly

# 1.1.2

- Updated API routes to new routes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "portfolio-website",
"version": "1.1.2",
"version": "1.1.3",
"private": true,
"dependencies": {
"@hookform/resolvers": "^0.1.0",
Expand Down
31 changes: 21 additions & 10 deletions src/components/Dashboard/Dash/RecentMessageCard/index.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
import { Card, CardContent, Grid, Typography } from '@material-ui/core'
import MailIcon from '@material-ui/icons/Mail'
import PropTypes from 'prop-types'
import React from 'react'
import React, { useEffect, useState } from 'react'

export const RecentMessageCard = ({ message, onClick, elevate = true }) => {
const [elevation, setElevation] = React.useState(5)
const [received, setReceived] = useState()

useEffect(() => {
const getDaysAgo = (date) => {
const now = new Date()
return Math.floor((now - date) / (1000 * 60 * 60 * 24))
}

const date = new Date(message.timeCreated)
const daysAgo = getDaysAgo(date)

if (daysAgo < 1) {
setReceived('Today')
} else if (daysAgo >= 1 && daysAgo < 2) {
setReceived('Yesterday')
} else {
setReceived(`${daysAgo} days ago`)
}
}, [message])

const handleMouseOver = () => elevate && setElevation(12)
const handleMouseOut = () => elevate && setElevation(5)

const daysAgo = (dateString) => {
const now = new Date()
const date = new Date(dateString)
return Math.floor((now - date) / (1000 * 60 * 60 * 24))
}

return (
<Card
elevation={elevation}
Expand All @@ -28,9 +41,7 @@ export const RecentMessageCard = ({ message, onClick, elevate = true }) => {
<Typography style={{ marginRight: '12px' }}>
{message.sender.alias}
</Typography>
<Typography variant="caption">
{daysAgo(message.timeCreated)} days ago
</Typography>
<Typography variant="caption">{received}</Typography>
</Grid>

<Typography style={{ marginTop: '8px' }}>{message.message}</Typography>
Expand Down

0 comments on commit 83ca6cf

Please sign in to comment.