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

Commit 83ca6cf

Browse files
committed
Fixed bug causing time received on recent message card to be displayed incorrectly
1 parent b676f3e commit 83ca6cf

3 files changed

Lines changed: 26 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.1.3
2+
3+
- Fixed bug causing the time received on the recent message card to be displayed incorrectly
4+
15
# 1.1.2
26

37
- Updated API routes to new routes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "portfolio-website",
3-
"version": "1.1.2",
3+
"version": "1.1.3",
44
"private": true,
55
"dependencies": {
66
"@hookform/resolvers": "^0.1.0",

src/components/Dashboard/Dash/RecentMessageCard/index.jsx

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
11
import { Card, CardContent, Grid, Typography } from '@material-ui/core'
22
import MailIcon from '@material-ui/icons/Mail'
33
import PropTypes from 'prop-types'
4-
import React from 'react'
4+
import React, { useEffect, useState } from 'react'
55

66
export const RecentMessageCard = ({ message, onClick, elevate = true }) => {
77
const [elevation, setElevation] = React.useState(5)
8+
const [received, setReceived] = useState()
9+
10+
useEffect(() => {
11+
const getDaysAgo = (date) => {
12+
const now = new Date()
13+
return Math.floor((now - date) / (1000 * 60 * 60 * 24))
14+
}
15+
16+
const date = new Date(message.timeCreated)
17+
const daysAgo = getDaysAgo(date)
18+
19+
if (daysAgo < 1) {
20+
setReceived('Today')
21+
} else if (daysAgo >= 1 && daysAgo < 2) {
22+
setReceived('Yesterday')
23+
} else {
24+
setReceived(`${daysAgo} days ago`)
25+
}
26+
}, [message])
827

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

12-
const daysAgo = (dateString) => {
13-
const now = new Date()
14-
const date = new Date(dateString)
15-
return Math.floor((now - date) / (1000 * 60 * 60 * 24))
16-
}
17-
1831
return (
1932
<Card
2033
elevation={elevation}
@@ -28,9 +41,7 @@ export const RecentMessageCard = ({ message, onClick, elevate = true }) => {
2841
<Typography style={{ marginRight: '12px' }}>
2942
{message.sender.alias}
3043
</Typography>
31-
<Typography variant="caption">
32-
{daysAgo(message.timeCreated)} days ago
33-
</Typography>
44+
<Typography variant="caption">{received}</Typography>
3445
</Grid>
3546

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

0 commit comments

Comments
 (0)