1
1
'use client' ;
2
2
3
3
import * as React from 'react' ;
4
+ import Link from 'next/link' ;
4
5
5
6
import { analyzeFoodImageAction } from '~/app/analyze/actions' ;
6
7
import { Header } from '~/components/header' ;
7
8
import { Icons } from '~/components/icons' ;
9
+ import {
10
+ AlertDialog ,
11
+ AlertDialogAction ,
12
+ AlertDialogCancel ,
13
+ AlertDialogContent ,
14
+ AlertDialogDescription ,
15
+ AlertDialogFooter ,
16
+ AlertDialogHeader ,
17
+ AlertDialogTitle ,
18
+ } from '~/components/ui/alert-dialog' ;
8
19
import { Button } from '~/components/ui/button' ;
9
20
import {
10
21
Sheet ,
@@ -23,7 +34,10 @@ export default function AnalyzePage() {
23
34
const [ result , setResult ] = React . useState < FoodAnalyzeResult | null > ( null ) ;
24
35
const [ isPending , startTransition ] = React . useTransition ( ) ;
25
36
26
- const videoElementRef = useVideoStream ( ) ;
37
+ const [
38
+ videoElementRef ,
39
+ { error : videoStreamError , retry : retryVideoStream } ,
40
+ ] = useVideoStream ( ) ;
27
41
const [
28
42
canvasElementRef ,
29
43
{ drawImageToCanvas, getImageFromCanvas, clearCanvas } ,
@@ -73,7 +87,7 @@ export default function AnalyzePage() {
73
87
< div className = "relative flex-1" >
74
88
< video
75
89
ref = { videoElementRef }
76
- className = "absolute inset-0 h-full w-full flex-1 rounded-lg border object-cover"
90
+ className = "absolute inset-0 h-full w-full flex-1 rounded-lg border bg-muted object-cover"
77
91
autoPlay
78
92
muted
79
93
/>
@@ -120,6 +134,28 @@ export default function AnalyzePage() {
120
134
</ div >
121
135
</ SheetContent >
122
136
</ Sheet >
137
+
138
+ < AlertDialog open = { videoStreamError !== null } >
139
+ < AlertDialogContent >
140
+ < AlertDialogHeader >
141
+ < AlertDialogTitle >
142
+ Failed to Access Device Camera!
143
+ </ AlertDialogTitle >
144
+ < AlertDialogDescription >
145
+ Please make sure you have granted access to your device camera
146
+ and try again
147
+ </ AlertDialogDescription >
148
+ </ AlertDialogHeader >
149
+ < AlertDialogFooter >
150
+ < AlertDialogCancel asChild >
151
+ < Link href = "/" > Back</ Link >
152
+ </ AlertDialogCancel >
153
+ < AlertDialogAction onClick = { retryVideoStream } >
154
+ Try again
155
+ </ AlertDialogAction >
156
+ </ AlertDialogFooter >
157
+ </ AlertDialogContent >
158
+ </ AlertDialog >
123
159
</ div >
124
160
</ main >
125
161
) ;
0 commit comments