diff options
Diffstat (limited to 'frontend/src/components/record.js')
| -rw-r--r-- | frontend/src/components/record.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/frontend/src/components/record.js b/frontend/src/components/record.js new file mode 100644 index 0000000..a01109c --- /dev/null +++ b/frontend/src/components/record.js | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | import React, { useEffect, useRef, useState } from 'react'; | ||
| 2 | import { useLocation, Link } from "react-router-dom"; | ||
| 3 | |||
| 4 | import "./record.css" | ||
| 5 | |||
| 6 | export default function Record({ name, place, portals, time, date }) { | ||
| 7 | // const {token} = prop; | ||
| 8 | const [record, setRecord] = useState(null); | ||
| 9 | const location = useLocation(); | ||
| 10 | |||
| 11 | useEffect(() => { | ||
| 12 | console.log(name, place, portals, time, date); | ||
| 13 | }) | ||
| 14 | |||
| 15 | function timeSince() { | ||
| 16 | const now = new Date(); | ||
| 17 | const dateNew = new Date(date); | ||
| 18 | |||
| 19 | const secondsPast = Math.floor((now - dateNew) / 1000); | ||
| 20 | console.log('Seconds past:', secondsPast); | ||
| 21 | |||
| 22 | if (secondsPast < 60) { | ||
| 23 | return `${secondsPast} seconds ago`; | ||
| 24 | } | ||
| 25 | if (secondsPast < 3600) { | ||
| 26 | const minutes = Math.floor(secondsPast / 60); | ||
| 27 | return `${minutes} minutes ago`; | ||
| 28 | } | ||
| 29 | if (secondsPast < 86400) { | ||
| 30 | const hours = Math.floor(secondsPast / 3600); | ||
| 31 | return `${hours} hours ago`; | ||
| 32 | } | ||
| 33 | if (secondsPast < 2592000) { | ||
| 34 | const days = Math.floor(secondsPast / 86400); | ||
| 35 | return `${days} days ago`; | ||
| 36 | } | ||
| 37 | if (secondsPast < 31536000) { | ||
| 38 | const months = Math.floor(secondsPast / 2592000); | ||
| 39 | return `${months} months ago`; | ||
| 40 | } | ||
| 41 | const years = Math.floor(secondsPast / 31536000); | ||
| 42 | return `${years} years ago`; | ||
| 43 | } | ||
| 44 | |||
| 45 | return( | ||
| 46 | <div className='record-container'> | ||
| 47 | <span>{place}</span> | ||
| 48 | <div style={{display: "flex", alignItems: "center"}}> | ||
| 49 | <img style={{height: "40px", borderRadius: "200px"}} src="https://avatars.steamstatic.com/32d110951da2339d8b8d8419bc945d9a2b150b2a_full.jpg"></img> | ||
| 50 | <span style={{paddingLeft: "5px", fontFamily: "BarlowSemiCondensed-SemiBold"}}>{name}</span> | ||
| 51 | </div> | ||
| 52 | <span style={{fontFamily: "BarlowCondensed-Bold", color: "#D980FF"}}>{portals}</span> | ||
| 53 | <span>{time}</span> | ||
| 54 | <span>{timeSince()}</span> | ||
| 55 | </div> | ||
| 56 | ) | ||
| 57 | } | ||