From 6aa89005774182793123a7c901fb296fd5fe295d Mon Sep 17 00:00:00 2001 From: Sacha Trauwaen Date: Fri, 15 Mar 2024 16:44:25 +0100 Subject: [PATCH 1/3] update react dev dependencies --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b76c924..49e6355 100644 --- a/package.json +++ b/package.json @@ -63,8 +63,8 @@ "@types/jsonwebtoken": "^8.5.9", "@types/node": "18.11.0", "@types/nodemailer": "^6.4.6", - "@types/react": "18.0.21", - "@types/react-dom": "18.0.6", + "@types/react": "18.2.0", + "@types/react-dom": "18.2.0", "@types/react-timeago": "^4.1.3", "@types/react-window": "^1.8.5", "autoprefixer": "^10.4.12", From 3a057039213173d0b5142a46a9a696f2fce4ae88 Mon Sep 17 00:00:00 2001 From: Sacha Trauwaen Date: Fri, 15 Mar 2024 16:47:27 +0100 Subject: [PATCH 2/3] fix double entrees in Discover Tab (Google Search Console) --- pages/domain/console/[slug]/index.tsx | 38 +++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/pages/domain/console/[slug]/index.tsx b/pages/domain/console/[slug]/index.tsx index a824122..1df5819 100644 --- a/pages/domain/console/[slug]/index.tsx +++ b/pages/domain/console/[slug]/index.tsx @@ -32,6 +32,40 @@ const DiscoverPage: NextPage = () => { const theDomains: DomainType[] = (domainsData && domainsData.domains) || []; const theKeywords: SearchAnalyticsItem[] = keywordsData?.data && keywordsData.data[scDateFilter] ? keywordsData.data[scDateFilter] : []; + const theKeywordsCount = theKeywords.reduce>((r, o) => { + const key = `${o.device}-${o.country}-${o.keyword}`; + const item = r.get(key) || 0; + return r.set(key, item + 1); + }, new Map()) || []; + + const theKeywordsGrouped : SearchAnalyticsItem[] = [...theKeywords.reduce>((r, o) => { + const key = `${o.device}-${o.country}-${o.keyword}`; + + const item = r.get(key) || { ...o, + ...{ + clicks: 0, + impressions: 0, + ctr: 0, + position: 0, + }, + }; + item.clicks += o.clicks; + item.impressions += o.impressions; + item.ctr = o.ctr + item.ctr; + item.position = o.position + item.position; + + return r.set(key, item); + }, new Map()).values()].map((o: SearchAnalyticsItem) => { + const key = `${o.device}-${o.country}-${o.keyword}`; + const count = theKeywordsCount?.get(key) || 0; + return { ...o, + ...{ + ctr: o.ctr / count, + position: o.position / count, + }, + }; + }); + const activDomain: DomainType|null = useMemo(() => { let active:DomainType|null = null; if (domainsData?.domains && router.query?.slug) { @@ -62,7 +96,7 @@ const DiscoverPage: NextPage = () => { domains={theDomains} showAddModal={() => console.log('XXXXX')} showSettingsModal={setShowDomainSettings} - exportCsv={() => exportCSV(theKeywords, activDomain.domain, scDateFilter)} + exportCsv={() => exportCSV(theKeywordsGrouped, activDomain.domain, scDateFilter)} scFilter={scDateFilter} setScFilter={(item:string) => setSCDateFilter(item)} /> @@ -71,7 +105,7 @@ const DiscoverPage: NextPage = () => { From 40e027e1ece43c34d48c144d0df4d91975e90f70 Mon Sep 17 00:00:00 2001 From: Sacha Trauwaen Date: Thu, 28 Mar 2024 20:41:50 +0100 Subject: [PATCH 3/3] 1) wrap both theKeywordsCount and theKeywordsGrouped with useMemo 2) changing reduce and map together to make the code more readable. 3) ctr and position value rounded. --- pages/domain/console/[slug]/index.tsx | 72 +++++++++++++++------------ 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/pages/domain/console/[slug]/index.tsx b/pages/domain/console/[slug]/index.tsx index 1df5819..c101bc9 100644 --- a/pages/domain/console/[slug]/index.tsx +++ b/pages/domain/console/[slug]/index.tsx @@ -30,41 +30,49 @@ const DiscoverPage: NextPage = () => { const { data: keywordsData, isLoading: keywordsLoading, isFetching } = useFetchSCKeywords(router, !!(domainsData?.domains?.length) && scConnected); const theDomains: DomainType[] = (domainsData && domainsData.domains) || []; - const theKeywords: SearchAnalyticsItem[] = keywordsData?.data && keywordsData.data[scDateFilter] ? keywordsData.data[scDateFilter] : []; + const theKeywords: SearchAnalyticsItem[] = useMemo(() => { + return keywordsData?.data && keywordsData.data[scDateFilter] ? keywordsData.data[scDateFilter] : []; + }, [keywordsData, scDateFilter]); - const theKeywordsCount = theKeywords.reduce>((r, o) => { - const key = `${o.device}-${o.country}-${o.keyword}`; - const item = r.get(key) || 0; - return r.set(key, item + 1); - }, new Map()) || []; + const theKeywordsCount = useMemo(() => { + return theKeywords.reduce>((r, o) => { + const key = `${o.device}-${o.country}-${o.keyword}`; + const item = r.get(key) || 0; + return r.set(key, item + 1); + }, new Map()) || []; + }, [theKeywords]); - const theKeywordsGrouped : SearchAnalyticsItem[] = [...theKeywords.reduce>((r, o) => { - const key = `${o.device}-${o.country}-${o.keyword}`; + const theKeywordsReduced : SearchAnalyticsItem[] = useMemo(() => { + return [...theKeywords.reduce>((r, o) => { + const key = `${o.device}-${o.country}-${o.keyword}`; + const item = r.get(key) || { ...o, + ...{ + clicks: 0, + impressions: 0, + ctr: 0, + position: 0, + }, + }; + item.clicks += o.clicks; + item.impressions += o.impressions; + item.ctr = o.ctr + item.ctr; + item.position = o.position + item.position; + return r.set(key, item); + }, new Map()).values()]; + }, [theKeywords]); - const item = r.get(key) || { ...o, - ...{ - clicks: 0, - impressions: 0, - ctr: 0, - position: 0, - }, - }; - item.clicks += o.clicks; - item.impressions += o.impressions; - item.ctr = o.ctr + item.ctr; - item.position = o.position + item.position; - - return r.set(key, item); - }, new Map()).values()].map((o: SearchAnalyticsItem) => { - const key = `${o.device}-${o.country}-${o.keyword}`; - const count = theKeywordsCount?.get(key) || 0; - return { ...o, - ...{ - ctr: o.ctr / count, - position: o.position / count, - }, - }; - }); + const theKeywordsGrouped : SearchAnalyticsItem[] = useMemo(() => { + return [...theKeywordsReduced.map((o: SearchAnalyticsItem) => { + const key = `${o.device}-${o.country}-${o.keyword}`; + const count = theKeywordsCount?.get(key) || 0; + return { ...o, + ...{ + ctr: Math.round((o.ctr / count) * 100) / 100, + position: Math.round(o.position / count), + }, + }; + })]; + }, [theKeywordsReduced, theKeywordsCount]); const activDomain: DomainType|null = useMemo(() => { let active:DomainType|null = null;