From b3f2c64de87cf8ef1c5497dd7e02d4bf8f6cc1db Mon Sep 17 00:00:00 2001 From: Ahmad Abdolsaheb Date: Thu, 24 Jun 2021 12:50:36 +0300 Subject: [PATCH] fix(client): remove algolia and hot keys modules from landing pages (#42394) * fix(client): remove algolia and hot keys from landing pages Co-authored-by: Oliver Eyton-Williams --- api-server/src/common/models/user.js | 2 +- client/i18n/locales/english/translations.json | 3 +- client/src/assets/icons/Magnifier.tsx | 24 ++++++ .../Header/components/UniversalNav.js | 19 ++++- client/src/components/layouts/Default.js | 21 +++--- .../components/search/searchBar/SearchBar.js | 62 +++++++++------- .../components/search/searchBar/SearchHits.js | 2 +- .../search/searchBar/search-bar-optimized.tsx | 59 +++++++++++++++ .../search/searchPage/SearchPageHits.js | 56 -------------- client/src/pages/search.js | 48 ------------ client/src/utils/path-parsers.test.js | 66 +++++++++++++++++ client/src/utils/path-parsers.ts | 23 ++++++ client/utils/gatsby/layoutSelector.js | 26 +++---- .../src/server/utils => config}/constants.js | 73 ++++++++++--------- .../learn/common-components/searchBar.js | 48 ++++++++++-- cypress/integration/learn/index.js | 6 +- cypress/integration/settings/settings.js | 3 +- .../integration/settings/username-change.js | 3 +- cypress/support/commands.js | 3 +- 19 files changed, 332 insertions(+), 215 deletions(-) create mode 100644 client/src/assets/icons/Magnifier.tsx create mode 100644 client/src/components/search/searchBar/search-bar-optimized.tsx delete mode 100644 client/src/components/search/searchPage/SearchPageHits.js delete mode 100644 client/src/pages/search.js create mode 100644 client/src/utils/path-parsers.test.js create mode 100644 client/src/utils/path-parsers.ts rename {api-server/src/server/utils => config}/constants.js (98%) diff --git a/api-server/src/common/models/user.js b/api-server/src/common/models/user.js index a2632bae427..90ce86ab133 100644 --- a/api-server/src/common/models/user.js +++ b/api-server/src/common/models/user.js @@ -26,7 +26,7 @@ import { renderSignInEmail } from '../utils'; -import { blocklistedUsernames } from '../../server/utils/constants.js'; +import { blocklistedUsernames } from '../../../../config/constants'; import { wrapHandledError } from '../../server/utils/create-handled-error.js'; import { saveUser, observeMethod } from '../../server/utils/rx.js'; import { getEmailSender } from '../../server/utils/url-utils'; diff --git a/client/i18n/locales/english/translations.json b/client/i18n/locales/english/translations.json index b8e2d94f379..bddad18243d 100644 --- a/client/i18n/locales/english/translations.json +++ b/client/i18n/locales/english/translations.json @@ -395,7 +395,8 @@ "analytics": "A bar chart and line graph", "shield": "A shield with a checkmark", "tensorflow": "Tensorflow icon", - "algorithm": "Branching nodes" + "algorithm": "Branching nodes", + "magnifier": "magnifier" }, "aria": { "fcc-logo": "freeCodeCamp Logo", diff --git a/client/src/assets/icons/Magnifier.tsx b/client/src/assets/icons/Magnifier.tsx new file mode 100644 index 00000000000..42e5a13c1e2 --- /dev/null +++ b/client/src/assets/icons/Magnifier.tsx @@ -0,0 +1,24 @@ +import React from 'react'; +import { useTranslation } from 'react-i18next'; + +const Magnifier = (): JSX.Element => { + const { t } = useTranslation(); + + return ( + <> + {t('icons.Magnifier')} + + + + + ); +}; + +Magnifier.displayName = 'Magnifier'; +export default Magnifier; diff --git a/client/src/components/Header/components/UniversalNav.js b/client/src/components/Header/components/UniversalNav.js index 47f5c86bbe1..4cfb9e58c1b 100644 --- a/client/src/components/Header/components/UniversalNav.js +++ b/client/src/components/Header/components/UniversalNav.js @@ -3,10 +3,17 @@ import PropTypes from 'prop-types'; import { Link, SkeletonSprite } from '../../helpers'; import NavLogo from './NavLogo'; -import SearchBar from '../../search/searchBar/SearchBar'; import MenuButton from './MenuButton'; import NavLinks from './NavLinks'; import './universalNav.css'; +import { isLanding } from '../../../utils/path-parsers'; + +import Loadable from '@loadable/component'; + +const SearchBar = Loadable(() => import('../../search/searchBar/SearchBar')); +const SearchBarOptimized = Loadable(() => + import('../../search/searchBar/search-bar-optimized') +); export const UniversalNav = ({ displayMenu, @@ -17,6 +24,14 @@ export const UniversalNav = ({ fetchState }) => { const { pending } = fetchState; + + const search = + typeof window !== `undefined` && isLanding(window.location.pathname) ? ( + + ) : ( + + ); + return (