Skip to content

Commit

Permalink
refactor: remove ImgFixed use (#1633)
Browse files Browse the repository at this point in the history
  • Loading branch information
andyesp authored Feb 5, 2024
1 parent 8aa1800 commit c745243
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 40 deletions.
18 changes: 7 additions & 11 deletions src/components/Proposal/ProposalHeaderPoi.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,29 @@
justify-content: space-between;
}

.ProposalHeaderPoi .Link > div.PoiImageContainer {
.ProposalHeaderPoi .Link > div.ProposalHeaderPoi__ImageContainer {
position: relative;
flex: 0 0 100%;
}

.ProposalHeaderPoi .Link.Link--with-scene > div.PoiImageContainer {
.ProposalHeaderPoi .Link.Link--with-scene > div.ProposalHeaderPoi__ImageContainer {
flex: 0 0 49%;
flex: 0 0 calc(50% - 6px);
}

.ProposalHeaderPoi .ImgFixed {
border-radius: 8px;
}

.ProposalHeaderPoi .PoiImageContainer .ui.header {
.ProposalHeaderPoi__ImageContainer .ui.header {
position: absolute;
color: white;
color: var(--white-900);
left: 16px;
bottom: 52px;
margin: 0;
text-shadow: 0 0 1rem #000, 0 0 0.5rem #000;
}

.ProposalHeaderPoi .PoiImageContainer .PoiPosition {
.ProposalHeaderPoi__PoiPosition {
position: absolute;
color: var(--black-400);
background-color: white;
background-color: var(--white-900);
height: 24px;
border-radius: 4px;
font-size: 13px;
Expand All @@ -43,6 +39,6 @@
bottom: 16px;
}

.ProposalHeaderPoi .PoiImageContainer .PoiPosition svg {
.ProposalHeaderPoi__PoiPosition svg {
vertical-align: text-bottom;
}
59 changes: 30 additions & 29 deletions src/components/Proposal/ProposalHeaderPoi.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useQuery } from '@tanstack/react-query'
import ImgFixed from 'decentraland-gatsby/dist/components/Image/ImgFixed'
import Catalyst from 'decentraland-gatsby/dist/utils/api/Catalyst'
import { Header } from 'decentraland-ui/dist/components/Header/Header'

Expand All @@ -10,42 +9,44 @@ import Link from '../Common/Typography/Link'
import Pin from '../Icon/Pin'

import './ProposalHeaderPoi.css'
import ProposalHeaderPoiImage from './ProposalHeaderPoiImage'

interface Props {
configuration: ProposalAttributes['configuration']
}

export default function ProposalHeaderPoi({ configuration }: Props) {
const { x, y } = configuration
const fetchSceneImg = async (x: number, y: number) => {
const scenes = await Catalyst.getInstance().getEntityScenes([[x, y]])
const scene = scenes[0]
if (!scene) {
return null
}

const fetchSceneImg = async (x: number, y: number) => {
const scenes = await Catalyst.getInstance().getEntityScenes([[x, y]])
const scene = scenes[0]
if (!scene) {
return null
let image = scene?.metadata?.display?.navmapThumbnail || ''
if (image && !image.startsWith('https://')) {
const list = scene.content || []
const content = list.find((content) => content.file === image)
if (content) {
image = Catalyst.getInstance().getContentUrl(content.hash)
}
}

let image = scene?.metadata?.display?.navmapThumbnail || ''
if (image && !image.startsWith('https://')) {
const list = scene.content || []
const content = list.find((content) => content.file === image)
if (content) {
image = Catalyst.getInstance().getContentUrl(content.hash)
}
}
if (!image || !image.startsWith('https://')) {
return null
}

if (!image || !image.startsWith('https://')) {
return null
}
return image
}

return image
}
export default function ProposalHeaderPoi({ configuration }: Props) {
const { x, y } = configuration

const { data: tile } = useQuery({
queryKey: [`tile#${x},${y}`],
queryFn: () => getTile([x, y]),
staleTime: DEFAULT_QUERY_STALE_TIME,
})

const { data: sceneImg } = useQuery({
queryKey: [`sceneImg#${x},${y}`],
queryFn: () => fetchSceneImg(x, y),
Expand All @@ -56,15 +57,15 @@ export default function ProposalHeaderPoi({ configuration }: Props) {
return (
<div className="ProposalHeaderPoi">
<Link href={`https://play.decentraland.org/?position=${x},${y}`}>
<div className="PoiImageContainer">
<div className="ProposalHeaderPoi__ImageContainer">
<Header>{tile?.name || `Parcel ${x},${y}`}&nbsp;</Header>
<div className="PoiPosition">
<div className="ProposalHeaderPoi__PoiPosition">
<Pin />
<span>
{x},{y}
</span>
</div>
<ImgFixed dimension="wide" size="initial" src={getParcelImageUrl([x, y])} />
<ProposalHeaderPoiImage dimension="wide" size="initial" src={getParcelImageUrl([x, y])} />
</div>
</Link>
</div>
Expand All @@ -74,18 +75,18 @@ export default function ProposalHeaderPoi({ configuration }: Props) {
return (
<div className="ProposalHeaderPoi">
<Link href={`https://play.decentraland.org/?position=${x},${y}`} className="Link--with-scene">
<div className="PoiImageContainer">
<div className="ProposalHeaderPoi__ImageContainer">
<Header>{tile?.name || `Parcel ${x},${y}`}&nbsp;</Header>
<div className="PoiPosition">
<div className="ProposalHeaderPoi__PoiPosition">
<Pin />
<span>
{x},{y}
</span>
</div>
<ImgFixed dimension="standard" size="cover" src={sceneImg} />
<ProposalHeaderPoiImage dimension="standard" size="cover" src={sceneImg} />
</div>
<div className="PoiImageContainer">
<ImgFixed dimension="standard" size="initial" src={getParcelImageUrl([x, y])} />
<div className="ProposalHeaderPoi__ImageContainer">
<ProposalHeaderPoiImage dimension="standard" size="initial" src={getParcelImageUrl([x, y])} />
</div>
</Link>
</div>
Expand Down
12 changes: 12 additions & 0 deletions src/components/Proposal/ProposalHeaderPoiImage.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.ProposalHeaderPoiImage {
width: 100%;
background-color: transparent;
background-repeat: no-repeat;
background-position: center center;
border-radius: 8px;
}

.ProposalHeaderPoiImage img {
width: 100%;
height: auto;
}
34 changes: 34 additions & 0 deletions src/components/Proposal/ProposalHeaderPoiImage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import './ProposalHeaderPoiImage.css'

type Props = {
dimension: 'wide' | 'standard'
size?: 'cover' | 'initial'
src: string
}

export default function ProposalHeaderPoiImage({ src, dimension, size = 'cover' }: Props) {
return (
<div
className="ProposalHeaderPoiImage"
style={{
backgroundSize: size,
backgroundImage: src && `url("${src}")`,
}}
>
{dimension === 'wide' && (
<img
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAABCAYAAAD0In+KAAAADUlEQVR4AWNwL/ABYwAKHQIHW//QwwAAAABJRU5ErkJggg=="
width="2"
height="1"
/>
)}
{dimension === 'standard' && (
<img
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAYAAAC09K7GAAAAD0lEQVR4AWNwL/BBwYQFADuuDCW4Y5knAAAAAElFTkSuQmCC"
width="4"
height="3"
/>
)}
</div>
)
}

0 comments on commit c745243

Please sign in to comment.