1
1
"use client"
2
2
3
3
import { Card , CardContent , CardHeader } from "./ui/card"
4
- import { useEffect , useRef , useState } from "react"
4
+ import { useEffect , useRef } from "react"
5
5
import { deletePictures } from "@/lib/send-detection/action"
6
6
7
7
import { UserView } from "@/lib/identity/definition"
@@ -12,34 +12,16 @@ import useHistory from "@/hooks/use-history"
12
12
import HistorySelect from "./history-select"
13
13
import ModelSelection from "./model-selection"
14
14
import ModelLoader from "./model-loader"
15
- import { ModelComputerVision , ModelList , modelList } from "@/models/model-list"
15
+ import { modelList } from "@/models/model-list"
16
16
import { detect } from "@/lib/yolov8n/detect"
17
17
import Image from "next/image"
18
- import { Popover , PopoverContent } from "@radix-ui/react-popover"
19
- import { PopoverTrigger } from "./ui/popover"
20
- import {
21
- Dialog ,
22
- DialogContent ,
23
- DialogDescription ,
24
- DialogHeader ,
25
- DialogTitle ,
26
- DialogTrigger ,
27
- } from "./ui/dialog"
28
- import { Badge } from "./ui/badge"
29
- import { BotIcon , PictureInPicture2Icon } from "lucide-react"
30
- import { Button } from "./ui/button"
31
18
32
19
interface IProps {
33
20
user : UserView
34
21
}
35
22
36
23
export default function History ( { user } : IProps ) {
37
- const ready = useTfjsBackendWeb ( { backend : "webgl" } )
38
- const { modelName } = useModelStore ( )
39
- const { model, loadModel, percentLoaded } = useModel ( { ready } )
40
24
const { pictures, setPictures, date, setDate } = useHistory ( { user } )
41
- const [ picture , setPicture ] = useState < string > ( "" )
42
- const canvasRef = useRef < HTMLCanvasElement > ( null )
43
25
44
26
async function handleDeleteAllSelection ( ) {
45
27
const confirmation = window . confirm (
@@ -53,51 +35,14 @@ export default function History({ user }: IProps) {
53
35
}
54
36
}
55
37
56
- function handleCreateCanvas ( ) {
57
- const img = new window . Image ( )
58
- img . crossOrigin = "anonymous"
59
- img . src = picture
60
- img . onload = async ( ) => {
61
- const canvas = canvasRef . current
62
- const context = canvas ?. getContext ( "2d" )
63
- if ( context ) {
64
- context . drawImage ( img , 0 , 0 , canvas . width , canvas . height )
65
- }
66
- }
67
- }
68
-
69
- async function handleRunDetection ( ) {
70
- const img = new window . Image ( )
71
- img . crossOrigin = "anonymous"
72
- img . src = picture
73
- img . onload = async ( ) => {
74
- const canvas = canvasRef . current
75
- const context = canvas ?. getContext ( "2d" )
76
- if ( context ) {
77
- detect ( img , model , canvas )
78
- }
79
- }
80
- }
81
-
82
38
return (
83
- < div className = "grid grid-cols-1 gap-4 lg:grid-cols-2 lg:gap-8" >
39
+ < div className = "grid grid-cols-1 gap-4 lg:grid-cols-2 lg:gap-8 mt-16 " >
84
40
< HistorySelect
85
41
date = { date }
86
42
setDate = { setDate }
87
43
pictures = { pictures }
88
44
handleDeleteAllSelection = { handleDeleteAllSelection }
89
- loadModel = { loadModel }
90
45
/>
91
- { loadModel ? (
92
- < ModelLoader
93
- percent = { percentLoaded }
94
- model = {
95
- modelList . find ( model => model . title === modelName ) as ModelList
96
- }
97
- />
98
- ) : (
99
- < ModelSelection />
100
- ) }
101
46
102
47
< Card className = "m-3 w-full lg:col-span-2 flex-grow bg-transparent border-none" >
103
48
< CardHeader className = "flex flex-row items-start bg-muted/50" >
@@ -134,50 +79,13 @@ export default function History({ user }: IProps) {
134
79
< div className = "grid grid-cols-1 gap-4 lg:grid-cols-2 lg:gap-8" >
135
80
{ pictures . map ( ( picture , index ) => (
136
81
< div key = { index } className = "relative" >
137
- < Dialog >
138
- < DialogTrigger >
139
- < Image
140
- src = { picture }
141
- alt = { "Image de la detection" }
142
- width = { 200 }
143
- height = { 200 }
144
- className = "rounded-lg w-full cursor-pointer"
145
- onClick = { ( ) => {
146
- setPicture ( picture )
147
- handleCreateCanvas ( )
148
- } }
149
- />
150
- </ DialogTrigger >
151
- < DialogContent className = "max-w-full max-h-full" >
152
- < DialogHeader className = "flex-row" >
153
- < DialogTitle className = "m-2" >
154
- < Badge variant = "default" >
155
- < PictureInPicture2Icon className = "mr-2 h-4 w-4" />
156
- < span className = "text-white" > { index + 1 } </ span >
157
- </ Badge >
158
- </ DialogTitle >
159
- < DialogDescription >
160
- < Button
161
- variant = "outline"
162
- className = "bg-blue-500 text-white hover:bg-blue-600 focus:bg-blue-700 active:bg-blue-800 hover:text-white focus:text-white active:text-white"
163
- onClick = { ( ) => {
164
- handleRunDetection ( )
165
- } } >
166
- < BotIcon className = "mr-2 h-4 w-4" />
167
- Lancer la reconnaissance
168
- </ Button >
169
- </ DialogDescription >
170
- </ DialogHeader >
171
- < div className = "flex justify-center" >
172
- < canvas
173
- ref = { canvasRef }
174
- width = { 640 }
175
- height = { 480 }
176
- className = "max-w-full max-h-full rounded-lg"
177
- />
178
- </ div >
179
- </ DialogContent >
180
- </ Dialog >
82
+ < Image
83
+ src = { picture }
84
+ alt = { "Image de la détection" }
85
+ width = { 300 }
86
+ height = { 300 }
87
+ className = "rounded-lg w-full cursor-pointer text-center transition duration-500"
88
+ />
181
89
</ div >
182
90
) ) }
183
91
</ div >
0 commit comments