Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update topbar search #20

Merged
merged 8 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ way to update this template, but currently, we follow a pattern:

## Upcoming version 2020-XX-XX

- [change] Make Topbar search configurable and use keyword-search there
[#20](https://github.com/sharetribe/ftw-product/pull/20)
- [change] Move stripe related forms and forms directory
[#17](https://github.com/sharetribe/ftw-product/pull/17)
- [change] Remove PayoutDetailsForm and rename some functions
Expand Down
34 changes: 0 additions & 34 deletions src/components/Logo/IconLogo.js

This file was deleted.

9 changes: 3 additions & 6 deletions src/components/Logo/Logo.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

import config from '../../config';
import IconLogo from './IconLogo';
import LogoImage from './saunatime-logo.png';
import css from './Logo.module.css';
import LogoImageMobile from './sneakertime-logo-mobile.png';
import LogoImage from './sneakertime-logo.png';

const Logo = props => {
const { className, format, ...rest } = props;
const mobileClasses = classNames(css.logoMobile, className);

if (format === 'desktop') {
return <img className={className} src={LogoImage} alt={config.siteTitle} {...rest} />;
}

return <IconLogo className={mobileClasses} {...rest} />;
return <img className={className} src={LogoImageMobile} alt={config.siteTitle} {...rest} />;
};

const { oneOf, string } = PropTypes;
Expand Down
5 changes: 0 additions & 5 deletions src/components/Logo/Logo.module.css

This file was deleted.

Binary file added src/components/Logo/sneakertime-logo-mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/components/Logo/sneakertime-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 39 additions & 18 deletions src/components/Topbar/Topbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import classNames from 'classnames';
import config from '../../config';
import routeConfiguration from '../../routing/routeConfiguration';
import { FormattedMessage, intlShape, injectIntl } from '../../util/reactIntl';
import { isMainSearchTypeKeywords, isOriginInUse } from '../../util/search';
import { withViewport } from '../../util/contextHelpers';
import { parse, stringify } from '../../util/urlHelpers';
import { createResourceLocatorString, pathByRouteName } from '../../util/routes';
Expand Down Expand Up @@ -99,15 +100,26 @@ class TopbarComponent extends Component {

handleSubmit(values) {
const { currentSearchParams } = this.props;
const { search, selectedPlace } = values.location;
const { history } = this.props;
const { origin, bounds } = selectedPlace;
const originMaybe = config.sortSearchByDistance ? { origin } : {};

const topbarSearchParams = () => {
if (isMainSearchTypeKeywords(config)) {
return { keywords: values?.keywords };
}
// topbar search defaults to 'location' search
const { search, selectedPlace } = values?.location;
const { origin, bounds } = selectedPlace;
const originMaybe = isOriginInUse(config) ? { origin } : {};

return {
...originMaybe,
address: search,
bounds,
};
};
const searchParams = {
...currentSearchParams,
...originMaybe,
address: search,
bounds,
...topbarSearchParams(),
};
history.push(createResourceLocatorString('SearchPage', routeConfiguration(), {}, searchParams));
}
Expand Down Expand Up @@ -154,7 +166,7 @@ class TopbarComponent extends Component {
showGenericError,
} = this.props;

const { mobilemenu, mobilesearch, address, origin, bounds } = parse(location.search, {
const { mobilemenu, mobilesearch, keywords, address, origin, bounds } = parse(location.search, {
latlng: ['origin'],
latlngBounds: ['bounds'],
});
Expand All @@ -176,18 +188,25 @@ class TopbarComponent extends Component {
/>
);

// Only render current search if full place object is available in the URL params
const locationFieldsPresent = config.sortSearchByDistance
? address && origin && bounds
: address && bounds;
const initialSearchFormValues = {
location: locationFieldsPresent
? {
search: address,
selectedPlace: { address, origin, bounds },
}
: null,
const topbarSearcInitialValues = () => {
if (isMainSearchTypeKeywords(config)) {
return { keywords };
}

// Only render current search if full place object is available in the URL params
const locationFieldsPresent = isOriginInUse(config)
? address && origin && bounds
: address && bounds;
return {
location: locationFieldsPresent
? {
search: address,
selectedPlace: { address, origin, bounds },
}
: null,
};
};
const initialSearchFormValues = topbarSearcInitialValues();

const classes = classNames(rootClassName || css.root, className);

Expand Down Expand Up @@ -236,6 +255,7 @@ class TopbarComponent extends Component {
notificationCount={notificationCount}
onLogout={this.handleLogout}
onSearchSubmit={this.handleSubmit}
appConfig={config}
/>
</div>
<Modal
Expand All @@ -260,6 +280,7 @@ class TopbarComponent extends Component {
onSubmit={this.handleSubmit}
initialValues={initialSearchFormValues}
isMobile
appConfig={config}
/>
<p className={css.mobileHelp}>
<FormattedMessage id="Topbar.mobileSearchHelp" />
Expand Down
8 changes: 5 additions & 3 deletions src/components/Topbar/TopbarDesktop/TopbarDesktop.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import { any, bool, func, object, number, string } from 'prop-types';
import classNames from 'classnames';

import { FormattedMessage, intlShape } from '../../../util/reactIntl';
Expand All @@ -23,6 +23,7 @@ import css from './TopbarDesktop.module.css';
const TopbarDesktop = props => {
const {
className,
appConfig,
currentUser,
currentPage,
rootClassName,
Expand Down Expand Up @@ -51,6 +52,7 @@ const TopbarDesktop = props => {
desktopInputRoot={css.topbarSearchWithLeftPadding}
onSubmit={onSearchSubmit}
initialValues={initialSearchFormValues}
appConfig={appConfig}
/>
);

Expand Down Expand Up @@ -157,15 +159,14 @@ const TopbarDesktop = props => {
);
};

const { bool, func, object, number, string } = PropTypes;

TopbarDesktop.defaultProps = {
rootClassName: null,
className: null,
currentUser: null,
currentPage: null,
notificationCount: 0,
initialSearchFormValues: {},
appConfig: null,
};

TopbarDesktop.propTypes = {
Expand All @@ -180,6 +181,7 @@ TopbarDesktop.propTypes = {
onSearchSubmit: func.isRequired,
initialSearchFormValues: object,
intl: intlShape.isRequired,
appConfig: object,
};

export default TopbarDesktop;
19 changes: 18 additions & 1 deletion src/components/Topbar/TopbarDesktop/TopbarDesktop.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import TopbarDesktop from './TopbarDesktop';
const noop = () => null;

describe('TopbarDesktop', () => {
it('data matches snapshot', () => {
it('data with location search matches snapshot', () => {
window.google = { maps: {} };
const topbarProps = {
isAuthenticated: true,
Expand All @@ -15,6 +15,23 @@ describe('TopbarDesktop', () => {
onSearchSubmit: noop,
intl: fakeIntl,
onLogout: noop,
appConfig: { mainSearchType: 'location' },
};
const tree = renderDeep(<TopbarDesktop {...topbarProps} />);
delete window.google;
expect(tree).toMatchSnapshot();
});

it('data with keywords search matches snapshot', () => {
window.google = { maps: {} };
const topbarProps = {
isAuthenticated: true,
currentUserHasListings: true,
name: 'John Doe',
onSearchSubmit: noop,
intl: fakeIntl,
onLogout: noop,
appConfig: { mainSearchType: 'keywords' },
};
const tree = renderDeep(<TopbarDesktop {...topbarProps} />);
delete window.google;
Expand Down
Loading