Skip to content

Commit 7588f8e

Browse files
committed
Recent Activity - API
1 parent 7b673a1 commit 7588f8e

File tree

6 files changed

+63
-55
lines changed

6 files changed

+63
-55
lines changed

src/app/api/discord/route.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ export const POST = async (request: Request) => {
3939
var channelData = await fs.readFile(channelDataPath, "utf8");
4040
const { discordId }: { discordId: string } = JSON.parse(channelData);
4141
const { text, date, msgChannel, msgId } = await request.json();
42-
const updateData = { msgId, text, date, msgChannel };
42+
const dateLocale = new Date(date * 1000).toLocaleTimeString("en-US", {
43+
hour: "2-digit",
44+
minute: "2-digit",
45+
second: "2-digit",
46+
});
47+
const updateData = { msgId, text, dateLocale, msgChannel };
4348
try {
4449
await fetch(discordId, {
4550
method: "POST",

src/app/api/recentMessage/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ const recentMsgPath = path.join(process.cwd(), "src/logs/recentMsg.json");
55
export const GET = async (request: Request) => {
66
const recentMsg = await fs.readFile(recentMsgPath, "utf8");
77
const recentMsgJson = JSON.parse(recentMsg);
8-
console.log(recentMsg, recentMsgJson);
9-
return new Response("hello", { status: 200 });
8+
9+
return Response.json(recentMsgJson, { status: 200 });
1010
};

src/app/globals.css

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,27 @@ body {
210210
display: flex;
211211
flex-direction: column;
212212
gap: 3vh;
213-
padding-left: 10px;
213+
padding: 0 10px;
214214
}
215215

216+
.recents-item-container {
217+
display: flex;
218+
gap: 5vw;
219+
align-items: center;
220+
justify-content: space-between;
221+
transition: all 0.2s ease-in-out;
222+
}
223+
224+
.recents-text {
225+
font-weight: 700;
226+
opacity: 0.7;
227+
max-height: 3vh;
228+
white-space: nowrap;
229+
text-overflow: ellipsis;
230+
overflow: hidden;
231+
232+
text-align: center;
233+
}
216234
.recents-item-head {
217235
display: flex;
218236
gap: 1vw;

src/app/page.tsx

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,11 @@ const Timer = dynamic(() => import("@/lib/timer"), {
88
loading: () => <p>Loading...</p>,
99
});
1010

11-
const data = [
12-
{ content: "Hello", status: "success" },
13-
{ content: "hi", status: "success" },
14-
{ content: "hello", status: "success" },
15-
{ content: "hi", status: "failed" },
16-
{ content: "hello", status: "success" },
17-
];
18-
1911
export default async function Home() {
20-
// await fetch("http://localhost:3000/api/recentMessage");
21-
12+
const res = await fetch("http://localhost:3000/api/recentMessage", {
13+
cache: "no-cache",
14+
});
15+
const Data = await res.json();
2216
return (
2317
<div className="App-main">
2418
<div className="hero-head">
@@ -56,32 +50,24 @@ export default async function Home() {
5650
<span>Handled 265 messages Last month</span>
5751
</h2>
5852
<div className="recents-components">
59-
<div className="recents-item-head">
60-
<Avatar>
61-
<AvatarImage
62-
style={{ scale: 1.3 }}
63-
src="https://i.pinimg.com/originals/cc/6a/f2/cc6af2b47a62e61e1154a4726299ba46.jpg"
64-
/>
65-
<AvatarFallback>CN</AvatarFallback>
66-
</Avatar>
67-
<div>
68-
<h2>Raghav</h2>
69-
<p>admin@shadowctrl.me</p>
70-
</div>
71-
</div>
72-
<div className="recents-item-head">
73-
<Avatar>
74-
<AvatarImage
75-
style={{ scale: 1.3 }}
76-
src="https://i.pinimg.com/originals/cc/6a/f2/cc6af2b47a62e61e1154a4726299ba46.jpg"
77-
/>
78-
<AvatarFallback>CN</AvatarFallback>
79-
</Avatar>
80-
<div>
81-
<h2>Raghav</h2>
82-
<p>admin@shadowctrl.me</p>
53+
{Data.map((data: any, key: number) => (
54+
<div key={key} className="recents-item-container">
55+
<div className="recents-item-head">
56+
<Avatar>
57+
<AvatarImage
58+
style={{ scale: 1.3 }}
59+
src="https://i.pinimg.com/originals/cc/6a/f2/cc6af2b47a62e61e1154a4726299ba46.jpg"
60+
/>
61+
<AvatarFallback>CN</AvatarFallback>
62+
</Avatar>
63+
<div>
64+
<h2>{data.msgChannel}</h2>
65+
<p>{data.dateLocale}</p>
66+
</div>
67+
</div>
68+
<h2 className="recents-text">{data.text}</h2>
8369
</div>
84-
</div>
70+
))}
8571
</div>
8672
</div>
8773
</div>

src/lib/telegramHelper.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"update_id": 19846357
2+
"update_id": 19846376
33
}

src/logs/recentMsg.json

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
11
[
22
{
3-
"msgId": 19846353,
4-
"text": "2",
5-
"date": 1721287164,
3+
"msgId": 19846369,
4+
"text": "Hmm",
5+
"dateLocale": "09:41:30 PM",
66
"msgChannel": "MirrorBridge"
77
},
88
{
9-
"msgId": 19846354,
10-
"text": "3",
11-
"date": 1721287165,
9+
"msgId": 19846372,
10+
"text": "Hi",
11+
"dateLocale": "09:44:04 PM",
1212
"msgChannel": "MirrorBridge"
1313
},
1414
{
15-
"msgId": 19846355,
16-
"text": "4",
17-
"date": 1721287166,
15+
"msgId": 19846374,
16+
"text": "Dear Applicant,\n\nWelcome to ONLINE ADMISSION PORTAL.\n\nExisting Users:\n\nLogin with the username (Application Number)\nPassword is your date of birth in format DDMMYYYY.\n(Eg. If your date of birth is 3rd April 2002 password format is 03042002).",
17+
"dateLocale": "09:48:13 PM",
1818
"msgChannel": "MirrorBridge"
1919
},
2020
{
21-
"msgId": 19846356,
22-
"text": "5",
23-
"date": 1721287167,
21+
"msgId": 19846375,
22+
"dateLocale": "09:48:41 PM",
2423
"msgChannel": "MirrorBridge"
2524
},
2625
{
27-
"msgId": 19846357,
28-
"text": "6",
29-
"date": 1721287169,
26+
"msgId": 19846376,
27+
"text": "Is there any one who got the losss please send me the screen shot",
28+
"dateLocale": "09:49:26 PM",
3029
"msgChannel": "MirrorBridge"
3130
}
3231
]

0 commit comments

Comments
 (0)