Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
add last modified timeago to scene cards
Browse files Browse the repository at this point in the history
  • Loading branch information
kfarr committed Sep 21, 2023
1 parent 4b14ef4 commit 07f2934
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 17 deletions.
52 changes: 38 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@types/uuid": "^9.0.0",
"classnames": "^2.3.2",
"clipboard": "^2.0.11",
"date-fns": "^2.30.0",
"dotenv-webpack": "^8.0.1",
"file-loader": "^6.2.0",
"firebase": "^9.23.0",
Expand Down
17 changes: 14 additions & 3 deletions src/components/components/SceneCard/SceneCard.component.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import React from 'react';
import ScenePlaceholder from '../../../../assets/scene.png';
import styles from './SceneCard.module.scss';
import { formatDistanceToNow } from 'date-fns';

function LastModified({ timestamp }) {
// Convert Firestore Timestamp to JavaScript Date object
const date = timestamp.toDate();

// Use date-fns to get "time ago" format
const timeAgo = formatDistanceToNow(date, { addSuffix: true });

return <p className={styles.date}>Last modified {timeAgo}</p>;
}

const SceneCard = ({ scenesData, handleSceneClick }) => (
<div className={styles.wrapper}>
Expand All @@ -13,9 +24,9 @@ const SceneCard = ({ scenesData, handleSceneClick }) => (
>
<img src={ScenePlaceholder} alt="scene" className={styles.img} />
<p className={styles.title}>{scene.data().title}</p>
{/* <p className={styles.date}>
Last modified 2 hours ago
</p> */}
<p className={styles.date}>
<LastModified timestamp={scene.data().updateTimestamp} />
</p>
</div>
))}
</div>
Expand Down

0 comments on commit 07f2934

Please sign in to comment.