Skip to content

Commit aa7462d

Browse files
Merge pull request #895 from unfoldingWord/zach-867-autoSave-WIP
autosave wip
2 parents 4f562d7 + 77a50b8 commit aa7462d

File tree

9 files changed

+132
-67
lines changed

9 files changed

+132
-67
lines changed

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "tc-create-app",
33
"homepage": "https://create.translationcore.com/",
4-
"version": "1.3.0-rc.4",
4+
"version": "1.4.0-rc.1",
55
"license": "MIT",
66
"private": false,
77
"bugs": {
@@ -16,6 +16,7 @@
1616
"styleguide:build": "styleguidist build && mv styleguide build",
1717
"start": "bash -c \"source ./scripts/set-env.sh && rescripts start\"",
1818
"build": "bash -c \"source ./scripts/set-env.sh && rescripts build && yarn styleguide:build\"",
19+
"publishDev": "bash -c \"source ./scripts/set-env.sh && rescripts build && yarn styleguide:build && netlify deploy\"",
1920
"electron:build": "react-scripts build",
2021
"deploy": "yarn build && netlify deploy",
2122
"cypress:run": "NODE_ENV=test cypress run",
@@ -32,19 +33,19 @@
3233
"@material-ui/lab": "^4.0.0-alpha.35",
3334
"@material-ui/styles": "^4.11.3",
3435
"axios": "^0.21.0",
35-
"datatable-translatable": "0.11.1-3.rc-1",
36+
"datatable-translatable": "0.11.13.rc-4",
3637
"deep-freeze": "^0.0.1",
3738
"eslint-plugin-test-selectors": "^1.3.0",
38-
"gitea-react-toolkit": "1.9.3",
39+
"gitea-react-toolkit": "1.11.1-rc.1",
3940
"lodash.isequal": "^4.5.0",
40-
"markdown-translatable": "1.3.1",
41+
"markdown-translatable": "1.3.1-rc.1",
4142
"react": "^16.14.0",
4243
"react-beforeunload": "^2.5.1",
4344
"react-dom": "^16.12.0",
4445
"react-headroom": "^3.0.0",
4546
"react-select": "^4.1.0",
4647
"react-waypoint": "^9.0.2",
47-
"scripture-resources-rcl": "4.1.6",
48+
"scripture-resources-rcl": "4.1.9-rc.1",
4849
"use-deep-compare-effect": "^1.3.1",
4950
"usfm-js": "^2.1.0",
5051
"uw-content-validation": "2.1.6",

public/build_number

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
73-4c6c391
1+
73-27a5017

src/App.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import {
1717
loadState,
1818
loadAuthentication,
1919
saveAuthentication,
20+
loadFileCache,
21+
saveFileCache
2022
} from './core/persistence';
2123

2224
import Workspace from './Workspace';
@@ -68,6 +70,24 @@ function AppComponent() {
6870
}
6971
return notices;
7072
}
73+
74+
const _onLoadCache = async ({authentication, repository, branch, html_url}) => {
75+
console.log("tcc // _onLoadCache", html_url);
76+
77+
if (html_url)
78+
{
79+
return await loadFileCache(html_url);
80+
}
81+
}
82+
83+
const _onSaveCache = ({authentication, repository, branch, file, content}) => {
84+
console.log("tcc // _onSaveCache");
85+
console.log(file);
86+
87+
if (file) {
88+
saveFileCache(file, content);
89+
}
90+
};
7191

