Skip to content

Commit 2923094

Browse files
Francisca105nalves599
authored andcommitted
Refactor zoom and pan functionality to VenueStands component
1 parent cd1be45 commit 2923094

File tree

5 files changed

+68
-180
lines changed

5 files changed

+68
-180
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"react-qr-code": "^2.0.12",
3333
"react-social-icons": "^6.18.0",
3434
"react-use": "^17.6.0",
35+
"react-zoom-pan-pinch": "^3.7.0",
3536
"sharp": "^0.33.5",
3637
"tailwindcss": "3.4.17",
3738
"typescript": "5.1.6"

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

Lines changed: 62 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import React, { useState, useEffect, useMemo } from "react";
44
import { useSearchParams, usePathname, useRouter } from "next/navigation";
5+
import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch";
56
import EventDayButton from "@/components/EventDayButton";
67
import GridList from "@/components/GridList";
7-
import ZoomSvg from "@/components/svg/ZoomableSvg";
88
import CompanyStand from "./stands/CompanyStand";
99
import Entrances from "./stands/Entrances";
1010
import CoworkingZone from "./stands/CoworkingZone";
@@ -135,30 +135,67 @@ const VenueStands: React.FC<VenueStandsProps> = ({ companies }) => {
135135
))}
136136
</GridList>
137137

138-
<ZoomSvg minZoom={0.6}>
139-
<svg viewBox="0 0 512 380" className="w-full h-auto max-w-4xl mx-auto">
140-
<Entrances />
141-
<SessionsStands />
142-
<FoodZone />
143-
<CoworkingZone />
144-
145-
{/* Company Stands */}
146-
<g id="stands">
147-
{standsForSelectedDay.map((stand) => {
148-
const company = getCompanyAtPosition(stand.standId);
149-
return (
150-
<CompanyStand
151-
key={`stand-${stand.standId}`}
152-
stand={stand}
153-
company={company}
154-
standPositions={standPositions}
155-
isSelected={isStandHighlighted(company)}
156-
/>
157-
);
158-
})}
159-
</g>
160-
</svg>
161-
</ZoomSvg>
138+
<div className="relative w-full">
139+
<TransformWrapper
140+
initialScale={1}
141+
centerZoomedOut={true}
142+
centerOnInit={true}
143+
>
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
160+
onClick={() => resetTransform()}
161+
className="button button-primary !bg-sinfo-secondary flex-1 p-2 rounded hover:opacity-90 transition-opacity"
162+
>
163+
Reset
164+
</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+
)}
197+
</TransformWrapper>
198+
</div>
162199
</div>
163200
);
164201
};

src/components/svg/ZoomableSvg.tsx

Lines changed: 0 additions & 154 deletions
This file was deleted.

src/components/svg/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3116,6 +3116,11 @@ react-use@^17.6.0:
31163116
ts-easing "^0.2.0"
31173117
tslib "^2.1.0"
31183118

3119+
react-zoom-pan-pinch@^3.7.0:
3120+
version "3.7.0"
3121+
resolved "https://registry.yarnpkg.com/react-zoom-pan-pinch/-/react-zoom-pan-pinch-3.7.0.tgz#7db4d2ec49c316eb20f71c56e9012eeb3ef4b504"
3122+
integrity sha512-UmReVZ0TxlKzxSbYiAj+LeGRW8s8LraAFTXRAxzMYnNRgGPsxCudwZKVkjvGmjtx7SW/hZamt69NUmGf4xrkXA==
3123+
31193124
31203125
version "18.2.0"
31213126
resolved "https://registry.yarnpkg.com/react/-/react-18.2.0.tgz#555bd98592883255fa00de14f1151a917b5d77d5"

0 commit comments

Comments
 (0)