Skip to content

Commit c5d2d32

Browse files
Add edited field in listing and show it in the notes cards
1 parent 0c656be commit c5d2d32

File tree

3 files changed

+110
-19
lines changed

3 files changed

+110
-19
lines changed

app/actions/todo-actions.ts

+2
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ export async function getTodo(
183183
done: boolean;
184184
id: string;
185185
todoColor: string;
186+
updatedAt: Date;
186187
user: { username: string };
187188
images: {
188189
id: string;
@@ -221,6 +222,7 @@ export async function getTodo(
221222
done: true,
222223
id: true,
223224
todoColor: true,
225+
updatedAt: true,
224226
user: {
225227
select: {
226228
username: true,

common/common.ts

+79
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,82 @@ export function getDarkModeColor(color: string) {
99
export function getColorName(color: string) {
1010
return color.replace('-700', '').replace('bg-', '');
1111
}
12+
13+
export const formatDate = (inputString: Date) => {
14+
const dateObj = new Date(inputString);
15+
const day = dateObj.getDate();
16+
const monthIndex = dateObj.getMonth();
17+
const year = dateObj.getFullYear();
18+
const hours = dateObj.getHours();
19+
const minutes = dateObj.getMinutes();
20+
// Format the day with appropriate suffix (e.g., 1st, 2nd, 3rd, 4th, etc.)
21+
const dayWithSuffix = getDayWithSuffix(day);
22+
// Get the month name from the month index
23+
const monthNames = [
24+
'January',
25+
'February',
26+
'March',
27+
'April',
28+
'May',
29+
'June',
30+
'July',
31+
'August',
32+
'September',
33+
'October',
34+
'November',
35+
'December',
36+
];
37+
const monthName = monthNames[monthIndex];
38+
// Format the time in 12-hour clock format with AM/PM
39+
const amOrPm = hours >= 12 ? 'PM' : 'AM';
40+
const formattedHours = hours % 12 || 12;
41+
const formattedMinutes = minutes.toString().padStart(2, '0');
42+
return `${dayWithSuffix} ${monthName} ${year}, ${formattedHours}:${formattedMinutes} ${amOrPm}`;
43+
};
44+
45+
export const secondFormatDate = (inputString: Date) => {
46+
const dateObj = new Date(inputString);
47+
const day = dateObj.getDate();
48+
const monthIndex = dateObj.getMonth();
49+
const hours = dateObj.getHours();
50+
const minutes = dateObj.getMinutes();
51+
// Format the day with appropriate suffix (e.g., 1st, 2nd, 3rd, 4th, etc.)
52+
const dayWithSuffix = getDayWithSuffix(day);
53+
// Get the month name from the month index
54+
const monthNames = [
55+
'Jan',
56+
'Feb',
57+
'Mar',
58+
'Apr',
59+
'May',
60+
'Jun',
61+
'July',
62+
'Aug',
63+
'Sept',
64+
'Oct',
65+
'Nov',
66+
'Dec',
67+
];
68+
const monthName = monthNames[monthIndex];
69+
// Format the time in 12-hour clock format with AM/PM
70+
const amOrPm = hours >= 12 ? 'PM' : 'AM';
71+
const formattedHours = hours % 12 || 12;
72+
const formattedMinutes = minutes.toString().padStart(2, '0');
73+
return `${dayWithSuffix} ${monthName}, ${formattedHours}:${formattedMinutes} ${amOrPm}`;
74+
};
75+
76+
export const getDayWithSuffix = (day: number) => {
77+
if (day >= 11 && day <= 13) {
78+
return day + 'th';
79+
}
80+
switch (day % 10) {
81+
case 1:
82+
return day + 'st';
83+
case 2:
84+
return day + 'nd';
85+
case 3:
86+
return day + 'rd';
87+
default:
88+
return day + 'th';
89+
}
90+
};

components/card/listing-card.tsx

+29-19
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ import {
3131
CircleX,
3232
} from 'lucide-react';
3333
import { useIsomorphicLayoutEffect } from '@/hooks/useIsomorphicLayoutEffect';
34-
import { getLightModeColor, getDarkModeColor } from '@/common/common';
34+
import {
35+
getLightModeColor,
36+
getDarkModeColor,
37+
secondFormatDate,
38+
} from '@/common/common';
3539
import { Avatar, AvatarImage, AvatarFallback } from '@/components/ui/avatar';
3640
import { Collaborator, User } from '@prisma/client';
3741

@@ -55,6 +59,7 @@ export const ListingCard = ({
5559
title: string;
5660
description: string;
5761
images: ImageProps[];
62+
updatedAt: Date;
5863
};
5964
children: React.ReactNode;
6065
className: string;
@@ -262,24 +267,29 @@ export const ListingCard = ({
262267
}
263268
/>
264269
</form>
265-
<div className="flex items-center ">
266-
{collabs
267-
?.filter(item => item.user.id !== userId)
268-
.map(item => (
269-
<Avatar key={item.user.id} className="flex items-center">
270-
<AvatarImage
271-
src={item.user.profilePic as string}
272-
alt="AS"
273-
className="cursor-pointer w-7 h-7 rounded-full"
274-
width={50}
275-
height={50}
276-
/>
277-
<AvatarFallback className="cursor-pointer w-7 h-7 p-2 shadow rounded-full dark:border border-gray-600 text-xs">
278-
{item.user?.firstName.charAt(0)}
279-
{item.user?.lastName.charAt(0)}
280-
</AvatarFallback>
281-
</Avatar>
282-
))}
270+
<div className="flex items-center justify-between">
271+
<div className="flex items-center flex-wrap">
272+
{collabs
273+
?.filter(item => item.user.id !== userId)
274+
.map(item => (
275+
<Avatar key={item.user.id} className="flex items-center">
276+
<AvatarImage
277+
src={item.user.profilePic as string}
278+
alt="AS"
279+
className="cursor-pointer w-7 h-7 rounded-full"
280+
width={50}
281+
height={50}
282+
/>
283+
<AvatarFallback className="cursor-pointer w-7 h-7 p-2 shadow rounded-full dark:border border-gray-600 text-xs">
284+
{item.user?.firstName.charAt(0)}
285+
{item.user?.lastName.charAt(0)}
286+
</AvatarFallback>
287+
</Avatar>
288+
))}
289+
</div>
290+
<div className="text-gray-400 text-xs">
291+
{secondFormatDate(item.updatedAt)}
292+
</div>
283293
</div>
284294
</DialogHeader>
285295
<DialogFooter>

0 commit comments

Comments
 (0)