From 541ccc410dc0336989f4c31cd21b2b919b6f23e3 Mon Sep 17 00:00:00 2001 From: SanttuA Date: Thu, 21 Sep 2023 11:41:03 +0300 Subject: [PATCH] Refactored common class components into functions (#273) Changes: - switched `FooterContent`, `UnconnectedNotificationsContainer`, `TimeRange` and `MobileNavbar` into function components to improve their performance and bundle size - changed resource page import of `NotFoundPage` to be in line of other similar imports --- app/pages/resource/ResourcePage.js | 2 +- app/shared/footer/FooterContent.js | 75 +++++++++---------- .../notifications/NotificationsContainer.js | 28 ++++--- app/shared/time-range/TimeRange.js | 38 +++++----- app/shared/top-navbar/mobile/MobileNavbar.js | 45 +++++------ 5 files changed, 88 insertions(+), 100 deletions(-) diff --git a/app/pages/resource/ResourcePage.js b/app/pages/resource/ResourcePage.js index de8ce0226..edf7cecb3 100644 --- a/app/pages/resource/ResourcePage.js +++ b/app/pages/resource/ResourcePage.js @@ -18,7 +18,7 @@ import { addNotification } from 'actions/notificationsActions'; import { fetchResource } from 'actions/resourceActions'; import { clearReservations, toggleResourceMap } from 'actions/uiActions'; import PageWrapper from 'pages/PageWrapper'; -import NotFoundPage from 'pages/not-found/NotFoundPage'; +import NotFoundPage from 'pages/not-found'; import ResourceCalendar from 'shared/resource-calendar'; import ResourceMap from 'shared/resource-map'; import { injectT } from 'i18n'; diff --git a/app/shared/footer/FooterContent.js b/app/shared/footer/FooterContent.js index fbdc08c98..a2a191eb2 100644 --- a/app/shared/footer/FooterContent.js +++ b/app/shared/footer/FooterContent.js @@ -13,45 +13,42 @@ import logoSv from '@city-assets/images/logo_footer_sv.png'; import { injectT } from 'i18n'; import { getFeedbackLink } from 'utils/languageUtils'; -class FooterContent extends React.Component { - static propTypes = { - t: PropTypes.func, - currentLang: PropTypes.string, - }; - - render() { - const { t, currentLang } = this.props; - const currentLogo = (currentLang !== 'sv') ? logoFi : logoSv; - const currentLink = getFeedbackLink(currentLang); - return ( - - - -
- {t('Logo.cityAlt')} -
- - -

Varaamo

-

- -
-
- {t('AccessibilityInfo.title')} -
- - {t('Footer.feedbackLink')} - -

- -
-
- ); - } +function FooterContent({ t, currentLang }) { + const currentLogo = (currentLang !== 'sv') ? logoFi : logoSv; + const currentLink = getFeedbackLink(currentLang); + return ( + + + +
+ {t('Logo.cityAlt')} +
+ + +

Varaamo

+

+ +
+
+ {t('AccessibilityInfo.title')} +
+ + {t('Footer.feedbackLink')} + +

+ +
+
+ ); } +FooterContent.propTypes = { + t: PropTypes.func.isRequired, + currentLang: PropTypes.string.isRequired, +}; + export default injectT(FooterContent); diff --git a/app/shared/notifications/NotificationsContainer.js b/app/shared/notifications/NotificationsContainer.js index a26c80a7a..76706588f 100644 --- a/app/shared/notifications/NotificationsContainer.js +++ b/app/shared/notifications/NotificationsContainer.js @@ -1,5 +1,5 @@ import PropTypes from 'prop-types'; -import React, { Component } from 'react'; +import React from 'react'; import ReactNotifications from 'react-notifications'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; @@ -8,20 +8,18 @@ import { hideNotification } from 'actions/notificationsActions'; import { injectT } from 'i18n'; import notificationsSelector from './notificationsSelector'; -class UnconnectedNotificationsContainer extends Component { - render() { - const { actions, notifications, t } = this.props; - const translatedNotifications = notifications.map(notification => ({ - ...notification, - message: notification.message || t(notification.messageId), - })); - return ( - - ); - } +function UnconnectedNotificationsContainer(props) { + const { actions, notifications, t } = props; + const translatedNotifications = notifications.map(notification => ({ + ...notification, + message: notification.message || t(notification.messageId), + })); + return ( + + ); } UnconnectedNotificationsContainer.propTypes = { diff --git a/app/shared/time-range/TimeRange.js b/app/shared/time-range/TimeRange.js index 85110e305..e33952cbb 100644 --- a/app/shared/time-range/TimeRange.js +++ b/app/shared/time-range/TimeRange.js @@ -1,28 +1,26 @@ import upperFirst from 'lodash/upperFirst'; import moment from 'moment'; import PropTypes from 'prop-types'; -import React, { Component } from 'react'; +import React from 'react'; -class TimeRange extends Component { - render() { - const { - begin, - className, - beginFormat, - end, - endFormat, - } = this.props; - const beginMoment = moment(begin); - const endMoment = moment(end); - const rangeString = `${beginMoment.format(beginFormat)} \u2013 ${endMoment.format(endFormat)}`; - const ISORangeString = `${begin}/${end}`; +function TimeRange(props) { + const { + begin, + className, + beginFormat, + end, + endFormat, + } = props; + const beginMoment = moment(begin); + const endMoment = moment(end); + const rangeString = `${beginMoment.format(beginFormat)} \u2013 ${endMoment.format(endFormat)}`; + const ISORangeString = `${begin}/${end}`; - return ( - - ); - } + return ( + + ); } TimeRange.propTypes = { diff --git a/app/shared/top-navbar/mobile/MobileNavbar.js b/app/shared/top-navbar/mobile/MobileNavbar.js index 084121bce..639ca16d9 100644 --- a/app/shared/top-navbar/mobile/MobileNavbar.js +++ b/app/shared/top-navbar/mobile/MobileNavbar.js @@ -7,33 +7,28 @@ import Row from 'react-bootstrap/lib/Row'; import FontChanger from 'shared/top-navbar/accessibility/TopNavbarFontContainer'; import ContrastChanger from 'shared/top-navbar/accessibility/TopNavbarContrastContainer'; -class MobileNavbar extends React.Component { - static propTypes = { - toggle: PropTypes.bool, - contrast: PropTypes.string - }; - - - getCollapseStatus = () => (this.props.toggle ? '' : 'is-collapsed') - - render() { - const element = this.getCollapseStatus(); - return ( -
-
- - -
    - - -
- -
-
+function MobileNavbar({ toggle, contrast }) { + const getCollapseStatus = () => (toggle ? '' : 'is-collapsed'); + const element = getCollapseStatus(); + return ( +
+
+ + +
    + + +
+ +
- ); - } +
+ ); } +MobileNavbar.propTypes = { + toggle: PropTypes.bool, + contrast: PropTypes.string +}; export default MobileNavbar;