From 1c875067313b6edff4cd779b1d7ec65d82b21119 Mon Sep 17 00:00:00 2001 From: nattadex Date: Mon, 12 Aug 2024 15:30:40 +0800 Subject: [PATCH 1/5] return 0% if divided by 0 --- src/utils/index/CalculatePercentage.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/utils/index/CalculatePercentage.ts b/src/utils/index/CalculatePercentage.ts index d5fe12c35..dc4cf3af3 100644 --- a/src/utils/index/CalculatePercentage.ts +++ b/src/utils/index/CalculatePercentage.ts @@ -1,10 +1,13 @@ export function CalculatePercentage( value1: number | undefined, - value2: number | undefined + value2: number | undefined, ): string { if (value1 === undefined || value2 === undefined) { return ""; } + if (value2 === 0) { + return "0.00%"; + } return `${((value1 / value2) * 100).toFixed(2)}%`; } From 68b02a223bf7ef029903f753d9d9c812dd1810c3 Mon Sep 17 00:00:00 2001 From: nattadex Date: Mon, 12 Aug 2024 15:33:17 +0800 Subject: [PATCH 2/5] remove added , --- src/utils/index/CalculatePercentage.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/index/CalculatePercentage.ts b/src/utils/index/CalculatePercentage.ts index dc4cf3af3..d4f130643 100644 --- a/src/utils/index/CalculatePercentage.ts +++ b/src/utils/index/CalculatePercentage.ts @@ -8,6 +8,7 @@ export function CalculatePercentage( if (value2 === 0) { return "0.00%"; } + console.log(((value1 / value2) * 100).toFixed(2)); return `${((value1 / value2) * 100).toFixed(2)}%`; } From ecf60a841b3a14eb0ad9bfd487c44d86992b54c9 Mon Sep 17 00:00:00 2001 From: nattadex Date: Mon, 12 Aug 2024 15:33:55 +0800 Subject: [PATCH 3/5] remove console --- src/utils/index/CalculatePercentage.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/utils/index/CalculatePercentage.ts b/src/utils/index/CalculatePercentage.ts index d4f130643..dc4cf3af3 100644 --- a/src/utils/index/CalculatePercentage.ts +++ b/src/utils/index/CalculatePercentage.ts @@ -8,7 +8,6 @@ export function CalculatePercentage( if (value2 === 0) { return "0.00%"; } - console.log(((value1 / value2) * 100).toFixed(2)); return `${((value1 / value2) * 100).toFixed(2)}%`; } From 4056d3df9fc9452dab64d3ff247e758e10ecd23a Mon Sep 17 00:00:00 2001 From: canonbrother Date: Thu, 10 Oct 2024 17:14:01 +0800 Subject: [PATCH 4/5] lint --- src/components/commons/searchbar/SearchBar.tsx | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/components/commons/searchbar/SearchBar.tsx b/src/components/commons/searchbar/SearchBar.tsx index e1b1255e4..e2814681c 100644 --- a/src/components/commons/searchbar/SearchBar.tsx +++ b/src/components/commons/searchbar/SearchBar.tsx @@ -68,11 +68,10 @@ export function SearchBar(props: SearchBarInterface): JSX.Element { const currentReference = refs.reference.current as Element; Object.assign(refs.floating.current?.style, { width: `${currentReference.scrollWidth}px`, - left: - `${ - currentReference.scrollLeft + - (currentReference.scrollWidth - refs.floating.current?.scrollWidth) - }px` ?? "", + left: `${ + currentReference.scrollLeft + + (currentReference.scrollWidth - refs.floating.current?.scrollWidth) + }px`, }); } @@ -113,7 +112,7 @@ export function SearchBar(props: SearchBarInterface): JSX.Element { const onChangeDebounceHandler = useMemo( () => debounce(changeHandler, 200), - [] + [], ); function onSelect(result: SearchResult): void { @@ -137,7 +136,7 @@ export function SearchBar(props: SearchBarInterface): JSX.Element { >
{ const searchResults: SearchResult[] = []; From 9b51e756a2a64e8335f96bc0a50d27eca948b4cd Mon Sep 17 00:00:00 2001 From: canonbrother Date: Thu, 10 Oct 2024 17:19:11 +0800 Subject: [PATCH 5/5] refine CalculatePercentage --- src/utils/index/CalculatePercentage.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/utils/index/CalculatePercentage.ts b/src/utils/index/CalculatePercentage.ts index dc4cf3af3..bf37861da 100644 --- a/src/utils/index/CalculatePercentage.ts +++ b/src/utils/index/CalculatePercentage.ts @@ -5,9 +5,11 @@ export function CalculatePercentage( if (value1 === undefined || value2 === undefined) { return ""; } - if (value2 === 0) { + + const result = value1 / value2; + if (isNaN(result)) { return "0.00%"; } - return `${((value1 / value2) * 100).toFixed(2)}%`; + return `${(result * 100).toFixed(2)}%`; }