@@ -13,7 +13,9 @@ import {
13
13
GITHUB_SAVE_FILE_AS ,
14
14
GITHUB_CREATE_FILE ,
15
15
GITHUB_DELETE_FILE ,
16
- GITHUB_DELETE_FOLDER
16
+ GITHUB_DELETE_FOLDER ,
17
+ GITHUB_RENAME_FILE ,
18
+ GITHUB_RENAME_FOLDER ,
17
19
} from '../../features/github/GitHubTypes' ;
18
20
import * as GitHubUtils from '../../features/github/GitHubUtils' ;
19
21
import { getGitHubOctokitInstance } from '../../features/github/GitHubUtils' ;
@@ -32,14 +34,15 @@ import { EditorTabState } from '../workspace/WorkspaceTypes';
32
34
export function * GitHubPersistenceSaga ( ) : SagaIterator {
33
35
yield takeLatest ( LOGIN_GITHUB , githubLoginSaga ) ;
34
36
yield takeLatest ( LOGOUT_GITHUB , githubLogoutSaga ) ;
35
-
36
37
yield takeLatest ( GITHUB_OPEN_FILE , githubOpenFile ) ;
37
38
yield takeLatest ( GITHUB_SAVE_FILE , githubSaveFile ) ;
38
39
yield takeLatest ( GITHUB_SAVE_FILE_AS , githubSaveFileAs ) ;
39
40
yield takeLatest ( GITHUB_SAVE_ALL , githubSaveAll ) ;
40
41
yield takeLatest ( GITHUB_CREATE_FILE , githubCreateFile ) ;
41
42
yield takeLatest ( GITHUB_DELETE_FILE , githubDeleteFile ) ;
42
43
yield takeLatest ( GITHUB_DELETE_FOLDER , githubDeleteFolder ) ;
44
+ yield takeLatest ( GITHUB_RENAME_FILE , githubRenameFile ) ;
45
+ yield takeLatest ( GITHUB_RENAME_FOLDER , githubRenameFolder ) ;
43
46
}
44
47
45
48
function * githubLoginSaga ( ) {
@@ -308,13 +311,12 @@ function* githubDeleteFile({ payload }: ReturnType<typeof actions.githubDeleteFi
308
311
const authUser : GetAuthenticatedResponse = yield call ( octokit . users . getAuthenticated ) ;
309
312
310
313
const githubLoginId = authUser . data . login ;
311
- const githubSaveInfo = getGithubSaveInfo ( ) ;
312
- const repoName = githubSaveInfo . repoName ;
313
- const lastSaved = githubSaveInfo . lastSaved ;
314
+ const repoName = getGithubSaveInfo ( ) . repoName ;
314
315
const githubEmail = authUser . data . email ;
315
316
const githubName = authUser . data . name ;
316
317
const commitMessage = 'Changes made from Source Academy' ;
317
318
319
+
318
320
if ( repoName === '' ) {
319
321
yield call ( console . log , "not synced to github" ) ;
320
322
return ;
@@ -329,14 +331,6 @@ function* githubDeleteFile({ payload }: ReturnType<typeof actions.githubDeleteFi
329
331
githubName ,
330
332
commitMessage ,
331
333
) ;
332
-
333
- const persistenceFileArray = store . getState ( ) . fileSystem . persistenceFileArray ;
334
- const persistenceFile = persistenceFileArray . find ( e =>
335
- e . repoName === repoName &&
336
- e . path === filePath &&
337
- e . lastSaved === lastSaved ) || { id : '' , name : '' } ;
338
- store . dispatch ( actions . deleteGithubSaveInfo ( persistenceFile ) ) ;
339
-
340
334
341
335
yield call ( store . dispatch , actions . enableFileSystemContextMenus ( ) ) ;
342
336
yield call ( store . dispatch , actions . updateRefreshFileViewKey ( ) ) ;
@@ -375,7 +369,89 @@ function* githubDeleteFolder({ payload }: ReturnType<typeof actions.githubDelete
375
369
githubName ,
376
370
commitMessage
377
371
) ;
378
-
372
+
373
+ yield call ( store . dispatch , actions . enableFileSystemContextMenus ( ) ) ;
374
+ yield call ( store . dispatch , actions . updateRefreshFileViewKey ( ) ) ;
375
+ }
376
+
377
+ function * githubRenameFile ( { payload } : ReturnType < typeof actions . githubRenameFile > ) : any {
378
+ yield call ( store . dispatch , actions . disableFileSystemContextMenus ( ) ) ;
379
+
380
+ const newFilePath = payload . newFilePath ;
381
+ const oldFilePath = payload . oldFilePath ;
382
+
383
+ const octokit = getGitHubOctokitInstance ( ) ;
384
+ if ( octokit === undefined ) return ;
385
+
386
+ type GetAuthenticatedResponse = GetResponseTypeFromEndpointMethod <
387
+ typeof octokit . users . getAuthenticated
388
+ > ;
389
+ const authUser : GetAuthenticatedResponse = yield call ( octokit . users . getAuthenticated ) ;
390
+
391
+ const githubLoginId = authUser . data . login ;
392
+ const githubSaveInfo = getGithubSaveInfo ( ) ;
393
+ const repoName = githubSaveInfo . repoName ;
394
+ const githubEmail = authUser . data . email ;
395
+ const githubName = authUser . data . name ;
396
+ const commitMessage = 'Changes made from Source Academy' ;
397
+
398
+ if ( repoName === '' || repoName === undefined ) {
399
+ yield call ( console . log , "not synced to github" ) ;
400
+ return ;
401
+ }
402
+
403
+ GitHubUtils . performFileRenaming (
404
+ octokit ,
405
+ githubLoginId ,
406
+ repoName ,
407
+ oldFilePath . slice ( 12 ) ,
408
+ githubName ,
409
+ githubEmail ,
410
+ commitMessage ,
411
+ newFilePath . slice ( 12 )
412
+ )
413
+
414
+ yield call ( store . dispatch , actions . enableFileSystemContextMenus ( ) ) ;
415
+ yield call ( store . dispatch , actions . updateRefreshFileViewKey ( ) ) ;
416
+ }
417
+
418
+ function * githubRenameFolder ( { payload } : ReturnType < typeof actions . githubRenameFile > ) : any {
419
+ yield call ( store . dispatch , actions . disableFileSystemContextMenus ( ) ) ;
420
+
421
+ const newFilePath = payload . newFilePath ;
422
+ const oldFilePath = payload . oldFilePath ;
423
+
424
+ const octokit = getGitHubOctokitInstance ( ) ;
425
+ if ( octokit === undefined ) return ;
426
+
427
+ type GetAuthenticatedResponse = GetResponseTypeFromEndpointMethod <
428
+ typeof octokit . users . getAuthenticated
429
+ > ;
430
+ const authUser : GetAuthenticatedResponse = yield call ( octokit . users . getAuthenticated ) ;
431
+
432
+ const githubLoginId = authUser . data . login ;
433
+ const githubSaveInfo = getGithubSaveInfo ( ) ;
434
+ const repoName = githubSaveInfo . repoName ;
435
+ const githubEmail = authUser . data . email ;
436
+ const githubName = authUser . data . name ;
437
+ const commitMessage = 'Changes made from Source Academy' ;
438
+
439
+ if ( repoName === '' || repoName === undefined ) {
440
+ yield call ( console . log , "not synced to github" ) ;
441
+ return ;
442
+ }
443
+
444
+ GitHubUtils . performFolderRenaming (
445
+ octokit ,
446
+ githubLoginId ,
447
+ repoName ,
448
+ oldFilePath . slice ( 12 ) ,
449
+ githubName ,
450
+ githubEmail ,
451
+ commitMessage ,
452
+ newFilePath . slice ( 12 )
453
+ )
454
+
379
455
yield call ( store . dispatch , actions . enableFileSystemContextMenus ( ) ) ;
380
456
yield call ( store . dispatch , actions . updateRefreshFileViewKey ( ) ) ;
381
457
}
0 commit comments