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

[C-4387] Add new responsive search page #8499

Merged
merged 14 commits into from
May 23, 2024
6 changes: 4 additions & 2 deletions packages/common/src/services/remote-config/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ export enum FeatureFlags {
USE_SDK_REWARDS = 'use_sdk_rewards',
DISCOVERY_TIP_REACTIONS = 'discovery_tip_reactions',
USE_ADDRESS_LOOKUPS = 'use_address_lookups',
MANAGER_MODE = 'manager_mode'
MANAGER_MODE = 'manager_mode',
SEARCH_V2 = 'search_v2'
}

type FlagDefaults = Record<FeatureFlags, boolean>
Expand Down Expand Up @@ -140,5 +141,6 @@ export const flagDefaults: FlagDefaults = {
[FeatureFlags.USE_SDK_REWARDS]: false,
[FeatureFlags.DISCOVERY_TIP_REACTIONS]: false,
[FeatureFlags.USE_ADDRESS_LOOKUPS]: false,
[FeatureFlags.MANAGER_MODE]: false
[FeatureFlags.MANAGER_MODE]: false,
[FeatureFlags.SEARCH_V2]: false
}
1 change: 1 addition & 0 deletions packages/harmony/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export * from './progress-bar'
export * from './scrubber'
export * from './skeleton'
export * from './artwork'
export { default as LoadingSpinner } from './loading-spinner/LoadingSpinner'
2 changes: 1 addition & 1 deletion packages/web/src/app/AppProviders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { LastLocationProvider } from 'react-router-last-location'

import { RouterContextProvider } from 'components/animated-switch/RouterContextProvider'
import { HeaderContextProvider } from 'components/header/mobile/HeaderContextProvider'
import { NavProvider } from 'components/nav/store/context'
import { NavProvider } from 'components/nav/mobile/NavContext'
import { ScrollProvider } from 'components/scroll-provider/ScrollProvider'
import { ToastContextProvider } from 'components/toast/ToastContext'
import { getSystemAppearance, getTheme } from 'utils/theme/theme'
Expand Down
43 changes: 27 additions & 16 deletions packages/web/src/app/web-player/WebPlayer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import RepostsPage from 'pages/reposts-page/RepostsPage'
import { RequiresUpdate } from 'pages/requires-update/RequiresUpdate'
import SavedPage from 'pages/saved-page/SavedPage'
import SearchPage from 'pages/search-page/SearchPage'
import { SearchPageV2 } from 'pages/search-page-v2/SearchPageV2'
import SettingsPage from 'pages/settings-page/SettingsPage'
import { SubPage } from 'pages/settings-page/components/mobile/SettingsPage'
import SmartCollectionPage from 'pages/smart-collection/SmartCollectionPage'
Expand Down Expand Up @@ -398,7 +399,8 @@ class WebPlayer extends Component {
}

