Skip to content

Commit 218f341

Browse files
committed
feat: Add relative time to commit messages
1 parent bb7f8cb commit 218f341

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

vite-project/src/app/module.css

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
height: 3rem;
66
background-color: #f8f8f8;
77
border-bottom: 1px solid #eaeaea;
8-
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
98
z-index: 100;
109
width: 100%;
1110
top: 0;

vite-project/src/app/repo/Repo.File.tsx

+20-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ import {RepoEmpty} from "@/app/repo/Repo.Empty.tsx";
1717
import {RepoREADME} from "@/app/repo/Repo.README.tsx";
1818
import {Tab, Tabs} from "@heroui/tabs";
1919
import {useNavigate} from "react-router-dom";
20+
import dayjs from "dayjs"
21+
import relativeTime from "dayjs/plugin/relativeTime"
2022

23+
24+
25+
dayjs.extend(relativeTime);
2126
interface RepoFileProps {
2227
info: Repository,
2328
owner: string,
@@ -245,6 +250,16 @@ function FileItem({ tree }: { tree: Tree }) {
245250
if (commit){
246251
commit.msg = commit.msg.substring(0, 50);
247252
}
253+
const relative_time = () => {
254+
if (commit){
255+
const date = new Date(Number(commit.time) * 1000);
256+
const to_now = dayjs().to(dayjs(date));
257+
return <>{to_now}</>
258+
} else {
259+
return <>N/A</>
260+
}
261+
}
262+
248263
return (
249264
<div className="file-item">
250265
<div>
@@ -255,7 +270,9 @@ function FileItem({ tree }: { tree: Tree }) {
255270
commit && (
256271
<div className={"file-item-commit"}>
257272
<div>{commit.msg}</div>
258-
<div>{commit.time}</div>
273+
<div>
274+
{relative_time()}
275+
</div>
259276
</div>
260277
)
261278
}
@@ -278,6 +295,8 @@ function Folder({ tree }: { tree: Tree }) {
278295
return a.name.localeCompare(b.name);
279296
}
280297
})
298+
299+
281300
return (
282301
<div className="folder-container">
283302
<div

0 commit comments

Comments
 (0)