@@ -27,13 +27,15 @@ export const FileSystemReducer: Reducer<FileSystemState, SourceActionType> = cre
27
27
. addCase ( setInBrowserFileSystem , ( state , action ) => {
28
28
state . inBrowserFileSystem = action . payload . inBrowserFileSystem ;
29
29
} )
30
- . addCase ( addGithubSaveInfo , ( state , action ) => { // TODO rewrite
30
+ . addCase ( addGithubSaveInfo , ( state , action ) => {
31
+ // TODO rewrite
31
32
const persistenceFilePayload = action . payload . persistenceFile ;
32
33
const persistenceFileArray = state [ 'persistenceFileArray' ] ;
33
34
34
35
const saveInfoIndex = persistenceFileArray . findIndex ( e => {
35
- return e . path === persistenceFilePayload . path &&
36
- e . repoName === persistenceFilePayload . repoName ;
36
+ return (
37
+ e . path === persistenceFilePayload . path && e . repoName === persistenceFilePayload . repoName
38
+ ) ;
37
39
} ) ;
38
40
if ( saveInfoIndex === - 1 ) {
39
41
persistenceFileArray [ persistenceFileArray . length ] = {
@@ -56,87 +58,104 @@ export const FileSystemReducer: Reducer<FileSystemState, SourceActionType> = cre
56
58
} ;
57
59
}
58
60
state . persistenceFileArray = persistenceFileArray ;
59
- } )
60
- . addCase ( deleteGithubSaveInfo , ( state , action ) => { // TODO rewrite - refer to deletePersistenceFile below
61
- const newPersistenceFileArray = state [ 'persistenceFileArray' ] . filter ( e => e . path !== action . payload . path ) ;
62
- const isGDriveSyncing = action . payload . id ? true : false ;
63
- if ( isGDriveSyncing ) {
64
- const newPersFile = {
65
- id : action . payload . id ,
66
- name : action . payload . name ,
67
- lastEdit : action . payload . lastEdit ,
68
- lastSaved : action . payload . lastSaved ,
69
- parentId : action . payload . parentId ,
70
- path : action . payload . path
71
- } ;
72
- const newPersFileArray = newPersistenceFileArray . concat ( newPersFile ) ;
73
- state . persistenceFileArray = newPersFileArray ;
74
- } else {
75
- state . persistenceFileArray = newPersistenceFileArray ;
76
- }
77
- } )
78
- . addCase ( deleteAllGithubSaveInfo , ( state , action ) => {
79
- if ( state . persistenceFileArray . length !== 0 ) {
80
- const isGDriveSyncing = state . persistenceFileArray [ 0 ] . id ? true : false ;
81
- const newPersistenceFileArray = state . persistenceFileArray ;
61
+ } )
62
+ . addCase ( deleteGithubSaveInfo , ( state , action ) => {
63
+ // TODO rewrite - refer to deletePersistenceFile below
64
+ const newPersistenceFileArray = state [ 'persistenceFileArray' ] . filter (
65
+ e => e . path !== action . payload . path
66
+ ) ;
67
+ const isGDriveSyncing = action . payload . id ? true : false ;
82
68
if ( isGDriveSyncing ) {
83
- newPersistenceFileArray . forEach (
84
- ( persistenceFile , index ) => {
69
+ const newPersFile = {
70
+ id : action . payload . id ,
71
+ name : action . payload . name ,
72
+ lastEdit : action . payload . lastEdit ,
73
+ lastSaved : action . payload . lastSaved ,
74
+ parentId : action . payload . parentId ,
75
+ path : action . payload . path
76
+ } ;
77
+ const newPersFileArray = newPersistenceFileArray . concat ( newPersFile ) ;
78
+ state . persistenceFileArray = newPersFileArray ;
79
+ } else {
80
+ state . persistenceFileArray = newPersistenceFileArray ;
81
+ }
82
+ } )
83
+ . addCase ( deleteAllGithubSaveInfo , ( state , action ) => {
84
+ if ( state . persistenceFileArray . length !== 0 ) {
85
+ const isGDriveSyncing = state . persistenceFileArray [ 0 ] . id ? true : false ;
86
+ const newPersistenceFileArray = state . persistenceFileArray ;
87
+ if ( isGDriveSyncing ) {
88
+ newPersistenceFileArray . forEach ( ( persistenceFile , index ) => {
85
89
newPersistenceFileArray [ index ] = {
86
90
id : persistenceFile . id ,
87
91
name : persistenceFile . name ,
88
92
lastEdit : persistenceFile . lastEdit ,
89
93
lastSaved : persistenceFile . lastSaved ,
90
94
parentId : persistenceFile . parentId ,
91
95
path : persistenceFile . path
92
- }
93
- }
94
- )
95
- state . persistenceFileArray = newPersistenceFileArray ;
96
+ } ;
97
+ } ) ;
98
+ state . persistenceFileArray = newPersistenceFileArray ;
99
+ } else {
100
+ state . persistenceFileArray = [ ] ;
101
+ }
102
+ }
103
+ } )
104
+ . addCase ( addPersistenceFile , ( state , action ) => {
105
+ // TODO rewrite
106
+ const persistenceFilePayload = action . payload ;
107
+ const persistenceFileArray = state [ 'persistenceFileArray' ] ;
108
+ const persistenceFileIndex = persistenceFileArray . findIndex (
109
+ e => e . id === persistenceFilePayload . id
110
+ ) ;
111
+ if ( persistenceFileIndex === - 1 ) {
112
+ persistenceFileArray [ persistenceFileArray . length ] = persistenceFilePayload ;
96
113
} else {
97
- state . persistenceFileArray = [ ] ;
114
+ persistenceFileArray [ persistenceFileIndex ] = persistenceFilePayload ;
98
115
}
99
- }
100
- } )
101
- . addCase ( addPersistenceFile , ( state , action ) => { // TODO rewrite
102
- const persistenceFilePayload = action . payload ;
103
- const persistenceFileArray = state [ 'persistenceFileArray' ] ;
104
- const persistenceFileIndex = persistenceFileArray . findIndex ( e => e . id === persistenceFilePayload . id ) ;
105
- if ( persistenceFileIndex === - 1 ) {
106
- persistenceFileArray [ persistenceFileArray . length ] = persistenceFilePayload ;
107
- } else {
108
- persistenceFileArray [ persistenceFileIndex ] = persistenceFilePayload ;
109
- }
110
- state . persistenceFileArray = persistenceFileArray ;
111
- } )
112
- . addCase ( deletePersistenceFile , ( state , action ) => {
113
- const newPersistenceFileArray = state [ 'persistenceFileArray' ] . filter ( e => e . id !== action . payload . id ) ;
114
- const isGitHubSyncing = action . payload . repoName ? true : false ;
115
- if ( isGitHubSyncing ) {
116
- const newPersFile = { id : '' , name : '' , repoName : action . payload . repoName , path : action . payload . path } ;
117
- const newPersFileArray = newPersistenceFileArray . concat ( newPersFile ) ;
118
- state . persistenceFileArray = newPersFileArray ;
119
- } else {
120
- state . persistenceFileArray = newPersistenceFileArray ;
121
- }
122
- } )
123
- . addCase ( deleteAllPersistenceFiles , ( state , action ) => {
124
- state . persistenceFileArray = [ ] ;
125
- } )
126
- . addCase ( updatePersistenceFilePathAndNameByPath , ( state , action ) => {
127
- const filesState = state [ 'persistenceFileArray' ] ;
128
- const persistenceFileFindIndex = filesState . findIndex ( e => e . path === action . payload . oldPath ) ;
129
- if ( persistenceFileFindIndex === - 1 ) {
130
- return ;
131
- }
132
- const newPersistenceFile = { ...filesState [ persistenceFileFindIndex ] , path : action . payload . newPath , name : action . payload . newFileName } ;
133
- filesState [ persistenceFileFindIndex ] = newPersistenceFile ;
134
- state . persistenceFileArray = filesState ;
135
- } )
136
- . addCase ( updatePersistenceFolderPathAndNameByPath , ( state , action ) => {
137
- const filesState = state [ 'persistenceFileArray' ] ;
138
- // get current level of folder
139
- const regexResult = / ^ ( .* [ \\ \/ ] ) ? ( \. * .* ?) ( \. [ ^ . ] + ?| ) $ / . exec ( action . payload . newPath ) ! ;
116
+ state . persistenceFileArray = persistenceFileArray ;
117
+ } )
118
+ . addCase ( deletePersistenceFile , ( state , action ) => {
119
+ const newPersistenceFileArray = state [ 'persistenceFileArray' ] . filter (
120
+ e => e . id !== action . payload . id
121
+ ) ;
122
+ const isGitHubSyncing = action . payload . repoName ? true : false ;
123
+ if ( isGitHubSyncing ) {
124
+ const newPersFile = {
125
+ id : '' ,
126
+ name : '' ,
127
+ repoName : action . payload . repoName ,
128
+ path : action . payload . path
129
+ } ;
130
+ const newPersFileArray = newPersistenceFileArray . concat ( newPersFile ) ;
131
+ state . persistenceFileArray = newPersFileArray ;
132
+ } else {
133
+ state . persistenceFileArray = newPersistenceFileArray ;
134
+ }
135
+ } )
136
+ . addCase ( deleteAllPersistenceFiles , ( state , action ) => {
137
+ state . persistenceFileArray = [ ] ;
138
+ } )
139
+ . addCase ( updatePersistenceFilePathAndNameByPath , ( state , action ) => {
140
+ const filesState = state [ 'persistenceFileArray' ] ;
141
+ const persistenceFileFindIndex = filesState . findIndex (
142
+ e => e . path === action . payload . oldPath
143
+ ) ;
144
+ if ( persistenceFileFindIndex === - 1 ) {
145
+ return ;
146
+ }
147
+ const newPersistenceFile = {
148
+ ...filesState [ persistenceFileFindIndex ] ,
149
+ path : action . payload . newPath ,
150
+ name : action . payload . newFileName
151
+ } ;
152
+ filesState [ persistenceFileFindIndex ] = newPersistenceFile ;
153
+ state . persistenceFileArray = filesState ;
154
+ } )
155
+ . addCase ( updatePersistenceFolderPathAndNameByPath , ( state , action ) => {
156
+ const filesState = state [ 'persistenceFileArray' ] ;
157
+ // get current level of folder
158
+ const regexResult = filePathRegex . exec ( action . payload . newPath ) ! ;
140
159
141
160
const currFolderSplit : string [ ] = regexResult [ 0 ] . slice ( 1 ) . split ( '/' ) ;
142
161
const currFolderIndex = currFolderSplit . length - 1 ;
0 commit comments