Skip to content

Commit 797356f

Browse files
Francisca105nalves599
authored andcommitted
add zoomToElement feature
1 parent 2923094 commit 797356f

File tree

2 files changed

+71
-49
lines changed

2 files changed

+71
-49
lines changed

src/app/(authenticated)/venue/VenueStands.tsx

+66-48
Original file line numberDiff line numberDiff line change
@@ -141,59 +141,77 @@ const VenueStands: React.FC<VenueStandsProps> = ({ companies }) => {
141141
centerZoomedOut={true}
142142
centerOnInit={true}
143143
>
144-
{({ zoomIn, zoomOut, resetTransform, ...rest }) => (
145-
<React.Fragment>
146-
<div className="absolute top-4 right-4 flex flex-col gap-2 z-10">
147-
<button
148-
onClick={() => zoomIn()}
149-
className="button button-primary !bg-sinfo-primary flex-1 p-2 rounded hover:opacity-90 transition-opacity"
150-
>
151-
+
152-
</button>
153-
<button
154-
onClick={() => zoomOut()}
155-
className="button button-primary !bg-sinfo-primary flex-1 p-2 rounded hover:opacity-90 transition-opacity"
156-
>
157-
-
158-
</button>
159-
{/* <button
144+
{({ zoomIn, zoomOut, resetTransform, zoomToElement, ...rest }) => {
145+
useEffect(() => {
146+
setTimeout(() => {
147+
if (companyParam) {
148+
let element = document.getElementById(
149+
`company-${companyParam}`
150+
);
151+
if (element) {
152+
console.log("Zooming to element", element);
153+
zoomToElement(`company-${companyParam}`, 3);
154+
}
155+
}
156+
}, 300); // Wait for the SVG to render
157+
}, [companyParam]);
158+
159+
return (
160+
<>
161+
<React.Fragment>
162+
<div className="absolute top-4 right-4 flex flex-col gap-2 z-10">
163+
<button
164+
onClick={() => zoomIn()}
165+
className="button button-primary !bg-sinfo-primary flex-1 p-2 rounded hover:opacity-90 transition-opacity"
166+
>
167+
+
168+
</button>
169+
<button
170+
onClick={() => zoomOut()}
171+
className="button button-primary !bg-sinfo-primary flex-1 p-2 rounded hover:opacity-90 transition-opacity"
172+
>
173+
-
174+
</button>
175+
{/* <button
160176
onClick={() => resetTransform()}
161177
className="button button-primary !bg-sinfo-secondary flex-1 p-2 rounded hover:opacity-90 transition-opacity"
162178
>
163179
Reset
164180
</button> */}
165-
</div>
166-
<div className="relative overflow-hidden border border-gray-300 rounded">
167-
<TransformComponent>
168-
<svg
169-
viewBox="0 0 512 380"
170-
className="w-full h-auto max-w-4xl mx-auto"
171-
>
172-
<Entrances />
173-
<SessionsStands />
174-
<FoodZone />
175-
<CoworkingZone />
176-
177-
{/* Company Stands */}
178-
<g id="stands">
179-
{standsForSelectedDay.map((stand) => {
180-
const company = getCompanyAtPosition(stand.standId);
181-
return (
182-
<CompanyStand
183-
key={`stand-${stand.standId}`}
184-
stand={stand}
185-
company={company}
186-
standPositions={standPositions}
187-
isSelected={isStandHighlighted(company)}
188-
/>
189-
);
190-
})}
191-
</g>
192-
</svg>
193-
</TransformComponent>
194-
</div>
195-
</React.Fragment>
196-
)}
181+
</div>
182+
<div className="relative overflow-hidden border border-gray-300 rounded">
183+
<TransformComponent>
184+
<svg
185+
viewBox="0 0 512 380"
186+
className="w-full h-auto max-w-4xl mx-auto"
187+
>
188+
<Entrances />
189+
<SessionsStands />
190+
<FoodZone />
191+
<CoworkingZone />
192+
193+
{/* Company Stands */}
194+
<g id="stands">
195+
{standsForSelectedDay.map((stand) => {
196+
const company = getCompanyAtPosition(stand.standId);
197+
return (
198+
<CompanyStand
199+
key={`stand-${stand.standId}`}
200+
stand={stand}
201+
company={company}
202+
standPositions={standPositions}
203+
isSelected={isStandHighlighted(company)}
204+
/>
205+
);
206+
})}
207+
</g>
208+
</svg>
209+
</TransformComponent>
210+
</div>
211+
</React.Fragment>
212+
</>
213+
);
214+
}}
197215
</TransformWrapper>
198216
</div>
199217
</div>

src/app/(authenticated)/venue/stands/CompanyStand.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ const CompanyStand: React.FC<StandProps> = ({
2323
if (!position) return null;
2424

2525
return (
26-
<a href={company ? `/companies/${company.id}` : "#"} className={className}>
26+
<a
27+
href={company ? `/companies/${company.id}` : "#"}
28+
className={className}
29+
id={company?.id ? `company-${company?.id}` : `stand-${standNumber}`}
30+
>
2731
<g
2832
className={`
2933
transition-all duration-200 ease-in-out

0 commit comments

Comments
 (0)