From 271e6316e85521c4c27e1bae582281df70b143bc Mon Sep 17 00:00:00 2001 From: Sean Ho Date: Mon, 24 Jan 2022 10:23:27 +0800 Subject: [PATCH 1/3] fix: unencoded url for categories --- src/common/utility.js | 1 - src/pages/academy/components/_search-banner.tsx | 7 ++++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/common/utility.js b/src/common/utility.js index f27942c8c4d..36e8807543d 100644 --- a/src/common/utility.js +++ b/src/common/utility.js @@ -345,7 +345,6 @@ export const slugify = (text) => .toLowerCase() .trim() // Remove whitespace from both sides of a string .replace(/\s+/g, '-') // Replace spaces with - - .replace(/[^\w-]+/g, '') // Remove all non-word chars .replace(/--+/g, '-') // Replace multiple - with single - export const unslugify = (slug) => { diff --git a/src/pages/academy/components/_search-banner.tsx b/src/pages/academy/components/_search-banner.tsx index 62a2bd728fa..0b268b15381 100644 --- a/src/pages/academy/components/_search-banner.tsx +++ b/src/pages/academy/components/_search-banner.tsx @@ -749,12 +749,12 @@ const SearchBanner = ({ hidden }: SearchBannerProps) => { const handleHref = (category) => { if (isBrowser() && window.location.pathname.includes('/academy/videos')) { - return `/academy/search?type=video&category=${slugify(category)}` + return `/academy/search?type=video&category=${encodeURIComponent(slugify(category))}` } if (isBrowser() && window.location.pathname.includes('/academy/blog')) { - return `/academy/search?type=article&category=${slugify(category)}` + return `/academy/search?type=article&category=${encodeURIComponent(slugify(category))}` } - return `/academy/search?category=${slugify(category)}` + return `/academy/search?category=${encodeURIComponent(slugify(category))}` } return ( @@ -861,6 +861,7 @@ const SearchBanner = ({ hidden }: SearchBannerProps) => { {filter.type.toUpperCase()} {filter.items.map((item, idx) => { + console.log(item.title) return ( Date: Mon, 24 Jan 2022 11:10:02 +0800 Subject: [PATCH 2/3] chore: remove console log --- src/pages/academy/components/_search-banner.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/academy/components/_search-banner.tsx b/src/pages/academy/components/_search-banner.tsx index 0b268b15381..c510f8588cc 100644 --- a/src/pages/academy/components/_search-banner.tsx +++ b/src/pages/academy/components/_search-banner.tsx @@ -861,7 +861,6 @@ const SearchBanner = ({ hidden }: SearchBannerProps) => { {filter.type.toUpperCase()} {filter.items.map((item, idx) => { - console.log(item.title) return ( Date: Mon, 24 Jan 2022 11:33:11 +0800 Subject: [PATCH 3/3] fix: casing of category title --- src/pages/academy/search/index.tsx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/pages/academy/search/index.tsx b/src/pages/academy/search/index.tsx index 13a070fabc6..0dd15fe0add 100644 --- a/src/pages/academy/search/index.tsx +++ b/src/pages/academy/search/index.tsx @@ -290,6 +290,24 @@ const SearchPage = () => { : total_article } of ${total_article} results` + // This is a temporary solution without adding slug to the combined_filter_type + // array from the constant file. This can be refactored in the future but + // requires a change in the logic for both SearchBanner and search page. + const getCategoryText = () => { + switch (category_type) { + case 'cfds': + return 'CFDs' + case 'dbot': + return 'DBot' + case 'dtrader': + return 'DTrader' + case 'deriv-mt5': + return 'Deriv MT5' + default: + return unslugify(category_type) + } + } + return ( { Selection for
- {unslugify(category_type)} + {getCategoryText()}
)}