@@ -16,6 +16,10 @@ import {
1616import { EnqueueKind } from '@/pythonTypes' ;
1717
1818import { InboxCardContext , useInboxCardContext } from '../cards/inboxCard' ;
19+ import {
20+ FileUploadContextType ,
21+ useFileUploadContext ,
22+ } from '../fileUpload/context' ;
1923import {
2024 FolderSelectionContext ,
2125 useFolderSelectionContext ,
@@ -26,13 +30,15 @@ export function useActionMutation(action: Action) {
2630 const selectionContext = useFolderSelectionContext ( ) ;
2731 const inboxContext = useInboxCardContext ( ) ;
2832 const terminalContext = useTerminalContext ( ) ;
33+ const uploadContext = useFileUploadContext ( ) ;
2934 const navigate = useNavigate ( ) ;
3035
3136 const [ options , mutationArgs ] = actionMutationOptionsAndArgs (
3237 action ,
3338 socket ,
3439 selectionContext ,
3540 inboxContext ,
41+ uploadContext ,
3642 terminalContext ,
3743 navigate
3844 ) ;
@@ -56,6 +62,7 @@ function actionMutationOptionsAndArgs<T = unknown>(
5662 socket : StatusSocket | null ,
5763 selectionContext : FolderSelectionContext ,
5864 inboxContext : InboxCardContext ,
65+ uploadContext : FileUploadContextType ,
5966 terminalContext : TerminalContextI ,
6067 navigate : UseNavigateResult < string >
6168) : [ UseMutationOptions < unknown , APIError , T > , T ] {
@@ -157,6 +164,15 @@ function actionMutationOptionsAndArgs<T = unknown>(
157164 escape : options ?. escape ?? true , // default to escaping paths
158165 } as T ,
159166 ] ;
167+ case 'upload' :
168+ return [
169+ uploadDialogMutationOptions as UseMutationOptions <
170+ unknown ,
171+ APIError ,
172+ T
173+ > ,
174+ { ...uploadContext , inboxFolder : inboxContext . folder } as T ,
175+ ] ;
160176 case 'import_terminal' :
161177 return [
162178 importTerminalMutationOptions as UseMutationOptions <
@@ -211,6 +227,22 @@ const copyPathMutationOptions: UseMutationOptions<
211227 } ,
212228} ;
213229
230+ const uploadDialogMutationOptions : UseMutationOptions <
231+ unknown ,
232+ APIError ,
233+ FileUploadContextType & { inboxFolder : InboxCardContext [ 'folder' ] }
234+ > = {
235+ // eslint-disable-next-line @typescript-eslint/require-await
236+ mutationFn : async ( { setUploadTargetDir, setOpenDialog, inboxFolder } ) => {
237+ // keep the suggested name consistent with the one used in dropzone
238+ setUploadTargetDir (
239+ inboxFolder . full_path +
240+ `/upload_${ formatDate ( new Date ( ) , '%Y%m%d_%H%M%S' ) } `
241+ ) ;
242+ setOpenDialog ( true ) ;
243+ } ,
244+ } ;
245+
214246function _escapePathForBash ( path : string ) {
215247 // escaping path is fishy, but this seems to be the best compromise
216248 // https://stackoverflow.com/questions/1779858/how-do-i-escape-a-string-for-a-shell-command-in-node
0 commit comments