@@ -14,10 +14,12 @@ import {
14
14
Tooltip ,
15
15
Tree ,
16
16
Typography ,
17
- theme
17
+ theme ,
18
+ Upload
18
19
} from 'antd' ;
19
20
import type { InputRef } from 'antd' ;
20
21
import type { TreeDataNode , TreeProps } from 'antd' ;
22
+ import type { UploadProps } from 'antd' ;
21
23
import {
22
24
AppstoreAddOutlined as MechanismAddOutlined ,
23
25
AppstoreOutlined as MechanismOutlined ,
@@ -348,7 +350,7 @@ const App: React.FC = () => {
348
350
if ( errorMessage ) {
349
351
setAlertErrorMessage ( 'Unable to load the list of modules: ' + errorMessage ) ;
350
352
setAlertErrorVisible ( true ) ;
351
- return
353
+ return ;
352
354
}
353
355
if ( array != null ) {
354
356
setModules ( array )
@@ -894,17 +896,65 @@ const App: React.FC = () => {
894
896
setOpenPopconfirm ( true ) ;
895
897
} ;
896
898
897
- const handleUploadClicked = ( ) => {
898
- messageApi . open ( {
899
- type : 'success' ,
900
- content : 'Not implemented yet .' ,
901
- } ) ;
899
+ const uploadProps : UploadProps = {
900
+ accept : commonStorage . UPLOAD_DOWNLOAD_FILE_EXTENSION ,
901
+ beforeUpload : ( file ) => {
902
+ const isBlocks = file . name . endsWith ( commonStorage . UPLOAD_DOWNLOAD_FILE_EXTENSION )
903
+ if ( ! isBlocks ) {
904
+ setAlertErrorMessage ( file . name + ' is not a blocks file' ) ;
905
+ setAlertErrorVisible ( true ) ;
906
+ return false ;
907
+ }
908
+ return isBlocks || Upload . LIST_IGNORE ;
909
+ } ,
910
+ onChange : ( info ) => {
911
+ } ,
912
+ customRequest : ( { file, onSuccess, onError } ) => {
913
+ const reader = new FileReader ( ) ;
914
+ reader . onload = ( event ) => {
915
+ const dataUrl = event . target . result ;
916
+ const uploadProjectName = commonStorage . makeUploadProjectName ( file . name , getProjectNames ( ) ) ;
917
+ storage . uploadProject (
918
+ uploadProjectName , dataUrl ,
919
+ ( success : boolean , errorMessage : string ) => {
920
+ if ( success ) {
921
+ onSuccess ( 'Upload successful' ) ;
922
+ afterListModulesSuccess . current = ( ) => {
923
+ const uploadProjectPath = commonStorage . makeProjectPath ( uploadProjectName ) ;
924
+ setCurrentModulePath ( uploadProjectPath ) ;
925
+ } ;
926
+ setTriggerListModules ( ! triggerListModules ) ;
927
+ } else {
928
+ onError ( errorMessage ) ;
929
+ setAlertErrorMessage ( 'Unable to upload the project' ) ;
930
+ setAlertErrorVisible ( true ) ;
931
+ }
932
+ } ) ;
933
+ } ;
934
+ reader . onerror = ( error ) => {
935
+ onError ( error ) ;
936
+ setAlertErrorMessage ( 'Unable to upload the project' ) ;
937
+ setAlertErrorVisible ( true ) ;
938
+ } ;
939
+ reader . readAsDataURL ( file ) ;
940
+ } ,
902
941
} ;
903
942
904
943
const handleDownloadClicked = ( ) => {
905
- messageApi . open ( {
906
- type : 'success' ,
907
- content : 'Not implemented yet .' ,
944
+ checkIfBlocksWereModified ( ( ) => {
945
+ storage . downloadProject (
946
+ currentModule . projectName ,
947
+ ( url : string | null , errorMessage : string ) => {
948
+ if ( errorMessage ) {
949
+ setAlertErrorMessage ( 'Unable to download the project: ' + errorMessage ) ;
950
+ setAlertErrorVisible ( true ) ;
951
+ return ;
952
+ }
953
+ const link = document . createElement ( 'a' ) ;
954
+ link . href = url ;
955
+ link . download = currentModule . projectName + commonStorage . UPLOAD_DOWNLOAD_FILE_EXTENSION ;
956
+ link . click ( ) ;
957
+ } ) ;
908
958
} ) ;
909
959
} ;
910
960
@@ -1083,16 +1133,20 @@ const App: React.FC = () => {
1083
1133
>
1084
1134
</ Button >
1085
1135
</ Tooltip >
1086
- < Tooltip title = "Upload" >
1087
- < Button
1088
- icon = { < UploadOutlined /> }
1089
- size = "small"
1090
- onClick = { handleUploadClicked }
1091
- style = { { color : 'white' } }
1136
+ < Tooltip title = "Upload Project" >
1137
+ < Upload
1138
+ { ...uploadProps }
1139
+ showUploadList = { false }
1092
1140
>
1093
- </ Button >
1141
+ < Button
1142
+ icon = { < UploadOutlined /> }
1143
+ size = "small"
1144
+ style = { { color : 'white' } }
1145
+ >
1146
+ </ Button >
1147
+ </ Upload >
1094
1148
</ Tooltip >
1095
- < Tooltip title = "Download" >
1149
+ < Tooltip title = "Download Project " >
1096
1150
< Button
1097
1151
icon = { < DownloadOutlined /> }
1098
1152
size = "small"
0 commit comments