From fd18ed14277b084b8de605350f4dec1275788992 Mon Sep 17 00:00:00 2001 From: Vesa Luusua Date: Fri, 27 Jan 2017 00:49:39 +0200 Subject: [PATCH] Refactor to more simple solution --- src/containers/SearchPage/SearchPage.js | 47 +++++++------------ .../__snapshots__/SearchPage.test.js.snap | 6 +-- 2 files changed, 21 insertions(+), 32 deletions(-) diff --git a/src/containers/SearchPage/SearchPage.js b/src/containers/SearchPage/SearchPage.js index 5bb52070..5aeb1d17 100644 --- a/src/containers/SearchPage/SearchPage.js +++ b/src/containers/SearchPage/SearchPage.js @@ -1,7 +1,7 @@ import React, { PropTypes } from 'react'; import classNames from 'classnames'; import { connect } from 'react-redux'; -import { find } from 'lodash'; +import { includes } from 'lodash'; import { addFlashNotification } from '../../ducks/FlashNotification.ducks'; import { addFilter } from './SearchPage.ducks'; import css from './SearchPage.css'; @@ -14,31 +14,6 @@ import { SearchResultsPanel, } from '../../components'; -const tabClasses = [ - { name: 'filters', css: css.filters }, - { name: 'listings', css: css.listings }, - { name: 'map', css: css.map }, -]; - -const findTab = forTabType => { - const foundTab = find(tabClasses, c => c.name === forTabType); - if (!foundTab) { - return find(tabClasses, c => c.name === 'listings'); - } - return foundTab; -}; - -const combinedClasses = (forTabType, currentTab) => { - const foundTab = findTab(forTabType); - const shouldOpenDefault = !currentTab && foundTab.name === 'listings'; - - if (foundTab.name === currentTab || shouldOpenDefault) { - return classNames(foundTab.css, css.open); - } - - return foundTab.css; -}; - const fakeListings = [ { id: 123, @@ -66,18 +41,32 @@ const fakeListings = [ export const SearchPageComponent = props => { const { tab } = props; + const selectedTab = includes(['filters','listings', 'map'], tab) + ? tab + : 'listings'; + + const filtersClassName = classNames(css.filters, { + [css.open]: selectedTab === 'filters', + }); + const listingsClassName = classNames(css.filters, { + [css.open]: selectedTab === 'listings', + }); + const mapClassName = classNames(css.filters, { + [css.open]: selectedTab === 'map', + }); + return (
-
+
-
+
{fakeListings.map(l => )}
-
+
{fakeListings.map(l => )} diff --git a/src/containers/SearchPage/__snapshots__/SearchPage.test.js.snap b/src/containers/SearchPage/__snapshots__/SearchPage.test.js.snap index 1d1ee0ee..fe5450ef 100644 --- a/src/containers/SearchPage/__snapshots__/SearchPage.test.js.snap +++ b/src/containers/SearchPage/__snapshots__/SearchPage.test.js.snap @@ -122,7 +122,7 @@ exports[`SearchPageComponent matches snapshot 1`] = `
+ className="">

@@ -145,7 +145,7 @@ exports[`SearchPageComponent matches snapshot 1`] = `

+ className="undefined">
@@ -343,7 +343,7 @@ exports[`SearchPageComponent matches snapshot 1`] = `
+ className="">