Skip to content

Commit 6e55979

Browse files
committed
feat: optimize width calculation in ToDoOverview component
- Introduced useMemo for width calculation in the ToDoOverview component, improving performance by memoizing the computed value based on dependencies. - Simplified the width style assignment in the render method, enhancing code readability and maintainability.
1 parent 67741b4 commit 6e55979

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

apps/app/src/app/(app)/[orgId]/frameworks/components/ToDoOverview.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from 'lucide-react';
1717
import { useAction } from 'next-safe-action/hooks';
1818
import Link from 'next/link';
19-
import { useState } from 'react';
19+
import { useMemo, useState } from 'react';
2020
import { toast } from 'sonner';
2121
import { ConfirmActionDialog } from './ConfirmActionDialog';
2222

@@ -90,6 +90,14 @@ export function ToDoOverview({
9090
}
9191
};
9292

93+
const width = useMemo(() => {
94+
return totalPolicies + totalTasks === 0
95+
? 0
96+
: ((totalPolicies + totalTasks - (unpublishedPolicies.length + incompleteTasks.length)) /
97+
(totalPolicies + totalTasks)) *
98+
100;
99+
}, [totalPolicies, totalTasks, unpublishedPolicies.length, incompleteTasks.length]);
100+
93101
return (
94102
<Card className="flex flex-col h-full">
95103
<CardHeader className="pb-2">
@@ -101,15 +109,7 @@ export function ToDoOverview({
101109
<div
102110
className="bg-primary/80 h-full transition-all"
103111
style={{
104-
width: `${
105-
totalPolicies + totalTasks === 0
106-
? 0
107-
: ((totalPolicies +
108-
totalTasks -
109-
(unpublishedPolicies.length + incompleteTasks.length)) /
110-
(totalPolicies + totalTasks)) *
111-
100
112-
}%`,
112+
width: `${width}%`,
113113
}}
114114
/>
115115
</div>

0 commit comments

Comments
 (0)