From fc183d246d55e0eecf43c91f6da8a59192e8e771 Mon Sep 17 00:00:00 2001 From: towfiqi Date: Fri, 3 Nov 2023 20:45:36 +0600 Subject: [PATCH] feat: Displays the Best position of the keywords closes #89 --- components/common/ChartSlim.tsx | 2 +- components/keywords/Keyword.tsx | 37 ++++++++++++++++++++++++--- components/keywords/KeywordsTable.tsx | 7 ++--- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/components/common/ChartSlim.tsx b/components/common/ChartSlim.tsx index 696a632..ba91bb4 100644 --- a/components/common/ChartSlim.tsx +++ b/components/common/ChartSlim.tsx @@ -35,7 +35,7 @@ const ChartSlim = ({ labels, sreies }:ChartProps) => { }, }; - return
+ return
{ return status; }, [history, position]); + const bestPosition: false | {position: number, date: string} = useMemo(() => { + let bestPos; + if (Object.keys(history).length > 0) { + const historyArray = Object.keys(history).map((itemID) => ({ date: itemID, position: history[itemID] })) + .sort((a, b) => a.position - b.position); + if (historyArray[0]) { + bestPos = { ...historyArray[0] }; + } + } + + return bestPos || false; + }, [history]); + const optionsButtonStyle = 'block px-2 py-2 cursor-pointer hover:bg-indigo-50 hover:text-blue-700'; const renderPosition = (pos:number, type?:string) => { @@ -85,6 +98,7 @@ const Keyword = (props: KeywordProps) => { style={style} className={`keyword relative py-5 px-4 text-gray-600 border-b-[1px] border-gray-200 lg:py-4 lg:px-6 lg:border-0 lg:flex lg:justify-between lg:items-center ${selected ? ' bg-indigo-50 keyword--selected' : ''} ${lastItem ? 'border-b-0' : ''}`}> +
}
+
+ lg:bg-transparent lg:w-auto lg:h-auto lg:mt-0 lg:p-0 lg:text-sm lg:flex-1 lg:basis-24 lg:grow-0 lg:right-0 text-center font-semibold`}> {renderPosition(position)} {!updating && positionChange > 0 && ▲ {positionChange}} {!updating && positionChange < 0 && ▼ {positionChange}}
+ + + {chartData.labels.length > 0 && ( -
showKeywordDetails()}> +
showKeywordDetails()}>
)} +
@@ -124,6 +152,7 @@ const Keyword = (props: KeywordProps) => { {turncatedURL || '-'}
+
@@ -176,6 +205,7 @@ const Keyword = (props: KeywordProps) => { )}
+ {lastUpdateError && lastUpdateError.date && showPositionError && (
2 ? 'lg:bottom-12 mt-[-70px]' : ' top-12'}`}> @@ -189,7 +219,8 @@ const Keyword = (props: KeywordProps) => { {lastUpdateError.scraper && {lastUpdateError.scraper}: }{lastUpdateError.error}
- )} + )} +
); }; diff --git a/components/keywords/KeywordsTable.tsx b/components/keywords/KeywordsTable.tsx index 7228530..59f4c02 100644 --- a/components/keywords/KeywordsTable.tsx +++ b/components/keywords/KeywordsTable.tsx @@ -153,7 +153,7 @@ const KeywordsTable = (props: KeywordsTableProps) => {