Skip to content

Commit 1f83c32

Browse files
authored
Merge pull request #118 from unfoldingWord/zach-autosave-prompt-921
autosave let app handle conflict
2 parents 7cbe715 + 55b6a15 commit 1f83c32

File tree

3 files changed

+13
-53
lines changed

3 files changed

+13
-53
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gitea-react-toolkit",
3-
"version": "2.0.1",
3+
"version": "2.0.2-rc.1",
44
"license": "MIT",
55
"description": "A Gitea API React Toolkit Component Library",
66
"homepage": "https://gitea-react-toolkit.netlify.com/",

src/components/file/useFile.js

Lines changed: 10 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -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
);

src/components/tree-blob/useBlob.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ function useBlob({
1919
const blob = __blob && deepFreeze(__blob);
2020

2121
let url = _url || (repository && repository.tree_url);
22-
console.log("releaseFlag?",releaseFlag);
22+
//console.log("releaseFlag?",releaseFlag);
2323
if ( releaseFlag && repository?.catalog?.prod?.branch_or_tag_name ) {
2424
// p.replace(regex, 'ferret')
2525
url = url.replace(/master$/,repository.catalog.prod.branch_or_tag_name);
2626
}
27-
console.log("url=",url);
27+
//console.log("url=",url);
2828
const update = useCallback((_blob) => {
2929
if (onBlob) {
3030
onBlob(_blob);

0 commit comments

Comments
 (0)