Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | 3x 3x 3x 4x 4x 4x 16x 16x 16x 16x 4x 16x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x | import { getStartOfDay } from "@features/GiveConversation/utils";
export const MODAL_HEIGHT = 657;
export const BOTTOM_OFFSET = 86;
export const getVirtualGroups = ({
list,
groupByKey,
timezone,
}: {
list?: any[];
groupByKey: string;
timezone: string;
}) => {
Iif (!list?.length) return { items: [], groupCounts: [], groupLabels: [] };
// Step 2: Group by start of day (in the correct timezone)
const groupsMap = new Map<number, { label: number; items: typeof list }>();
for (const notif of list) {
// Convert notif[groupByKey] into the correct timezone Date
const acuateDateTime = notif[groupByKey];
const dateInTz = new Date(
new Date(acuateDateTime).toLocaleString("en-US", {
timeZone: timezone,
}),
);
// Pass timestamp to getStartOfDay
const day = getStartOfDay(dateInTz.getTime());
if (!groupsMap.has(day)) {
groupsMap.set(day, { label: acuateDateTime, items: [] });
}
groupsMap.get(day)!.items.push(notif);
}
// Step 3: Convert to arrays preserving descending order
const sortedGroups = Array.from(groupsMap.entries())
.sort((a, b) => b[0] - a[0]) // Sort days descending
.map(([, value]) => value);
const groupLabels: number[] = [];
const flatItems: typeof list = [];
const groupCounts: number[] = [];
for (const { label, items } of sortedGroups) {
groupLabels.push(label);
groupCounts.push(items.length);
flatItems.push(...items);
}
return {
items: flatItems,
groupCounts,
groupLabels,
};
};
|