1
1
import { Excalidraw } from "@excalidraw/excalidraw" ;
2
2
import { type ExcalidrawElement } from "@excalidraw/excalidraw/types/element/types" ;
3
- import { useMutation , useQuery } from "@tanstack/react-query" ;
3
+ import { useMutation } from "@tanstack/react-query" ;
4
4
import { t } from "i18next" ;
5
5
import { navigate } from "raviger" ;
6
6
import { useEffect , useState } from "react" ;
@@ -18,50 +18,24 @@ import { CreateFileResponse } from "@/components/Patient/models";
18
18
19
19
import routes from "@/Utils/request/api" ;
20
20
import mutate from "@/Utils/request/mutate" ;
21
- import query from "@/Utils/request/query" ;
22
21
23
22
type Props = {
24
23
associatingId : string ;
25
24
fileType : string ;
26
- drawingId ?: string ;
27
25
} ;
28
26
29
- export default function ExcalidrawPage ( {
30
- associatingId,
31
- drawingId,
32
- fileType,
33
- } : Props ) {
27
+ export default function ExcalidrawEditor ( { associatingId, fileType } : Props ) {
34
28
const [ elements , setElements ] = useState < readonly ExcalidrawElement [ ] | null > (
35
- drawingId ? null : [ ] ,
29
+ [ ] ,
36
30
) ;
37
31
const [ name , setName ] = useState ( "" ) ;
38
- const [ id , setId ] = useState ( drawingId ) ;
32
+ const [ id , setId ] = useState ( "" ) ;
39
33
const [ isDirty , setIsDirty ] = useState ( false ) ;
40
34
41
- const { data, isLoading } = useQuery ( {
42
- queryKey : [ "file" , id ] ,
43
- queryFn : query ( routes . retrieveUpload , {
44
- pathParams : { id : id || "" } ,
45
- } ) ,
46
- enabled : ! ! id ,
47
- } ) ;
48
-
49
35
useEffect ( ( ) => {
50
36
setIsDirty ( ! ! elements ?. length ) ;
51
37
} , [ elements ?. length ] ) ;
52
38
53
- useEffect ( ( ) => {
54
- if ( ! data ) {
55
- return ;
56
- }
57
- setName ( data . name ! ) ;
58
- const fetchData = async ( ) => {
59
- const response = await fetch ( data . read_signed_url ! ) ;
60
- const json = await response . json ( ) ;
61
- setElements ( json . elements ) ;
62
- } ;
63
- fetchData ( ) ;
64
- } , [ data ] ) ;
65
39
const { mutateAsync : markUploadComplete , error : markUploadCompleteError } =
66
40
useMutation ( {
67
41
mutationFn : mutate ( routes . markUploadCompleted , {
@@ -78,24 +52,24 @@ export default function ExcalidrawPage({
78
52
79
53
const handleSave = async ( ) => {
80
54
if ( ! name . trim ( ) ) {
81
- toast . error ( "Please enter a name for the drawing." ) ;
55
+ toast . error ( t ( "please_enter_a_name_for_the_drawing" ) ) ;
82
56
return ;
83
57
}
84
58
85
59
const obj = {
86
60
type : "excalidraw" ,
87
61
version : "2" ,
88
- source : "https://care.ohc.network.com" ,
62
+ source : window . location . origin ,
89
63
elements : elements ,
90
64
appState : { } ,
91
65
files : { } ,
92
66
} ;
93
67
94
68
try {
95
69
const file = new File ( [ JSON . stringify ( obj ) ] , `${ name } .excalidraw` , {
96
- type : "text/plain " ,
70
+ type : "application/vnd.excalidraw " ,
97
71
} ) ;
98
- let signedUrl = data ?. read_signed_url || "" ;
72
+ let signedUrl = "" ;
99
73
let response : CreateFileResponse | null = null ;
100
74
if ( ! id ) {
101
75
response = await createUpload ( {
@@ -118,7 +92,7 @@ export default function ExcalidrawPage({
118
92
} ) ;
119
93
120
94
if ( ! upload . ok ) {
121
- toast . error ( "Error uploading file" ) ;
95
+ toast . error ( t ( "error_uploading_file" ) ) ;
122
96
123
97
return ;
124
98
}
@@ -131,12 +105,12 @@ export default function ExcalidrawPage({
131
105
toast . success ( t ( "file_success__upload_complete" ) ) ;
132
106
navigate ( `drawings/${ response ! . id } ` ) ;
133
107
}
134
- } catch ( error ) {
135
- console . error ( "Error in Step 1 (createUpload):" , error ) ;
108
+ } catch {
109
+ toast . error ( t ( "error_in_createUpload" ) ) ;
136
110
}
137
111
} ;
138
112
139
- if ( isLoading || elements === null ) {
113
+ if ( elements === null ) {
140
114
return < Loading /> ;
141
115
}
142
116
@@ -151,7 +125,7 @@ export default function ExcalidrawPage({
151
125
< Input
152
126
type = "text"
153
127
value = { name }
154
- placeholder = "Enter the File Name"
128
+ placeholder = { t ( "enter_the_file_name" ) }
155
129
onChange = { ( e ) => setName ( e . target . value ) }
156
130
/>
157
131
</ div >
@@ -175,7 +149,7 @@ export default function ExcalidrawPage({
175
149
initialData = { {
176
150
appState : { theme : "light" } ,
177
151
} }
178
- onChange = { debounce ( async ( elements ) => {
152
+ onChange = { debounce ( ( elements ) => {
179
153
setElements ( elements ) ;
180
154
} , 100 ) }
181
155
/>
0 commit comments