@@ -77,63 +77,24 @@ function useFile({
7777 filepath, defaultContent, authentication, config, repository, branch, onOpenValidation,
7878 } ) ;
7979
80- console . log ( "ensureFile:" ) ;
81- console . log ( _file ) ;
80+ console . log ( "ensureFile:" , _file ) ;
8281
8382 let defaultCachedContentFile ;
84- // if (loadDefaultCachedContentFile) {
85- // console.log("_file.html_url");
86- // console.log(_file.html_url);
87- // defaultCachedContentFile = await loadDefaultCachedContentFile(_file.html_url);
88- // }
89- console . log ( "GRT // onLoadCache!" , _file , _file . html_url ) ;
9083 if ( onLoadCache && _file && _file . html_url )
9184 {
92- defaultCachedContentFile = await onLoadCache ( { authentication, repository, branch, html_url : _file . html_url } ) ;
85+ defaultCachedContentFile = await onLoadCache ( { authentication, repository, branch, html_url : _file . html_url , file : _file } ) ;
9386 }
9487
95- console . log ( "GRT defaultContent" , '|' , defaultContent ) ;
96- console . log ( "GRT defaultCachedContent" , '|' , defaultCachedContentFile ) ;
88+ // console.log("GRT defaultContent", '|', defaultContent);
89+ // console.log("GRT defaultCachedContent", '|', defaultCachedContentFile);
9790
98- if ( defaultCachedContentFile )
99- {
100- console . log ( defaultCachedContentFile . sha ) ;
101- }
102- if ( _file ) {
103- console . log ( _file . sha ) ;
104- }
105-
106- // let content;
107- // content = await repositoryActions.fileFromZip(filepath);
108- //const content = await getContentFromFile(_file);
109-
110- // Allow app to provide CACHED ("offline" content);
111- // Might be different BRANCH (different user) or different FILE.
112- // Might be STALE (sha has changed on DCS).
113- // (NOTE: STALE cache would mean THIS user edited the same file in another browser.)
11491 let content ;
11592 let _publishedContent ;
11693
117- if ( defaultCachedContentFile && defaultCachedContentFile . content && defaultCachedContentFile . sha
118- && defaultCachedContentFile . html_url && defaultCachedContentFile . filepath && defaultCachedContentFile . timestamp
119- && defaultCachedContentFile . sha === _file . sha
120- && defaultCachedContentFile . html_url === _file . html_url
121- ) {
94+ if ( defaultCachedContentFile && defaultCachedContentFile . content ) {
12295 // Load autosaved content:
12396 content = defaultCachedContentFile . content ;
12497 } else {
125- if ( _file && _file . content
126- && defaultCachedContentFile && defaultCachedContentFile . content
127- && defaultCachedContentFile . filepath && defaultCachedContentFile . sha
128- && defaultCachedContentFile . timestamp ) {
129- console . log ( _file ) ;
130- console . log ( defaultCachedContentFile ) ;
131- alert (
132- "A previous file was autosaved. The autosaved file will be overwritten.\n\n" +
133- "File: " + defaultCachedContentFile . filepath + ".\n" +
134- "Edited: " + defaultCachedContentFile . timestamp . toLocaleString ( ) + "."
135- ) ;
136- }
13798 // Get SERVER content: Overwrite cache:
13899 content = await getContentFromFile ( _file ) ;
139100
@@ -148,8 +109,10 @@ function useFile({
148109 ..._file , branch, content, filepath : _file . path , publishedContent : _publishedContent ,
149110 } ) ;
150111 }
151- } , [ authentication , branch , config , defaultContent , onLoadCache , filepath , repository , update ] ) ;
152-
112+ } , [ config , repository , filepath , onLoadCache , ensureFile , update ,
113+ defaultContent , authentication , branch , onOpenValidation
114+ ] ) ;
115+
153116 const createFile = useCallback ( async ( {
154117 branch : _branch , filepath : _filepath , defaultContent : _defaultContent , onOpenValidation,
155118 } ) => {
@@ -187,17 +150,14 @@ function useFile({
187150 } , [ writeable , authentication , repository , branch , file , onSaveCache ] ) ;
188151
189152 const save = useCallback ( async ( content ) => {
190- console . log ( "GRT save // will save file" ) ;
153+ // console.log("GRT save // will save file");
191154 await saveFile ( {
192155 authentication, repository, branch, file, content,
193156 } ) . then (
194157 // Empty cache if user has saved this file
195158 // (save() will not happen for "OFFLINE" system files)
196159 async ( ) => {
197- console . log ( "GRT save // will EMPTY cache" ) ;
198160 await saveCache ( null ) ;
199-
200- console . log ( "GRT save // will load file" ) ;
201161 await load ( ) ;
202162 }
203163 ) ;
0 commit comments