Skip to content

Commit e33ecfe

Browse files
committed
fix: removed cam switching
1 parent 828ec6b commit e33ecfe

File tree

1 file changed

+9
-62
lines changed

1 file changed

+9
-62
lines changed

src/app/search/page.tsx

Lines changed: 9 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export default function ProductSearch() {
7878

7979
const debouncedQuery = useDebounce(query, 500); // Increased debounce delay
8080

81-
// Filter cameras to select exactly one back camera and one front camera
81+
// Filter cameras to select only back camera (prefer ultrawide if available)
8282
const filterCameras = async (devices: MediaDeviceInfo[]): Promise<MediaDeviceInfo[]> => {
8383
const backCameras: MediaDeviceInfo[] = [];
8484
const frontCameras: MediaDeviceInfo[] = [];
@@ -175,7 +175,7 @@ export default function ProductSearch() {
175175
}
176176
}
177177

178-
// Build final camera selection: exactly one back and one front camera
178+
// Build final camera selection: only one back camera
179179
const filtered: MediaDeviceInfo[] = [];
180180

181181
// Select the best back camera (prefer ultrawide if available, otherwise first back camera)
@@ -196,30 +196,20 @@ export default function ProductSearch() {
196196
selectedBackCamera = backCameras[0];
197197
}
198198

199-
// Select front camera
200-
let selectedFrontCamera: MediaDeviceInfo | null = null;
201-
if (frontCameras.length > 0) {
202-
selectedFrontCamera = frontCameras[0];
199+
// If no back camera available, fallback to front camera
200+
if (!selectedBackCamera && frontCameras.length > 0) {
201+
selectedBackCamera = frontCameras[0];
203202
}
204203

205-
// Add cameras to filtered array (back camera first for default)
204+
// Add selected camera to filtered array
206205
if (selectedBackCamera) {
207206
filtered.push(selectedBackCamera);
208207
}
209-
if (selectedFrontCamera) {
210-
filtered.push(selectedFrontCamera);
211-
}
212208

213209
// Mobile device fallback: if no cameras were categorized properly
214210
if (filtered.length === 0 && devices.length > 0) {
215-
if (devices.length >= 2) {
216-
// Assume first is back, second is front
217-
filtered.push(devices[0]); // Back camera (usually)
218-
filtered.push(devices[1]); // Front camera (usually)
219-
} else {
220-
// Only one camera available
221-
filtered.push(devices[0]);
222-
}
211+
// Use the first camera available (usually back camera on mobile)
212+
filtered.push(devices[0]);
223213
}
224214

225215
return filtered;
@@ -335,20 +325,6 @@ export default function ProductSearch() {
335325
};
336326
}, []);
337327

338-
const flipCamera = () => {
339-
if (filteredCameras.length > 1) {
340-
// Stop current camera before switching
341-
if (cameraControlsRef.current) {
342-
cameraControlsRef.current.stop();
343-
cameraControlsRef.current = null;
344-
}
345-
346-
setCurrentCameraIndex((prevIndex) =>
347-
(prevIndex + 1) % filteredCameras.length
348-
);
349-
}
350-
};
351-
352328
const handleManualSearch = () => {
353329
handleSearch(query);
354330
};
@@ -471,7 +447,7 @@ export default function ProductSearch() {
471447
>
472448
Scan a Barcode
473449
</h1>
474-
<div className="relative">
450+
<div>
475451
<div
476452
className="rounded-lg overflow-hidden shadow-xl mb-4 w-full max-w-xs flex items-center justify-center aspect-video"
477453
style={{
@@ -481,35 +457,6 @@ export default function ProductSearch() {
481457
>
482458
<video ref={videoRef} className="w-full h-auto" />
483459
</div>
484-
{/* Flip Camera Button */}
485-
{filteredCameras.length > 1 && (
486-
<button
487-
onClick={flipCamera}
488-
className="absolute top-2 right-2 p-2 rounded-full shadow-lg transition-all duration-200 hover:scale-110 active:scale-95"
489-
style={{
490-
backgroundColor: colours.content.surface,
491-
border: `1px solid ${colours.card.border}`,
492-
color: colours.text.primary
493-
}}
494-
title="Flip Camera"
495-
>
496-
<svg
497-
width="20"
498-
height="20"
499-
viewBox="0 0 24 24"
500-
fill="none"
501-
stroke="currentColor"
502-
strokeWidth="2"
503-
strokeLinecap="round"
504-
strokeLinejoin="round"
505-
>
506-
<path d="M3 6h4l2-2h6l2 2h4a1 1 0 0 1 1 1v11a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1z"/>
507-
<circle cx="12" cy="13" r="3"/>
508-
<path d="M16 6l2-2"/>
509-
<path d="M16 6l-2-2"/>
510-
</svg>
511-
</button>
512-
)}
513460
</div>
514461
</div>
515462
</ContentBox>

0 commit comments

Comments
 (0)