Skip to content

Commit 88fee62

Browse files
committed
simplified sorting
1 parent 737e881 commit 88fee62

File tree

4 files changed

+20
-21
lines changed

4 files changed

+20
-21
lines changed

apps/frontend/app/(app)/dashboard/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default function Page() {
3030
/>
3131
) : (
3232
// @ts-ignore
33-
<CustomTable userHistory={userHistory} />
33+
<CustomTable userHistory={[...userHistory].reverse()} />
3434
)}
3535
</div>
3636
</div>

apps/frontend/components/composite/custom-table.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { useEffect, useMemo, useState } from "react";
3+
import { useMemo, useState } from "react";
44

55
import {
66
Table,
@@ -36,17 +36,11 @@ export default function CustomTable({
3636
}: {
3737
userHistory: Array<UserHistory>;
3838
}) {
39-
const [userHistoryArr, setUserHistoryArr] =
40-
useState<Array<UserHistory>>(userHistory);
4139
const PAGE_SIZE = 10;
4240

43-
useEffect(() => {
44-
setUserHistoryArr([...userHistory].reverse());
45-
}, [userHistory]);
46-
4741
const [page, setPage] = useState(1);
4842

49-
const total = userHistoryArr?.length ?? 0;
43+
const total = userHistory?.length ?? 0;
5044
const totalPages = Math.max(1, Math.ceil(total / PAGE_SIZE));
5145
// Clamp page if data changes
5246
const currentPage = Math.min(page, totalPages);
@@ -55,13 +49,13 @@ export default function CustomTable({
5549
const startIdx = (currentPage - 1) * PAGE_SIZE;
5650
const endIdx = startIdx + PAGE_SIZE;
5751
return {
58-
rows: (userHistoryArr ?? []).slice(startIdx, endIdx),
52+
rows: (userHistory ?? []).slice(startIdx, endIdx),
5953
start: startIdx + 1,
6054
end: Math.min(endIdx, total),
6155
};
62-
}, [currentPage, userHistoryArr, total]);
56+
}, [currentPage, userHistory, total]);
6357

64-
if (!userHistoryArr || userHistoryArr.length === 0) {
58+
if (!userHistory || userHistory.length === 0) {
6559
return (
6660
<div className="mx-4 lg:mx-6 flex items-center justify-center rounded-lg border border-zinc-200 bg-white p-10 text-sm text-zinc-500 dark:border-zinc-800 dark:bg-zinc-950 dark:text-zinc-400">
6761
No history yet.

apps/frontend/components/composite/leads-counter.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
// components/Stopwatch.tsx
22
"use client";
33

4-
export default function LeadsCount({ count }: { count: number }) {
4+
export default function LeadsCount({
5+
count,
6+
state,
7+
}: {
8+
count: number;
9+
state: any;
10+
}) {
511
return (
6-
<div className="w-full max-w-md mx-auto p-5 rounded-2xl bg-gradient-to-r from-green-600/95 to-emerald-500/95 shadow-xl backdrop-blur-sm border border-white/10">
12+
<div
13+
className={`w-full max-w-md mx-auto p-5 rounded-2xl ${state.metaData.maxLeads.value > count ? "bg-gradient-to-r from-green-600/95 to-emerald-500/95" : "bg-neutral-200"} shadow-xl backdrop-blur-sm border border-white/10`}
14+
>
715
<div className="flex flex-col items-center gap-2">
816
{/* stopwatch / uptime */}
917
<div className="text-5xl md:text-6xl font-mono font-extrabold text-white drop-shadow-md tracking-wider">

apps/frontend/components/sections/service-monitor.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ import LeadsCount from "../composite/leads-counter";
1818
import CustomTable from "../composite/custom-table";
1919
import { usePathname } from "next/navigation";
2020

21-
export default function ServiceMonitor({
22-
setServiceRunning,
23-
state
24-
}: any) {
21+
export default function ServiceMonitor({ setServiceRunning, state }: any) {
2522
const [messages, socket, status] = useSocket();
2623
const pathname = usePathname();
2724
const oldPathname = pathname;
@@ -115,15 +112,15 @@ export default function ServiceMonitor({
115112

116113
<div className="grid grid-cols-2 gap-6">
117114
{/* @ts-ignore */}
118-
<Stopwatch count={messages.length} state={state}/>
115+
<Stopwatch count={messages.length} state={state} />
119116
{/* @ts-ignore */}
120-
<LeadsCount count={messages.length} />
117+
<LeadsCount count={messages.length} state={state} />
121118
</div>
122119

123120
<hr className="border-t border-zinc-100 dark:border-zinc-800" />
124121

125122
{/* @ts-ignore */}
126-
<CustomTable userHistory={messages} />
123+
<CustomTable userHistory={[...messages].reverse()} />
127124
</CardContent>
128125
</Card>
129126
);

0 commit comments

Comments
 (0)