render() {
const { incrementScroll, decrementScroll, userHandle } = this.props
const { incrementScroll, decrementScroll, userHandle, isSearchV2Enabled } =
this.props

const {
showWebUpdateBanner,
Expand Down Expand Up @@ -647,23 +649,31 @@ class WebPlayer extends Component {

<Route
path={SEARCH_CATEGORY_PAGE}
render={(props) => (
<SearchPage
{...props}
scrollToTop={this.scrollToTop}
containerRef={this.props.mainContentRef.current}
/>
)}
render={(props) =>
isSearchV2Enabled ? (
<SearchPageV2 />
) : (
<SearchPage
{...props}
scrollToTop={this.scrollToTop}
containerRef={this.props.mainContentRef.current}
/>
)
}
/>
<Route
path={SEARCH_PAGE}
render={(props) => (
<SearchPage
{...props}
scrollToTop={this.scrollToTop}
containerRef={this.props.mainContentRef.current}
/>
)}
render={(props) =>
isSearchV2Enabled ? (
<SearchPageV2 />
) : (
<SearchPage
{...props}
scrollToTop={this.scrollToTop}
containerRef={this.props.mainContentRef.current}
/>
)
}
/>

<DesktopRoute
Expand Down Expand Up @@ -990,7 +1000,8 @@ const mapStateToProps = (state) => ({
accountStatus: getAccountStatus(state),
signOnStatus: getSignOnStatus(state),
showCookieBanner: getShowCookieBanner(state),
isChatEnabled: getFeatureEnabled(FeatureFlags.CHAT_ENABLED)
isChatEnabled: getFeatureEnabled(FeatureFlags.CHAT_ENABLED),
isSearchV2Enabled: getFeatureEnabled(FeatureFlags.SEARCH_V2)
})

const mapDispatchToProps = (dispatch) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { Dispatch } from 'redux'
import { CollectionCard } from 'components/collection'
import CardLineup from 'components/lineup/CardLineup'
import MobilePageContainer from 'components/mobile-page-container/MobilePageContainer'
import { useTemporaryNavContext } from 'components/nav/mobile/NavContext'
import TextElement, { Type } from 'components/nav/mobile/TextElement'
import { useTemporaryNavContext } from 'components/nav/store/context'
import { ToastContext } from 'components/toast/ToastContext'
import useHasChangedRoute from 'hooks/useHasChangedRoute'
import NewPlaylistButton from 'pages/saved-page/components/mobile/NewPlaylistButton'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import DynamicImage from 'components/dynamic-image/DynamicImage'
import EditableRow, { Format } from 'components/groupable-list/EditableRow'
import GroupableList from 'components/groupable-list/GroupableList'
import Grouping from 'components/groupable-list/Grouping'
import { useTemporaryNavContext } from 'components/nav/mobile/NavContext'
import TextElement, { Type } from 'components/nav/mobile/TextElement'
import { useTemporaryNavContext } from 'components/nav/store/context'
import TrackList from 'components/track/mobile/TrackList'
import { useCollectionCoverArt } from 'hooks/useCollectionCoverArt'
import useHasChangedRoute from 'hooks/useHasChangedRoute'
Expand Down
19 changes: 13 additions & 6 deletions packages/web/src/components/header/desktop/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'

import { BackButton } from 'components/back-button/BackButton'
import { HeaderGutter } from 'components/header/desktop/HeaderGutter'
import { useMedia } from 'hooks/useMedia'

import styles from './Header.module.css'

Expand Down Expand Up @@ -32,6 +33,8 @@ const Header = (props) => {
[styles.page]: variant === 'page'
}

const { isMobile } = useMedia()

return (
<>
<HeaderGutter
Expand All @@ -40,12 +43,16 @@ const Header = (props) => {
scrollBarWidth={scrollBarWidth}
/>
<div
className={cn(
styles.container,
variantStyle,
{ [containerStyles]: !!containerStyles },
{ [styles.containerWithBar]: !!bottomBar }
)}
className={
!isMobile
? cn(
styles.container,
variantStyle,
{ [containerStyles]: !!containerStyles },
{ [styles.containerWithBar]: !!bottomBar }
)
: undefined
}
>
<div
className={cn(styles.maxWidthWrapper, {
Expand Down
31 changes: 23 additions & 8 deletions packages/web/src/components/nav/mobile/NavBar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState, useContext, useCallback, useEffect } from 'react'

import { useFeatureFlag } from '@audius/common/hooks'
import { Status } from '@audius/common/models'
import { FeatureFlags } from '@audius/common/services'
import { formatCount } from '@audius/common/utils'
Expand All @@ -18,6 +19,7 @@ import { Link } from 'react-router-dom'
// eslint-disable-next-line no-restricted-imports -- TODO: migrate to @react-spring/web
import { useTransition, animated } from 'react-spring'

import { useHistoryContext } from 'app/HistoryProvider'
import {
RouterContext,
SlideDirection
Expand All @@ -26,7 +28,7 @@ import NavContext, {
LeftPreset,
CenterPreset,
RightPreset
} from 'components/nav/store/context'
} from 'components/nav/mobile/NavContext'
import SearchBar from 'components/search-bar/SearchBar'
import { useFlag } from 'hooks/useRemoteConfig'
import { getIsIOS } from 'utils/browser'
Expand All @@ -52,6 +54,7 @@ interface NavBarProps {
const messages = {
signUp: 'Sign Up',
searchPlaceholder: 'Search Audius',
searchPlaceholderV2: 'What do you want to listen to?',
earlyAccess: 'Early Access'
}

Expand All @@ -70,7 +73,11 @@ const NavBar = ({
location: { pathname }
}
}: NavBarProps) => {
const { history } = useHistoryContext()
const { leftElement, centerElement, rightElement } = useContext(NavContext)!
const { isEnabled: isSearchV2Enabled } = useFeatureFlag(
FeatureFlags.SEARCH_V2
)

const [isSearching, setIsSearching] = useState(false)
const [searchValue, setSearchValue] = useState('')
Expand All @@ -84,11 +91,17 @@ const NavBar = ({
useEffect(() => {
const splitPath = pathname.split('/')
const isSearch = splitPath.length > 1 && splitPath[1] === 'search'
if (!isSearch) {
setIsSearching(false)
}
setIsSearching(isSearch)
}, [pathname])

const handleOpenSearch = useCallback(() => {
if (isSearchV2Enabled) {
history.push(`/search`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to dispatch the push?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, making that change now!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah actually even if I don't dispatch it a router location change action still occurs. I noticed some other places we just use history.push so just double checked

} else {
setIsSearching(true)
}
}, [history, isSearchV2Enabled])

const onCloseSearch = () => {
setIsSearching(false)
setSearchValue('')
Expand Down Expand Up @@ -243,13 +256,15 @@ const NavBar = ({
{rightElement === RightPreset.SEARCH ? (
<SearchBar
open={isSearching}
onOpen={() => {
setIsSearching(true)
}}
onOpen={handleOpenSearch}
onClose={onCloseSearch}
value={searchValue}
onSearch={setSearchValue}
placeholder={messages.searchPlaceholder}
placeholder={
isSearchV2Enabled
? messages.searchPlaceholderV2
: messages.searchPlaceholder
}
showHeader={false}
className={cn(
styles.searchBar,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useDispatch, useSelector } from 'react-redux'

import loadingSpinner from 'assets/animations/loadingSpinner.json'
import MobilePageContainer from 'components/mobile-page-container/MobilePageContainer'
import NavContext, { LeftPreset } from 'components/nav/store/context'
import NavContext, { LeftPreset } from 'components/nav/mobile/NavContext'

import { EmptyNotifications } from './EmptyNotifications'
import { Notification } from './Notification'
Expand Down
13 changes: 10 additions & 3 deletions packages/web/src/components/search-bar/ConnectedSearchBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
imageProfilePicEmpty as profilePicEmpty
} from '@audius/common/assets'
import { Name, SquareSizes } from '@audius/common/models'
import { FeatureFlags } from '@audius/common/services'
import { getTierForUser } from '@audius/common/store'
import { push as pushRoute } from 'connected-react-router'
import { has } from 'lodash'
Expand All @@ -20,7 +21,9 @@ import {
clearSearch
} from 'common/store/search-bar/actions'
import { getSearch } from 'common/store/search-bar/selectors'
import Bar from 'components/search/SearchBar'
import SearchBar from 'components/search/SearchBar'
import SearchBarV2 from 'components/search/SearchBarV2'
import { getFeatureEnabled } from 'services/remote-config/featureFlagHelpers'
import { collectionPage, profilePage, getPathname } from 'utils/route'

import styles from './ConnectedSearchBar.module.css'
Expand Down Expand Up @@ -256,9 +259,12 @@ class ConnectedSearchBar extends Component {
0
)
const { status, searchText } = this.props.search
const SearchBarComponent = this.props.isSearchV2Enabled
? SearchBarV2
: SearchBar
return (
<div className={styles.search}>
<Bar
<SearchBarComponent
value={this.state.value}
isTagSearch={this.isTagSearch()}
status={status}
Expand All @@ -277,7 +283,8 @@ class ConnectedSearchBar extends Component {
}

const mapStateToProps = (state, props) => ({
search: getSearch(state, props)
search: getSearch(state, props),
isSearchV2Enabled: getFeatureEnabled(FeatureFlags.SEARCH_V2)
})
const mapDispatchToProps = (dispatch) => ({
fetchSearch: (value) => dispatch(fetchSearch(value)),
Expand Down
Loading