2020-10-31 23:37:15 +00:00
|
|
|
import React from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl'
|
|
|
|
import { me } from '../initial_state'
|
|
|
|
import {
|
|
|
|
BREAKPOINT_EXTRA_SMALL,
|
|
|
|
CX,
|
|
|
|
} from '../constants'
|
|
|
|
import Layout from '../layouts/layout'
|
|
|
|
import PageTitle from '../features/ui/util/page_title'
|
|
|
|
import DefaultNavigationBar from '../components/navigation_bar/default_navigation_bar'
|
|
|
|
import FooterBar from '../components/footer_bar'
|
|
|
|
import SearchNavigationBar from '../components/navigation_bar/search_navigation_bar_xs'
|
|
|
|
import LoggedOutNavigationBar from '../components/navigation_bar/logged_out_navigation_bar'
|
|
|
|
import Responsive from '../features/ui/util/responsive_component'
|
|
|
|
import WrappedBundle from '../features/ui/util/wrapped_bundle'
|
|
|
|
import Search from '../components/search'
|
|
|
|
import Pills from '../components/pills'
|
|
|
|
import {
|
|
|
|
LinkFooter,
|
2020-11-07 05:19:04 +00:00
|
|
|
TrendsBreakingPanel,
|
2020-10-31 23:37:15 +00:00
|
|
|
SearchFilterPanel,
|
|
|
|
SignUpPanel,
|
2020-11-03 21:27:39 +00:00
|
|
|
ExploreTimeline,
|
|
|
|
HashtagTimeline,
|
|
|
|
SidebarXS,
|
2020-10-31 23:37:15 +00:00
|
|
|
} from '../features/ui/util/async_components'
|
|
|
|
|
|
|
|
class SearchLayout extends React.PureComponent {
|
|
|
|
|
2020-11-03 21:27:39 +00:00
|
|
|
state = {
|
|
|
|
isSearchFocused: false,
|
|
|
|
currentExploreTabIndex: 0,
|
|
|
|
}
|
|
|
|
|
2020-10-31 23:37:15 +00:00
|
|
|
componentWillMount() {
|
|
|
|
const { intl } = this.props
|
|
|
|
|
2020-11-03 21:27:39 +00:00
|
|
|
this.exploreTabs = [
|
|
|
|
{
|
|
|
|
title: 'Explore',
|
|
|
|
onClick: () => this.setState({ currentExploreTabIndex: 0 }),
|
|
|
|
component: ExploreTimeline,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: '#Election2020',
|
|
|
|
onClick: () => this.setState({ currentExploreTabIndex: 1 }),
|
|
|
|
component: HashtagTimeline,
|
|
|
|
componentParams: { params: { id: 'election2020' } },
|
|
|
|
},
|
2020-11-05 03:27:34 +00:00
|
|
|
{
|
2020-11-05 17:59:30 +00:00
|
|
|
title: '#RiggedElection',
|
2020-11-05 03:27:34 +00:00
|
|
|
onClick: () => this.setState({ currentExploreTabIndex: 2 }),
|
|
|
|
component: HashtagTimeline,
|
2020-11-05 17:59:30 +00:00
|
|
|
componentParams: { params: { id: 'riggedelection' } },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: '#StopTheSteal',
|
|
|
|
onClick: () => this.setState({ currentExploreTabIndex: 3 }),
|
|
|
|
component: HashtagTimeline,
|
2020-11-05 03:27:34 +00:00
|
|
|
componentParams: { params: { id: 'stopthesteal' } },
|
|
|
|
},
|
2020-11-03 21:27:39 +00:00
|
|
|
]
|
|
|
|
|
2020-10-31 23:37:15 +00:00
|
|
|
this.searchTabs = [
|
|
|
|
{
|
|
|
|
title: intl.formatMessage(messages.top),
|
|
|
|
to: '/search',
|
|
|
|
active: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: intl.formatMessage(messages.people),
|
|
|
|
to: '/search/people',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: intl.formatMessage(messages.groups),
|
|
|
|
to: '/search/groups',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: intl.formatMessage(messages.statuses),
|
|
|
|
to: '/search/statuses',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: intl.formatMessage(messages.links),
|
|
|
|
to: '/search/links',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: intl.formatMessage(messages.hashtags),
|
|
|
|
to: '/search/hashtags',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2020-11-03 21:27:39 +00:00
|
|
|
handleOnToggleSearchExplore = (isSearchFocused) => {
|
|
|
|
this.setState({ isSearchFocused })
|
|
|
|
}
|
|
|
|
|
2020-10-31 23:37:15 +00:00
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
intl,
|
|
|
|
children,
|
|
|
|
value,
|
|
|
|
} = this.props
|
2020-11-03 21:27:39 +00:00
|
|
|
const {
|
|
|
|
isSearchFocused,
|
|
|
|
currentExploreTabIndex,
|
|
|
|
} = this.state
|
2020-10-31 23:37:15 +00:00
|
|
|
|
2020-11-03 21:27:39 +00:00
|
|
|
|
|
|
|
const activeExploreTab = this.exploreTabs[currentExploreTabIndex];
|
|
|
|
const activeTabComponent = activeExploreTab.component
|
|
|
|
const activeTabComponentParams = activeExploreTab.componentParams || {}
|
|
|
|
const activeExploreTabs = this.exploreTabs.map((tab, i) => {
|
|
|
|
return {
|
|
|
|
...tab,
|
|
|
|
active: i === currentExploreTabIndex,
|
|
|
|
}
|
2020-10-31 23:37:15 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
const title = intl.formatMessage(messages.search)
|
|
|
|
const qos = !!value ? value : ''
|
|
|
|
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
<Responsive max={BREAKPOINT_EXTRA_SMALL}>
|
2020-11-03 21:27:39 +00:00
|
|
|
|
|
|
|
<WrappedBundle component={SidebarXS} />
|
|
|
|
|
2020-10-31 23:37:15 +00:00
|
|
|
{
|
|
|
|
!!me &&
|
2020-11-03 21:27:39 +00:00
|
|
|
<SearchNavigationBar
|
|
|
|
isSearchFocused={isSearchFocused}
|
|
|
|
tabs={isSearchFocused ? this.searchTabs : activeExploreTabs}
|
|
|
|
onToggleSearchExplore={this.handleOnToggleSearchExplore}
|
|
|
|
/>
|
2020-10-31 23:37:15 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
!me &&
|
|
|
|
<LoggedOutNavigationBar />
|
|
|
|
}
|
|
|
|
|
2020-11-03 21:27:39 +00:00
|
|
|
<main role='main' className={[_s.d, _s.w100PC, _s.z1].join(' ')}>
|
2020-10-31 23:37:15 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
!me &&
|
|
|
|
<div className={[_s.d, _s.py15].join(' ')}>
|
|
|
|
<Pills pills={this.searchTabs} />
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
|
2020-11-03 21:27:39 +00:00
|
|
|
{
|
|
|
|
!!isSearchFocused &&
|
|
|
|
children
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
!isSearchFocused &&
|
|
|
|
<div className={[_s.d, _s.pt10, _s.w100PC].join(' ')}>
|
|
|
|
<WrappedBundle
|
|
|
|
component={activeTabComponent}
|
|
|
|
componentParams={activeTabComponentParams}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
}
|
2020-10-31 23:37:15 +00:00
|
|
|
</main>
|
|
|
|
|
|
|
|
<FooterBar />
|
|
|
|
|
|
|
|
</Responsive>
|
|
|
|
|
|
|
|
<Responsive min={BREAKPOINT_EXTRA_SMALL}>
|
|
|
|
<Layout
|
|
|
|
noComposeButton
|
|
|
|
title={title}
|
|
|
|
showBackBtn
|
|
|
|
tabs={this.searchTabs}
|
|
|
|
page={`search.${qos}`}
|
|
|
|
layout={[
|
|
|
|
SignUpPanel,
|
|
|
|
SearchFilterPanel,
|
2020-11-07 05:19:04 +00:00
|
|
|
TrendsBreakingPanel,
|
2020-10-31 23:37:15 +00:00
|
|
|
LinkFooter,
|
|
|
|
]}
|
|
|
|
>
|
|
|
|
<PageTitle path={title} />
|
|
|
|
{children}
|
|
|
|
</Layout>
|
|
|
|
</Responsive>
|
|
|
|
|
|
|
|
</React.Fragment>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SearchLayout.propTypes = {
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
children: PropTypes.node.isRequired,
|
|
|
|
value: PropTypes.string,
|
|
|
|
}
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
search: { id: 'search', defaultMessage: 'Search' },
|
|
|
|
top: { id: 'top', defaultMessage: 'Top' },
|
|
|
|
people: { id: 'people', defaultMessage: 'People' },
|
|
|
|
groups: { id: 'groups', defaultMessage: 'Groups' },
|
|
|
|
statuses: { id: 'statuses', defaultMessage: 'Statuses' },
|
|
|
|
hashtags: { id: 'hashtags', defaultMessage: 'Hashtags' },
|
|
|
|
links: { id: 'links', defaultMessage: 'Links' },
|
|
|
|
})
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => ({
|
|
|
|
value: state.getIn(['search', 'value']),
|
|
|
|
})
|
|
|
|
|
|
|
|
export default injectIntl(connect(mapStateToProps)(SearchLayout))
|