11import { Excalidraw } from "@excalidraw/excalidraw" ;
22import { type ExcalidrawElement } from "@excalidraw/excalidraw/types/element/types" ;
3- import { useMutation , useQuery } from "@tanstack/react-query" ;
3+ import { useMutation } from "@tanstack/react-query" ;
44import { t } from "i18next" ;
55import { navigate } from "raviger" ;
66import { useEffect , useState } from "react" ;
@@ -18,50 +18,24 @@ import { CreateFileResponse } from "@/components/Patient/models";
1818
1919import routes from "@/Utils/request/api" ;
2020import mutate from "@/Utils/request/mutate" ;
21- import query from "@/Utils/request/query" ;
2221
2322type Props = {
2423 associatingId : string ;
2524 fileType : string ;
26- drawingId ?: string ;
2725} ;
2826
29- export default function ExcalidrawPage ( {
30- associatingId,
31- drawingId,
32- fileType,
33- } : Props ) {
27+ export default function ExcalidrawEditor ( { associatingId, fileType } : Props ) {
3428 const [ elements , setElements ] = useState < readonly ExcalidrawElement [ ] | null > (
35- drawingId ? null : [ ] ,
29+ [ ] ,
3630 ) ;
3731 const [ name , setName ] = useState ( "" ) ;
38- const [ id , setId ] = useState ( drawingId ) ;
32+ const [ id , setId ] = useState ( "" ) ;
3933 const [ isDirty , setIsDirty ] = useState ( false ) ;
4034
41- const { data, isLoading } = useQuery ( {
42- queryKey : [ "file" , id ] ,
43- queryFn : query ( routes . retrieveUpload , {
44- pathParams : { id : id || "" } ,
45- } ) ,
46- enabled : ! ! id ,
47- } ) ;
48-
4935 useEffect ( ( ) => {
5036 setIsDirty ( ! ! elements ?. length ) ;
5137 } , [ elements ?. length ] ) ;
5238
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 ] ) ;
6539 const { mutateAsync : markUploadComplete , error : markUploadCompleteError } =
6640 useMutation ( {
6741 mutationFn : mutate ( routes . markUploadCompleted , {
@@ -78,24 +52,24 @@ export default function ExcalidrawPage({
7852
7953 const handleSave = async ( ) => {
8054 if ( ! name . trim ( ) ) {
81- toast . error ( "Please enter a name for the drawing." ) ;
55+ toast . error ( t ( "please_enter_a_name_for_the_drawing" ) ) ;
8256 return ;
8357 }
8458
8559 const obj = {
8660 type : "excalidraw" ,
8761 version : "2" ,
88- source : "https://care.ohc.network.com" ,
62+ source : window . location . origin ,
8963 elements : elements ,
9064 appState : { } ,
9165 files : { } ,
9266 } ;
9367
9468 try {
9569 const file = new File ( [ JSON . stringify ( obj ) ] , `${ name } .excalidraw` , {
96- type : "text/plain " ,
70+ type : "application/vnd.excalidraw " ,
9771 } ) ;
98- let signedUrl = data ?. read_signed_url || "" ;
72+ let signedUrl = "" ;
9973 let response : CreateFileResponse | null = null ;
10074 if ( ! id ) {
10175 response = await createUpload ( {
@@ -118,7 +92,7 @@ export default function ExcalidrawPage({
11892 } ) ;
11993
12094 if ( ! upload . ok ) {
121- toast . error ( "Error uploading file" ) ;
95+ toast . error ( t ( "error_uploading_file" ) ) ;
12296
12397 return ;
12498 }
@@ -131,12 +105,12 @@ export default function ExcalidrawPage({
131105 toast . success ( t ( "file_success__upload_complete" ) ) ;
132106 navigate ( `drawings/${ response ! . id } ` ) ;
133107 }
134- } catch ( error ) {
135- console . error ( "Error in Step 1 (createUpload):" , error ) ;
108+ } catch {
109+ toast . error ( t ( "error_in_createUpload" ) ) ;
136110 }
137111 } ;
138112
139- if ( isLoading || elements === null ) {
113+ if ( elements === null ) {
140114 return < Loading /> ;
141115 }
142116
@@ -151,7 +125,7 @@ export default function ExcalidrawPage({
151125 < Input
152126 type = "text"
153127 value = { name }
154- placeholder = "Enter the File Name"
128+ placeholder = { t ( "enter_the_file_name" ) }
155129 onChange = { ( e ) => setName ( e . target . value ) }
156130 />
157131 </ div >
@@ -175,7 +149,7 @@ export default function ExcalidrawPage({
175149 initialData = { {
176150 appState : { theme : "light" } ,
177151 } }
178- onChange = { debounce ( async ( elements ) => {
152+ onChange = { debounce ( ( elements ) => {
179153 setElements ( elements ) ;
180154 } , 100 ) }
181155 />
0 commit comments