/[sudobot]/trunk/docs/components/MDX/PageInfo.tsx
ViewVC logotype

Contents of /trunk/docs/components/MDX/PageInfo.tsx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 575 - (show annotations)
Mon Jul 29 17:59:26 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 1372 byte(s)
chore: add trunk
1 "use client";
2
3 import { getPageInfo } from "@/actions/pageinfo";
4 import useActualPathname from "@/hooks/useActualPathname";
5 import { formatDistanceToNowStrict } from "date-fns";
6 import { useEffect, useState } from "react";
7
8 export default function LastModified() {
9 const [date, setDate] = useState<Date | null>(null);
10 const [avatar, setAvatar] = useState<string | null>(null);
11 const pathname = useActualPathname();
12
13 useEffect(() => {
14 getPageInfo(pathname)
15 .then(({ avatarURL, lastModifiedDate }) => {
16 setDate(lastModifiedDate);
17 setAvatar(avatarURL);
18 })
19 .catch(console.error);
20 }, [pathname]);
21
22 if (!date) {
23 return <></>;
24 }
25
26 return (
27 <div className="flex items-center gap-3">
28 {avatar ? (
29 <img
30 src={avatar}
31 className="w-[30px] h-[30px] rounded-full [border:1px_solid_#007bff]"
32 />
33 ) : (
34 <div className="w-[30px] h-[30px] rounded-full [border:1px_solid_#007bff] bg-[rgba(0,123,255,0.3)]"></div>
35 )}
36
37 <span className="text-[#999]">
38 Last modified{" "}
39 {formatDistanceToNowStrict(date, {
40 addSuffix: true,
41 })}
42 </span>
43 </div>
44 );
45 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26