Add date meta to json and new tag to ui

This commit is contained in:
Steve Paul
2024-11-22 15:56:11 +05:30
parent 9c8be3e861
commit 3a47ecbb96
3 changed files with 20 additions and 10 deletions
+13 -1
View File
@@ -1,7 +1,18 @@
import "./Card.css"; import "./Card.css";
export default function Card(props) { export default function Card(props) {
const { href, title, body, tag } = props; const { href, title, body, tag, dateAdded } = props;
const isNew = () => {
if (!dateAdded) return false;
const addedDate = new Date(dateAdded);
const today = new Date();
const differenceInTime = today.getTime() - addedDate.getTime();
const differenceInDays = differenceInTime / (1000 * 3600 * 24);
return differenceInDays <= 30;
};
return ( return (
<li className="link-card"> <li className="link-card">
@@ -9,6 +20,7 @@ export default function Card(props) {
<strong className="nu-c-h6 nu-u-mt-1 nu-u-mb-1">{title}</strong> <strong className="nu-c-h6 nu-u-mt-1 nu-u-mb-1">{title}</strong>
<p className="nu-c-fs-small nu-u-mt-1 nu-u-mb-1">{body}</p> <p className="nu-c-fs-small nu-u-mt-1 nu-u-mb-1">{body}</p>
<p className="distribution"> <p className="distribution">
{isNew() && <span className="tag nu-u-me-2">New</span>}
<span className="tag">{tag}</span> <span className="tag">{tag}</span>
</p> </p>
</a> </a>
+2 -1
View File
@@ -14,13 +14,14 @@ export default function CardsContainer({ filter }) {
return ( return (
<section> <section>
<ul role="list" className="link-card-grid"> <ul role="list" className="link-card-grid">
{filteredCards.map(({ url, title, body, tag }, i) => ( {filteredCards.map(({ url, title, body, tag, "date-added": dateAdded }, i) => (
<Card <Card
key={`${title}-${i}`} key={`${title}-${i}`}
href={url} href={url}
title={title} title={title}
body={body} body={body}
tag={tag} tag={tag}
dateAdded={dateAdded}
/> />
))} ))}
</ul> </ul>
+5 -8
View File
@@ -3,6 +3,8 @@
box-shadow: inset 0px -1px 0px var(--border-muted); box-shadow: inset 0px -1px 0px var(--border-muted);
white-space: nowrap; white-space: nowrap;
overflow-x: scroll; overflow-x: scroll;
/* scrollbar-width: none; /* Firefox */
/* -ms-overflow-style: none; /* Internet Explorer and Edge */
position: sticky; position: sticky;
top: 0; top: 0;
background-color: var(--background); background-color: var(--background);
@@ -13,12 +15,7 @@
z-index: 999999; z-index: 999999;
} }
/* hide scrollbar /* Hide scrollbar for Chrome, Safari and Opera */
.category-nav { /* .category-nav::-webkit-scrollbar {
scrollbar-width: none;
-ms-overflow-style: none;
}
.category-nav::-webkit-scrollbar{
display: none; display: none;
} } */
*/