7292
const handleClose = useCallback( () => {
7393
setCriticalErrors([]);
@@ -149,6 +169,8 @@ function AppComponent() {
149169
filepath={filepath}
150170
onFilepath={setFilepath}
151171
onOpenValidation={_onOpenValidation}
172+
onLoadCache={_onLoadCache}
173+
onSaveCache={_onSaveCache}
152174
onConfirmClose={_onConfirmClose}
153175
>
154176
{

src/components/files-header/FilesHeader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ function FilesHeader({
4545
style={style}
4646
/>
4747
), [classes.header]);
48-
const sourceBranch = sourceRepository.branch || sourceRepository.default_branch;
49-
const targetBranch = targetRepository.branch || targetRepository.default_branch;
48+
const sourceBranch = sourceRepository?.branch || sourceRepository?.default_branch;
49+
const targetBranch = targetRepository?.branch || targetRepository?.default_branch;
5050

5151
let sourceCompareLink, targetCompareLink;
5252
const sourceLanguage = getLanguage({

src/components/translatable/Translatable.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ function Translatable() {
105105
async (content) => {
106106
setSavingTargetFileContent(content);
107107

108+
// DEBUG
109+
console.log("targetFile");
110+
console.log(targetFile);
111+
108112
try {
109113
await targetFileActions.save(content);
110114
} catch (error) {
@@ -118,6 +122,14 @@ function Translatable() {
118122
}
119123
}
120124
);
125+
126+
const autoSaveOnEdit = (
127+
async (content) => {
128+
console.log("tC Create / autosave", targetFile, content);
129+
targetFileActions.saveCache(content);
130+
}
131+
);
132+
121133
if (
122134
filepath &&
123135
sourceFile &&
@@ -132,13 +144,13 @@ function Translatable() {
132144
onTranslation: saveOnTranslation,
133145
onContentIsDirty: setContentIsDirty,
134146
};
135-
_translatable = <MarkdownContextProvider><MarkDownTranslatable {...translatableProps} /></MarkdownContextProvider>;
147+
_translatable = <MarkdownContextProvider><MarkDownTranslatable {...translatableProps} onEdit={autoSaveOnEdit} /></MarkdownContextProvider>;
136148
} else if (sourceFile.filepath.match(/^tq_...\.tsv$/)) {
137-
_translatable = <TranslatableTqTSV onSave={saveOnTranslation} onContentIsDirty={setContentIsDirty} />;
149+
_translatable = <TranslatableTqTSV onSave={saveOnTranslation} onEdit={autoSaveOnEdit} onContentIsDirty={setContentIsDirty} />;
138150
} else if (sourceFile.filepath.match(/^twl_...\.tsv$/)) {
139-
_translatable = <TranslatableTwlTSV onSave={saveOnTranslation} onContentIsDirty={setContentIsDirty} />;
151+
_translatable = <TranslatableTwlTSV onSave={saveOnTranslation} onEdit={autoSaveOnEdit} onContentIsDirty={setContentIsDirty} />;
140152
} else if (sourceFile.filepath.match(/\.tsv$/)) {
141-
_translatable = <TranslatableTSV onSave={saveOnTranslation} onContentIsDirty={setContentIsDirty} />;
153+
_translatable = <TranslatableTSV onSave={saveOnTranslation} onEdit={autoSaveOnEdit} onContentIsDirty={setContentIsDirty} />;
142154
} else {
143155
_translatable = <h3 style={{ 'textAlign': 'center' }} >Unsupported File. Please select .md or .tsv files.</h3>;
144156
}
@@ -150,6 +162,11 @@ function Translatable() {
150162
scrollToTop();
151163
}, [filepath, scrollToTop]);
152164

165+
console.log("targetFile");
166+
console.log(targetFile);
167+
console.log("targetRepository");
168+
console.log(targetRepository);
169+
153170
const filesHeader = targetFile && targetRepository && (
154171
<FilesHeader
155172
sourceRepository={sourceRepository}

src/components/translatable/TranslatableTSV.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const _config = {
3434
],
3535
};
3636

37-
function TranslatableTSVWrapper({ onSave, onContentIsDirty }) {
37+
function TranslatableTSVWrapper({ onSave, onEdit, onContentIsDirty }) {
3838
// manage the state of the resources for the provider context
3939
const [resources, setResources] = useState([]);
4040
const [open, setOpen] = React.useState(false);
@@ -184,9 +184,10 @@ function TranslatableTSVWrapper({ onSave, onContentIsDirty }) {
184184
_config.rowHeader = rowHeader;
185185
return (
186186
<DataTable
187-
sourceFile={sourceFile.content}
188-
targetFile={targetFile.content}
187+
sourceFile={sourceFile && sourceFile.content}
188+
targetFile={targetFile && targetFile.content}
189189
onSave={onSave}
190+
onEdit={onEdit}
190191
onValidate={onValidate}
191192
onContentIsDirty={onContentIsDirty}
192193
delimiters={delimiters}
@@ -195,7 +196,7 @@ function TranslatableTSVWrapper({ onSave, onContentIsDirty }) {
195196
options={options}
196197
/>
197198
);
198-
}, [sourceFile.content, targetFile.content, onSave, onValidate, onContentIsDirty, generateRowId, options, rowHeader]);
199+
}, [sourceFile, targetFile, onSave, onEdit, onValidate, onContentIsDirty, generateRowId, options, rowHeader, ]);
199200

200201
return (
201202
<>

src/core/TargetFile.context.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function TargetFileContextProvider({
1515
} = {},
1616
} = useContext(AppContext);
1717

18-
const { state: sourceFile, stateValues: sourceStateValues } = useContext(FileContext) || {};
18+
const { state: sourceFile, stateValues: sourceStateValues, actions: sourceFileActions } = useContext(FileContext) || {};
1919

2020
const appContext = useContext(AppContext);
2121
const sourceContext = useContext(FileContext);
@@ -53,6 +53,10 @@ function TargetFileContextProvider({
5353
onFilepath: setFilepath,
5454
defaultContent: _defaultContent,
5555
onOpenValidation: onOpenValidation,
56+
// Pass cache actions from the app's FileContext (happens to be SOURCE).
57+
// Sharing actions allows the app to use onCacheChange events.
58+
onLoadCache: sourceFileActions.onLoadCache,
59+
onSaveCache: sourceFileActions.onSaveCache,
5660
onConfirmClose: null,
5761
});
5862

src/core/persistence.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ export const loadState = async (key) => {
1111
return value;
1212
};
1313

14+
export const loadValue = async (store, key) => {
15+
let value = await store.getItem(key);
16+
return value;
17+
};
18+
1419
export const saveState = async (key, value) => {
1520
let response;
1621

@@ -22,6 +27,17 @@ export const saveState = async (key, value) => {
2227
return response;
2328
};
2429

30+
export const saveKeyValue = async (store, key, value) => {
31+
let response;
32+
33+
if (value === null || value === undefined) {
34+
response = await store.removeItem(key);
35+
} else {
36+
response = await store.setItem(key, value);
37+
}
38+
return response;
39+
};
40+
2541
export const loadAuthentication = async () => {
2642
let _authentication = await loadState('authentication');
2743

@@ -37,3 +53,37 @@ export const loadAuthentication = async () => {
3753
export const saveAuthentication = async (authentication) => {
3854
saveState('authentication', authentication);
3955
};
56+
57+
const cacheStore = localforage.createInstance({
58+
driver: [localforage.INDEXEDDB],
59+
name: `${appPackage.name}-cache-store`,
60+
});
61+
62+
export const saveFileCache = async (file, content) => {
63+
console.log("tcc saveFileCache", file, content);
64+
65+
let response;
66+
const key = file.html_url;
67+
68+
const cachedContent = {
69+
html_url: file.html_url,
70+
filepath: file.filepath,
71+
sha: file.sha,
72+
timestamp: new Date(),
73+
content: content
74+
};
75+
76+
if (content === null || content === undefined) {
77+
console.log("tcc saveFileCache // REMOVING", file, content);
78+
response = await cacheStore.removeItem(key);
79+
} else {
80+
response = await cacheStore.setItem(key, cachedContent);
81+
}
82+
return response;
83+
};
84+
85+
export const loadFileCache = async (html_url) => {
86+
const cachedFile = await loadValue(cacheStore, html_url);
87+
console.log("tc create loadCacheTargetFile", html_url, cachedFile);
88+
return cachedFile;
89+
};

yarn.lock

Lines changed: 20 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5442,14 +5442,14 @@ data-urls@^1.0.0, data-urls@^1.1.0:
54425442
whatwg-mimetype "^2.2.0"
54435443
whatwg-url "^7.0.0"
54445444

5445-
datatable-translatable@0.11.11:
5446-
version "0.11.11"
5447-
resolved "https://registry.yarnpkg.com/datatable-translatable/-/datatable-translatable-0.11.11.tgz#54a0c200e6bb8570fa52decf8ec71fec6cab7e86"
5448-
integrity sha512-QfLQh//qHvRhZkbcGn2MEaPBFWRsTGwNZdSnO8aK7tw/M0ttQFU8mIyhAWcCfdyyypy56Vh7KYxBOXHwOwARDw==
5445+
datatable-translatable@0.11.13.rc-4:
5446+
version "0.11.1-3.rc-4"
5447+
resolved "https://registry.yarnpkg.com/datatable-translatable/-/datatable-translatable-0.11.1-3.rc-4.tgz#f29bc2b912ceaed11f8387d11db4376e85027f9b"
5448+
integrity sha512-XzmS4XkI6a3C4n+1HJhW10kL1eohHjHlohzzyw5USFbhaH9MgkrHM+aYq/yw9eQFUBExaOJBZThpCxygrMXW9A==
54495449
dependencies:
54505450
deep-freeze "^0.0.1"
54515451
lodash.isequal "^4.5.0"
5452-
markdown-translatable "1.3.1"
5452+
markdown-translatable "1.3.1-rc.1"
54535453
mui-datatables "3.3.1"
54545454
use-deep-compare-effect "^1.3.1"
54555455

@@ -7557,34 +7557,18 @@ getpass@^0.1.1:
75577557
dependencies:
75587558
assert-plus "^1.0.0"
75597559

7560-
gitea-react-toolkit@1.6.4:
7561-
version "1.6.4"
7562-
resolved "https://registry.yarnpkg.com/gitea-react-toolkit/-/gitea-react-toolkit-1.6.4.tgz#43ef60643c4015ed106d3dbe009cfb11c08a15eb"
7563-
integrity sha512-xSL//jpDh7A/Uqxat2bVMT+4fNp2oGi9N6kSpN57YML1l134rgIKJ26/Rhiamk8Sg3ni2fwTw2FMxADg4YibFQ==
7560+
gitea-react-toolkit@1.11.1-rc.1:
7561+
version "1.11.1-rc.1"
7562+
resolved "https://registry.yarnpkg.com/gitea-react-toolkit/-/gitea-react-toolkit-1.11.1-rc.1.tgz#05f34898cb4a20d569742b43da2a92d817d1a97e"
7563+
integrity sha512-y4tsFuUe2veQgIGpvAlnj/0aNGY9EXDWp+51tIWnhSONC3nS7qpBYMwHJk4BI+vnjrnAr9ObT1gxtLnQIbt1uQ==
75647564
dependencies:
75657565
awesome-debounce-promise "2.1.0"
75667566
axios "0.19.0"
75677567
axios-cache-adapter "2.4.1"
75687568
base-64 "0.1.0"
75697569
jszip "^3.5.0"
75707570
localforage "1.7.3"
7571-
markdown-translatable "1.2.16"
7572-
prop-types "15.7.2"
7573-
use-deep-compare-effect "^1.3.1"
7574-
utf8 "3.0.0"
7575-
7576-
gitea-react-toolkit@1.9.3:
7577-
version "1.9.3"
7578-
resolved "https://registry.yarnpkg.com/gitea-react-toolkit/-/gitea-react-toolkit-1.9.3.tgz#0f1467087fbb814aa68f6f6bc695407c76cd3966"
7579-
integrity sha512-JubGD8xmLFTSa4unszKIohVxq/6N04mISkA7XekyuPhH1Bm3GBBScETO5zUyZD2x7YeOnUyqCo4lBNKS/6HD9Q==
7580-
dependencies:
7581-
awesome-debounce-promise "2.1.0"
7582-
axios "0.19.0"
7583-
axios-cache-adapter "2.4.1"
7584-
base-64 "0.1.0"
7585-
jszip "^3.5.0"
7586-
localforage "1.7.3"
7587-
markdown-translatable "1.3.1"
7571+
markdown-translatable "1.3.1-rc.1"
75887572
prop-types "15.7.2"
75897573
use-deep-compare-effect "^1.3.1"
75907574
utf8 "3.0.0"
@@ -10602,24 +10586,10 @@ markdown-to-jsx@^6.11.4:
1060210586
prop-types "^15.6.2"
1060310587
unquote "^1.1.0"
1060410588

10605-
markdown-translatable@1.2.16:
10606-
version "1.2.16"
10607-
resolved "https://registry.yarnpkg.com/markdown-translatable/-/markdown-translatable-1.2.16.tgz#048624bb4762370db30030c4d0265b721c54f7e8"
10608-
integrity sha512-miTzfgoCCFwodkNN9EuUlGg2HoKZbJlYt1BqbqsfpT2jbXbu7jMPVB4d+Jj7wh3wyNSJzON4GqV4X90ke6Gt1w==
10609-
dependencies:
10610-
deep-freeze "^0.0.1"
10611-
md5 "^2.2.1"
10612-
prop-types "^15.7.2"
10613-
react-headroom "^3.1.0"
10614-
react-markdown "4.0.6"
10615-
showdown "^1.9.1"
10616-
turndown "^7.0.0"
10617-
turndown-plugin-gfm "^1.0.2"
10618-
10619-
markdown-translatable@1.3.1:
10620-
version "1.3.1"
10621-
resolved "https://registry.yarnpkg.com/markdown-translatable/-/markdown-translatable-1.3.1.tgz#29393f8650be38885c7991f2e2e661bbe9d000ae"
10622-
integrity sha512-oZieaVOCjxZISyGDvcpb3XsJsnPvKd4xCULFQawQ/L395EwGHFERG6gCH65b3w3HjkLEWhdPknWf1BLK6Mu6Tg==
10589+
markdown-translatable@1.3.1-rc.1:
10590+
version "1.3.1-rc.1"
10591+
resolved "https://registry.yarnpkg.com/markdown-translatable/-/markdown-translatable-1.3.1-rc.1.tgz#498a264d544f87511465ae06dd454565be1daabb"
10592+
integrity sha512-Cn6GFYHZTAQOBy+XCtweOzDVMmshTjIgd2z9oex9DlNWVqlHO54yEvXduFg4YOl4qgTxkdeH+i3Z3VA+01d71w==
1062310593
dependencies:
1062410594
deep-freeze "^0.0.1"
1062510595
md5 "^2.2.1"
@@ -14468,16 +14438,16 @@ schema-utils@^3.0.0:
1446814438
ajv "^6.12.5"
1446914439
ajv-keywords "^3.5.2"
1447014440

14471-
scripture-resources-rcl@4.1.6:
14472-
version "4.1.6"
14473-
resolved "https://registry.yarnpkg.com/scripture-resources-rcl/-/scripture-resources-rcl-4.1.6.tgz#3b173c84994055c4d042ae6e39e3827179cc98c6"
14474-
integrity sha512-VISwN0+DYKA9E4eaQmFeXeP9IcpHmRK/Db6kU2P4Xdiosta8ZBjsTroRHJoWUEggCNpouYJlIoP9Yn7vMx6I1w==
14441+
scripture-resources-rcl@4.1.9-rc.1:
14442+
version "4.1.9-rc.1"
14443+
resolved "https://registry.yarnpkg.com/scripture-resources-rcl/-/scripture-resources-rcl-4.1.9-rc.1.tgz#ef9cd5c8ec8dd8d6af67fd9175410e8260153703"
14444+
integrity sha512-UTUQKWgfBS76CBsfClmpbgYU48CCufizxcpSpeI3A7eRKJUM31qSB+losGUQRICD2gFq6JuMB/Jrodr1bCGrLw==
1447514445
dependencies:
1447614446
deep-freeze "^0.0.1"
14477-
gitea-react-toolkit "1.6.4"
14447+
gitea-react-toolkit "1.11.1-rc.1"
1447814448
js-yaml-parser "^1.0.0"
1447914449
lodash "^4.17.15"
14480-
markdown-translatable "1.2.16"
14450+
markdown-translatable "1.3.1-rc.1"
1448114451
nyc "^15.0.0-beta.3"
1448214452
prop-types "^15.7.2"
1448314453
react-waypoint "^9.0.2"

0 commit comments

Comments
 (0)