Skip to content

Commit

Permalink
refactor: remove unused code in PlaceCard component
Browse files Browse the repository at this point in the history
  • Loading branch information
braianj committed Oct 31, 2024
1 parent 5ef5028 commit 9ea5dd1
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 82 deletions.
56 changes: 2 additions & 54 deletions src/components/Place/PlaceCard/PlaceCard.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import React, { useCallback, useContext, useMemo } from "react"
import React, { useContext, useMemo } from "react"

import { withPrefix } from "gatsby"

import ImgFixed from "decentraland-gatsby/dist/components/Image/ImgFixed"
import useTrackContext from "decentraland-gatsby/dist/context/Track/useTrackContext"
import useTrackLinkContext from "decentraland-gatsby/dist/context/Track/useTrackLinkContext"
import { Link } from "decentraland-gatsby/dist/plugins/intl"
import { navigate } from "decentraland-gatsby/dist/plugins/intl/utils"
import TokenList from "decentraland-gatsby/dist/utils/dom/TokenList"
import { Card } from "decentraland-ui/dist/components/Card/Card"

import { TrackingPlacesSearchContext } from "../../../context/TrackingContext"
import { AggregatePlaceAttributes } from "../../../entities/Place/types"
import { explorerUrl } from "../../../entities/Place/utils"
import locations from "../../../modules/locations"
import { SegmentPlace } from "../../../modules/segment"
import FavoriteButton from "../../Button/FavoriteButton"
import JumpInPositionButton from "../../Button/JumpInPositionButton"
import UserCount from "../../Label/UserCount/UserCount"
import UserLikePercentage from "../../Label/UserLikePercentage/UserLikePercentage"
import UserPreviewCount from "../../Label/UserPreviewCount/UserPreviewCount"
Expand All @@ -25,41 +21,17 @@ import "./PlaceCard.css"

export type PlaceCardProps = {
place?: AggregatePlaceAttributes
onClickFavorite?: (
e: React.MouseEvent<HTMLButtonElement>,
place: AggregatePlaceAttributes
) => void
dataPlace?: SegmentPlace
loading?: boolean
loadingFavorites?: boolean
positionWithinList?: number
}

export default React.memo(function PlaceCard(props: PlaceCardProps) {
const track = useTrackContext()

const {
place,
loading,
loadingFavorites,
onClickFavorite,
dataPlace,
positionWithinList,
} = props
const { place, loading, positionWithinList } = props

const [trackingId] = useContext(TrackingPlacesSearchContext)

const handleClickFavorite = useCallback(
(e: React.MouseEvent<any>) => {
e.stopPropagation()
e.preventDefault()
if (onClickFavorite && place) {
onClickFavorite(e, place)
}
},
[place, onClickFavorite]
)

const href = useMemo(() => {
if (place && !place.world) {
return locations.place(place.base_position)
Expand All @@ -68,8 +40,6 @@ export default React.memo(function PlaceCard(props: PlaceCardProps) {
}
}, [place])

const placerUrl = useMemo(() => place && explorerUrl(place), [place])

const handleClickCard = (e: React.MouseEvent<HTMLAnchorElement>) => {
e.preventDefault()
track(SegmentPlace.PlaceCardClick, {
Expand All @@ -81,8 +51,6 @@ export default React.memo(function PlaceCard(props: PlaceCardProps) {
href && navigate(href)
}

const handleJumpInTrack = useTrackLinkContext()

return (
<Card
as="div"
Expand Down Expand Up @@ -125,26 +93,6 @@ export default React.memo(function PlaceCard(props: PlaceCardProps) {
>
{place?.contact_name || " "}
</Card.Meta>
{false && (
/* hidden for now */
<div className="place-card__button-container">
<JumpInPositionButton
href={placerUrl}
loading={loading}
onClick={handleJumpInTrack}
data-event={SegmentPlace.JumpIn}
data-place-id={place?.id}
data-place={dataPlace}
data-trackingId={trackingId}
/>
<FavoriteButton
active={!!place?.user_favorite}
onClick={handleClickFavorite}
loading={loading || loadingFavorites}
dataPlace={dataPlace}
/>
</div>
)}
</Card.Content>
</Card>
)
Expand Down
10 changes: 0 additions & 10 deletions src/components/Place/PlaceList/PlaceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ export default React.memo(function PlaceList(props: PlaceListProps) {
key={props.item?.id}
place={props.item}
loading={loading}
onClickFavorite={onClickFavorite}
dataPlace={dataPlace}
loadingFavorites={
props.item?.id ? loadingFavorites?.has(props.item.id) : false
}
positionWithinList={places.findIndex(
({ id }) => id === props.item.id
)}
Expand All @@ -104,11 +99,6 @@ export default React.memo(function PlaceList(props: PlaceListProps) {
key={place?.id || key}
place={place}
loading={loading}
onClickFavorite={onClickFavorite}
dataPlace={dataPlace}
loadingFavorites={
place?.id ? loadingFavorites?.has(place.id) : false
}
positionWithinList={key}
/>
)
Expand Down
1 change: 1 addition & 0 deletions src/entities/Place/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function siteUrl(pathname = "") {
return target
}

/** @deprecated */
export function explorerUrl(
place?: Pick<PlaceAttributes, "base_position" | "world_name">,
realm?: string
Expand Down
18 changes: 0 additions & 18 deletions src/pages/favorites/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,6 @@ export default function FavoritesPage() {
placeListMyFavoritesState.version === 0 ||
placeListMyFavoritesState.loading
}
onClickFavorite={(e, place) =>
handleFavorite(place.id, place, {
place: e.currentTarget.dataset.place!,
})
}
dataPlace={SegmentPlace.FavoritesPlaces}
loadingFavorites={
item?.id ? handlingFavorite?.has(item.id) : false
}
/>
)
})}
Expand Down Expand Up @@ -284,15 +275,6 @@ export default function FavoritesPage() {
worldListMyFavoritesState.version === 0 ||
worldListMyFavoritesState.loading
}
onClickFavorite={(e, place) =>
handleFavorite(place.id, place, {
place: e.currentTarget.dataset.place!,
})
}
dataPlace={SegmentPlace.FavoritesPlaces}
loadingFavorites={
item?.id ? handlingFavorite?.has(item.id) : false
}
/>
)
})}
Expand Down

0 comments on commit 9ea5dd1

Please sign in to comment.