From b9363b9031b4d5a63d73ca3c1bcc061403871970 Mon Sep 17 00:00:00 2001 From: Vesa Luusua Date: Thu, 25 Jan 2018 16:33:56 +0200 Subject: [PATCH] ListingPage: rules and map as maybe components --- src/containers/ListingPage/ListingPage.js | 18 ++------- src/containers/ListingPage/SectionMapMaybe.js | 36 ++++++++++++++++++ .../ListingPage/SectionRulesMaybe.css | 37 ++++++++++++++++++ .../ListingPage/SectionRulesMaybe.js | 31 +++++++++++++++ .../__snapshots__/ListingPage.test.js.snap | 38 ++++++++----------- src/translations/en.json | 1 + 6 files changed, 125 insertions(+), 36 deletions(-) create mode 100644 src/containers/ListingPage/SectionMapMaybe.js create mode 100644 src/containers/ListingPage/SectionRulesMaybe.css create mode 100644 src/containers/ListingPage/SectionRulesMaybe.js diff --git a/src/containers/ListingPage/ListingPage.js b/src/containers/ListingPage/ListingPage.js index 61218e44..162062c7 100644 --- a/src/containers/ListingPage/ListingPage.js +++ b/src/containers/ListingPage/ListingPage.js @@ -20,7 +20,6 @@ import { AvatarLarge, AvatarMedium, Button, - Map, ModalInMobile, Page, ResponsiveImage, @@ -41,6 +40,8 @@ import { BookingDatesForm, TopbarContainer, EnquiryForm } from '../../containers import { sendEnquiry, loadData, setInitialValues } from './ListingPage.duck'; import EditIcon from './EditIcon'; +import SectionRulesMaybe from './SectionRulesMaybe'; +import SectionMapMaybe from './SectionMapMaybe'; import css from './ListingPage.css'; // This defines when ModalInMobile shows content as Modal @@ -358,20 +359,8 @@ export class ListingPageComponent extends Component { }); const authorDisplayName = userDisplayName(ensuredAuthor, bannedUserDisplayName); - const address = publicData.location ? publicData.location.address : ''; - const bookBtnMessage = intl.formatMessage({ id: 'ListingPage.ctaButtonMessage' }); const { formattedPrice, priceTitle } = priceData(price, intl); - const map = geolocation ? ( -
-

- -

-
- -
-
- ) : null; const showClosedListingHelpText = currentListing.id && isClosed; const bookingHeading = ( @@ -567,7 +556,8 @@ export class ListingPageComponent extends Component {

{description}

- {map} + +

diff --git a/src/containers/ListingPage/SectionMapMaybe.js b/src/containers/ListingPage/SectionMapMaybe.js new file mode 100644 index 00000000..0d0b6a0a --- /dev/null +++ b/src/containers/ListingPage/SectionMapMaybe.js @@ -0,0 +1,36 @@ +import React from 'react'; +import { object, string } from 'prop-types'; +import { FormattedMessage } from 'react-intl'; +import classNames from 'classnames'; +import { propTypes } from '../../util/types'; +import { Map } from '../../components'; + +import css from './ListingPage.css'; + +const SectionMapMaybe = props => { + const { className, rootClassName, geolocation, publicData } = props; + const address = publicData.location ? publicData.location.address : ''; + const classes = classNames(rootClassName || css.locationContainer, className); + + return geolocation ? ( +
+

+ +

+
+ +
+
+ ) : null; +}; + +SectionMapMaybe.defaultProps = { className: null, rootClassName: null }; + +SectionMapMaybe.propTypes = { + className: string, + rootClassName: string, + geolocation: propTypes.latlng.isRequired, + publicData: object.isRequired, +}; + +export default SectionMapMaybe; diff --git a/src/containers/ListingPage/SectionRulesMaybe.css b/src/containers/ListingPage/SectionRulesMaybe.css new file mode 100644 index 00000000..fb6dcaff --- /dev/null +++ b/src/containers/ListingPage/SectionRulesMaybe.css @@ -0,0 +1,37 @@ +@import '../../marketplace.css'; + +.root { + padding: 0 24px; + margin-bottom: 35px; + + @media (--viewportMedium) { + padding: 0; + margin-bottom: 52px; + } +} + +.title { + /* Font */ + @apply --marketplaceH3FontStyles; + color: var(--matterColorAnti); + + margin-top: 0; + margin-bottom: 13px; + @media (--viewportMedium) { + margin-top: 0; + margin-bottom: 20px; + } +} + +.rules { + margin-top: 0; + margin-bottom: 0; + + /* Preserve newlines, but collapse other whitespace */ + white-space: pre-line; + + @media (--viewportMedium) { + margin-top: 0; + margin-bottom: 0; + } +} diff --git a/src/containers/ListingPage/SectionRulesMaybe.js b/src/containers/ListingPage/SectionRulesMaybe.js new file mode 100644 index 00000000..a78571d1 --- /dev/null +++ b/src/containers/ListingPage/SectionRulesMaybe.js @@ -0,0 +1,31 @@ +import React from 'react'; +import { shape, string } from 'prop-types'; +import { FormattedMessage } from 'react-intl'; +import classNames from 'classnames'; + +import css from './SectionRulesMaybe.css'; + +const SectionRulesMaybe = props => { + const { className, rootClassName, publicData } = props; + const classes = classNames(rootClassName || css.root, className); + return publicData.rules ? ( +
+

+ +

+

{publicData.rules}

+
+ ) : null; +}; + +SectionRulesMaybe.defaultProps = { className: null, rootClassName: null }; + +SectionRulesMaybe.propTypes = { + className: string, + rootClassName: string, + publicData: shape({ + rules: string, + }).isRequired, +}; + +export default SectionRulesMaybe; diff --git a/src/containers/ListingPage/__snapshots__/ListingPage.test.js.snap b/src/containers/ListingPage/__snapshots__/ListingPage.test.js.snap index c1fcbaf5..31ea2e2f 100644 --- a/src/containers/ListingPage/__snapshots__/ListingPage.test.js.snap +++ b/src/containers/ListingPage/__snapshots__/ListingPage.test.js.snap @@ -271,28 +271,22 @@ exports[`ListingPage matches snapshot 1`] = ` listing1 description

-
-

- -

-
- -
-
+ +