Skip to content

Commit dcc462f

Browse files
Refactor activity log sorting to use manual bubble sort with for...of
Co-authored-by: joaquim.verges <[email protected]>
1 parent 91a8db8 commit dcc462f

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/transactions/tx/[id]/transaction-details-ui.tsx

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -400,22 +400,29 @@ function ActivityLogCard({
400400
sortedLogs[sortedLogs.length] = log;
401401
}
402402

403-
// Manual bubble sort using for...of loops
404-
for (let i = 0; i < sortedLogs.length; i++) {
405-
for (let j = 0; j < sortedLogs.length - 1 - i; j++) {
406-
const currentLog = sortedLogs[j];
407-
const nextLog = sortedLogs[j + 1];
408-
403+
// Manual bubble sort using only for...of loops with manual index tracking
404+
let sortingComplete = false;
405+
while (!sortingComplete) {
406+
sortingComplete = true;
407+
let prevLog: ActivityLogEntry | null = null;
408+
let prevIndex = -1;
409+
let currentIndex = 0;
410+
411+
for (const log of sortedLogs) {
409412
if (
410-
currentLog &&
411-
nextLog &&
412-
new Date(currentLog.createdAt).getTime() >
413-
new Date(nextLog.createdAt).getTime()
413+
prevLog &&
414+
new Date(prevLog.createdAt).getTime() >
415+
new Date(log.createdAt).getTime()
414416
) {
415-
// Swap elements
416-
sortedLogs[j] = nextLog;
417-
sortedLogs[j + 1] = currentLog;
417+
// Swap elements using manual assignment
418+
sortedLogs[prevIndex] = log;
419+
sortedLogs[currentIndex] = prevLog;
420+
sortingComplete = false;
418421
}
422+
423+
prevLog = log;
424+
prevIndex = currentIndex;
425+
currentIndex++;
419426
}
420427
}
421428

@@ -424,8 +431,8 @@ function ActivityLogCard({
424431

425432
for (const log of sortedLogs) {
426433
const isLast = index === sortedLogs.length - 1;
427-
logElements.push(
428-
<ActivityLogEntryItem isLast={isLast} key={log.id} log={log} />,
434+
logElements[logElements.length] = (
435+
<ActivityLogEntryItem isLast={isLast} key={log.id} log={log} />
429436
);
430437
index++;
431438
}

0 commit comments

Comments
 (0)