Skip to content

Commit fd7fcd6

Browse files
authored
Merge pull request #66 from KeneNwogu/Ken/camera-fix
fix: camera initialization bug fix closes #66
2 parents 8fff9f7 + 45e04c0 commit fd7fcd6

File tree

3 files changed

+36
-26
lines changed

3 files changed

+36
-26
lines changed

LEADERBOARD.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# GitHub Leaderboard
32

43
🏆 **Welcome to the Official Leaderboard!** 🏆
@@ -18,5 +17,4 @@ A heartfelt **thank you** to all our fantastic contributors for their hard work
1817

1918
---
2019

21-
*Want to see your name on the leaderboard? Contribute to our project on [GitHub](https://github.com/mlsanigeria/speak-to-docs) and make an impact!*
22-
20+
_Want to see your name on the leaderboard? Contribute to our project on [GitHub](https://github.com/mlsanigeria/speak-to-docs) and make an impact!_

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ Watch our info session on how to get started with Hacktoberfest and contribute t
8888
We maintain a leaderboard to track your contributions and their impact on our projects. The more you contribute, the higher you'll climb on the leaderboard.
8989

9090
<!-- Section Start -->
91+
9192
### Top 10 Contributors
9293

9394
Thank you to all our fantastic contributors for their hard work and dedication! Here are our top 10 contributors:

src/app/scan-image/page.tsx

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,29 @@ import Link from "next/link";
66

77
export default function ScanImagePage() {
88
const videoRef = useRef<HTMLVideoElement>(null);
9+
const [isStarted, setIsStarted] = useState(false);
910
const [error, setError] = useState<string | null>(null);
10-
const [loading, setLoading] = useState(true);
11+
const [loading, setLoading] = useState(false);
1112

12-
useEffect(() => {
13-
const startCamera = async () => {
14-
try {
15-
const stream = await navigator.mediaDevices.getUserMedia({
16-
video: { facingMode: "environment" },
17-
});
18-
if (videoRef.current) {
19-
videoRef.current.srcObject = stream;
20-
setLoading(false);
21-
}
22-
} catch (err) {
23-
console.error("Camera access error:", err);
24-
setError("Unable to access camera. Please allow camera permissions.");
13+
const startCamera = async () => {
14+
try {
15+
setLoading(true);
16+
setIsStarted(true);
17+
const stream = await navigator.mediaDevices.getUserMedia({
18+
video: { facingMode: "environment" },
19+
});
20+
if (videoRef.current) {
21+
videoRef.current.srcObject = stream;
2522
setLoading(false);
2623
}
27-
};
24+
} catch (err) {
25+
console.error("Camera access error:", err);
26+
setError("Unable to access camera. Please allow camera permissions.");
27+
setLoading(false);
28+
}
29+
};
2830

31+
useEffect(() => {
2932
startCamera();
3033

3134
return () => {
@@ -60,16 +63,24 @@ export default function ScanImagePage() {
6063
{error ? (
6164
<p className="text-center text-sm text-red-400 px-4">{error}</p>
6265
) : loading ? (
63-
<p className="text-neutral-500 text-sm">Initializing camera...</p>
66+
<p className="w-full text-center text-neutral-500 text-sm">
67+
Initializing camera...
68+
</p>
6469
) : (
65-
<video
66-
ref={videoRef}
67-
autoPlay
68-
playsInline
69-
muted
70-
className="w-full h-full object-cover"
71-
/>
70+
""
7271
)}
72+
73+
<video
74+
ref={videoRef}
75+
autoPlay
76+
playsInline
77+
muted
78+
className={
79+
isStarted && !loading
80+
? "w-full h-full object-cover"
81+
: "absolute invisible left-[-100vw]"
82+
}
83+
/>
7384
</div>
7485

7586
{/* Footer */}

0 commit comments

Comments
 (0)