Skip to content

Commit

Permalink
fix: Names search showing other assets (#2266)
Browse files Browse the repository at this point in the history
  • Loading branch information
LautaroPetaccio authored Jul 10, 2024
1 parent 116f791 commit 28863a3
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 5 deletions.
3 changes: 2 additions & 1 deletion webapp/src/components/AssetBrowse/AssetBrowse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const AssetBrowse = (props: Props) => {
onlyOnSale,
onlySmart,
viewInState,
disableSearchDropdown,
onlyOnRent
} = props

Expand Down Expand Up @@ -186,7 +187,7 @@ const AssetBrowse = (props: Props) => {
case DecentralandSection.ENS:
right = (
<>
<AssetTopbar />
<AssetTopbar disableSearchDropdown={disableSearchDropdown} />
<AssetList isManager={isCurrentAccount} />
</>
)
Expand Down
6 changes: 5 additions & 1 deletion webapp/src/components/AssetBrowse/AssetBrowse.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type Props = {
onBrowse: typeof browse
onlyOnSale?: boolean
onlySmart?: boolean
disableSearchDropdown?: boolean
onlyOnRent?: boolean
}

Expand All @@ -31,4 +32,7 @@ export type MapStateProps = Pick<
>
export type MapDispatchProps = Pick<Props, 'onSetView' | 'onFetchAssetsFromRoute' | 'onBrowse'>
export type MapDispatch = Dispatch<SetViewAction | FetchAssetsFromRouteAction | BrowseAction>
export type OwnProps = Pick<Props, 'vendor' | 'address' | 'isFullscreen' | 'isMap' | 'view' | 'sections' | 'section' | 'contracts'>
export type OwnProps = Pick<
Props,
'vendor' | 'address' | 'isFullscreen' | 'isMap' | 'view' | 'sections' | 'section' | 'contracts' | 'disableSearchDropdown'
>
5 changes: 3 additions & 2 deletions webapp/src/components/AssetTopbar/AssetTopbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const AssetTopbar = ({
onBrowse,
onClearFilters,
onOpenFiltersModal,
disableSearchDropdown,
sortByOptions
}: Props): JSX.Element => {
const isMobile = useTabletAndBelowMediaQuery()
Expand All @@ -41,7 +42,7 @@ export const AssetTopbar = ({
const handleInputChange = useCallback(
(text: string) => {
// if the user is typing, open the dropdown
if (!shouldRenderSearchDropdown && text) {
if (!shouldRenderSearchDropdown && text && !disableSearchDropdown) {
setShouldRenderSearchDropdown(true)
}
// if the user clears the input, reset the search
Expand All @@ -50,7 +51,7 @@ export const AssetTopbar = ({
search: ''
}) // triggers search with no search term
}
if (shouldRenderSearchDropdown) {
if (shouldRenderSearchDropdown && !disableSearchDropdown) {
setSearchValueForDropdown(text)
} else if (text && text !== search) {
// common search, when the dropdown is not opened and the input is different than the current search term
Expand Down
1 change: 1 addition & 0 deletions webapp/src/components/AssetTopbar/AssetTopbar.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type Props = {
section: Section
hasFiltersEnabled: boolean
isLoading: boolean
disableSearchDropdown?: boolean
onBrowse: (options: BrowseOptions) => void
onClearFilters: typeof clearFilters
onOpenFiltersModal: () => ReturnType<typeof openModal>
Expand Down
8 changes: 7 additions & 1 deletion webapp/src/components/NamesPage/NamesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import { PageLayout } from '../PageLayout'
const NamesPage = () => {
return (
<PageLayout activeTab={NavigationTab.NAMES}>
<AssetBrowse vendor={VendorName.DECENTRALAND} view={View.MARKET} section={Section.ENS} sections={[Section.ENS]} />
<AssetBrowse
disableSearchDropdown
vendor={VendorName.DECENTRALAND}
view={View.MARKET}
section={Section.ENS}
sections={[Section.ENS]}
/>
</PageLayout>
)
}
Expand Down
6 changes: 6 additions & 0 deletions webapp/src/modules/routing/selectors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ describe('when getting if the are filters set', () => {
})

describe('when getting the section', () => {
describe("and there's no section URL param and the location is related to names", () => {
it("should return the decentraland's ENS section", () => {
expect(getSection.resultFunc('', locations.names(), VendorName.DECENTRALAND)).toBe(Sections.decentraland.ENS)
})
})

describe("when there's no section URL param and the location is related to lands", () => {
it("should return the decentraland's LAND section", () => {
expect(getSection.resultFunc('', locations.lands(), VendorName.DECENTRALAND)).toBe(Sections.decentraland.LAND)
Expand Down
4 changes: 4 additions & 0 deletions webapp/src/modules/routing/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export const getSection = createSelector<RootState, string, ReturnType<typeof ge
return Sections.decentraland.LAND
}

if (!section && pathname === locations.names()) {
return Sections.decentraland.ENS
}

if (
(!section || (isOfEnumType(section, Sections[vendor]) && section === Sections[vendor].ALL)) &&
pathname === locations.browse() &&
Expand Down

0 comments on commit 28863a3

Please sign in to comment.