Skip to content

Commit 32792e0

Browse files
author
Vivek Vishal
authored
feat: add date column and new badge to latest session
Signed-off-by: Vivek Vishal <vishalvivek488@gmail.com>
1 parent 1a12b8c commit 32792e0

1 file changed

Lines changed: 40 additions & 4 deletions

File tree

  • src/sections/Community/Newcomers-guide/Tutorials-table

src/sections/Community/Newcomers-guide/Tutorials-table/index.js

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,42 @@ const TutorialsTable = () => {
88

99
const columns = React.useMemo(
1010
() => [
11+
{
12+
Header: "Date",
13+
accessor: "date",
14+
Cell: ({ value }) => {
15+
const parsedDate = new Date(value);
16+
return (
17+
<span>
18+
{parsedDate.toLocaleDateString("en-US", {
19+
year: "numeric",
20+
month: "short",
21+
day: "numeric",
22+
})}
23+
</span>
24+
);
25+
}
26+
},
1127
{
1228
Header: "Topic",
1329
accessor: "topic",
30+
Cell: ({ row, value }) => {
31+
const parsedDate = new Date(row.original.date);
32+
const thisYear = new Date().getFullYear();
33+
const isNew = parsedDate.getFullYear() === thisYear;
34+
35+
return (
36+
<span className="newBadge">
37+
{value}
38+
{isNew && (
39+
<img
40+
src="/images/new-badge.png"
41+
alt="New"
42+
/>
43+
)}
44+
</span>
45+
);
46+
},
1447
},
1548
{
1649
Header: "Resources",
@@ -39,17 +72,19 @@ const TutorialsTable = () => {
3972
],
4073
[]
4174
);
75+
const sortedData = React.useMemo(() => {
76+
return [...data].sort((a, b) => new Date(b.date) - new Date(a.date));
77+
}, []);
4278

79+
const tableInstance = useTable({ columns, data: sortedData });
4380
const {
4481
getTableProps,
4582
getTableBodyProps,
4683
headerGroups,
4784
rows,
4885
prepareRow,
49-
} = useTable({
50-
columns,
51-
data,
52-
});
86+
} = tableInstance;
87+
5388

5489
return (
5590
<TutorialsTableWrapper>
@@ -88,3 +123,4 @@ const TutorialsTable = () => {
88123
};
89124

90125
export default TutorialsTable;
126+

0 commit comments

Comments
 (0)