-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from MediaComem/merge-after-figma_link
Add post figma-link code
- Loading branch information
Showing
10 changed files
with
10,038 additions
and
10,281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { | ||
AccordionButton, | ||
AccordionItem, | ||
AccordionPanel, | ||
Box, | ||
Heading, | ||
} from "@chakra-ui/react"; | ||
import AccordionChevron from "../layout/AccordionChevron"; | ||
import Recommandation from "./Recommandation"; | ||
import { RecommandationType } from "./RecommandationsList"; | ||
import ZoneScreenshot from "../zones/ZoneScreenshot"; | ||
|
||
interface RecommandationDisplayProps { | ||
zoneRecommandations: RecommandationType[]; | ||
zoneId: string; | ||
} | ||
|
||
export default function RecommandationsByZone({ | ||
zoneRecommandations, | ||
zoneId, | ||
}: RecommandationDisplayProps) { | ||
//const { totalBenefits, setTotalBenefits } = React.useContext(ReportCTX); | ||
|
||
const showZone = zoneRecommandations.find((reco) => reco.betterValue); | ||
|
||
return showZone ? ( | ||
<AccordionItem> | ||
{({ isExpanded }) => ( | ||
<> | ||
<AccordionButton _hover={{ backgroundColor: "brand.100" }} pl={2}> | ||
<Box flex="1" textAlign="left"> | ||
<Heading mr={1} size="sm"> | ||
{zoneRecommandations[0].zoneName} | ||
</Heading> | ||
<ZoneScreenshot zoneId={zoneId} /> | ||
</Box> | ||
<AccordionChevron isExpanded={isExpanded} /> | ||
</AccordionButton> | ||
<AccordionPanel> | ||
{zoneRecommandations?.map((reco) => ( | ||
<Recommandation recommandation={reco} key={reco.id} /> | ||
))} | ||
</AccordionPanel> | ||
</> | ||
)} | ||
</AccordionItem> | ||
) : null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { useAppSelector } from "../../app/hooks"; | ||
import { Image as ChakraImage, Box } from "@chakra-ui/react"; | ||
import { useEffect, useState } from "react"; | ||
import { getSvgUrlFromCurrentUrl } from "../../features/figma/components/FetchedSVG"; | ||
import { RootState } from "../../app/store"; | ||
import { ZONES_CONTAINER_WIDTH } from "../../services/const"; | ||
|
||
//GET image loaded into project | ||
//Link project to S3 url -> one img/ project | ||
type ZoneScreenshotProps = { | ||
zoneId: string; | ||
}; | ||
|
||
const screenshotPadding = 10; | ||
|
||
const ZoneScreenshot = ({ zoneId }: ZoneScreenshotProps) => { | ||
const zone = useAppSelector((state: RootState) => | ||
state.zonesSlice.zones?.find((z) => z.id === zoneId) | ||
); | ||
|
||
const [zoneDim, setZoneDim] = useState({ | ||
x: zone?.x || 0, | ||
y: zone?.y || 0, | ||
width: zone?.width || 0, | ||
height: zone?.height || 0, | ||
}); | ||
const imageUrl = getSvgUrlFromCurrentUrl(); | ||
|
||
useEffect(() => { | ||
if (!zone) return; | ||
|
||
const img = new Image(); | ||
img.width = ZONES_CONTAINER_WIDTH; | ||
img.src = imageUrl; | ||
|
||
img.onload = () => { | ||
// add extra padding if value are valid (not smaller than 0 and bigger than image height | ||
|
||
const paddingWidthToAdd = Math.max( | ||
0, | ||
Math.min(screenshotPadding, (img.width - zoneDim.width) / 2) | ||
); | ||
const paddingHeightToAdd = Math.max( | ||
0, | ||
Math.min(screenshotPadding, (img.height - zoneDim.height) / 2) | ||
); | ||
|
||
setZoneDim({ | ||
x: zone.x - paddingWidthToAdd, | ||
y: zone.y - paddingHeightToAdd, | ||
width: zone.width + paddingWidthToAdd * 2, | ||
height: zone.height + paddingHeightToAdd * 2, | ||
}); | ||
}; | ||
}, [zone]); | ||
if (!zone) return <div />; | ||
|
||
console.log("zoneDim", zoneDim); | ||
return ( | ||
<Box py={2}> | ||
<ChakraImage | ||
border="1px solid lightgray" | ||
objectFit="contain" | ||
src={`//images.weserv.nl/?url=${imageUrl}&w=${ZONES_CONTAINER_WIDTH}&cx=${zoneDim.x}&cy=${zoneDim.y}&cw=${zoneDim.width}&ch=${zoneDim.height}`} | ||
height="80px" /* fallbackSrc="/assets/placeholder.gif" */ | ||
/> | ||
</Box> | ||
); | ||
}; | ||
|
||
// return { ZoneScreenshot }; | ||
// }; | ||
export default ZoneScreenshot; |
Oops, something went wrong.