Choose when saveDictionary() updates lastUpdated

This commit is contained in:
Robbie Antenesse 2019-05-23 14:26:57 -06:00
parent c5bdfa5450
commit 569a0b9fc5
3 changed files with 9 additions and 7 deletions

View File

@ -94,7 +94,7 @@ export function uploadWholeDictionary(asNew = false) {
dictionary, dictionary,
}, remoteId => { }, remoteId => {
window.currentDictionary.externalID = remoteId; window.currentDictionary.externalID = remoteId;
saveDictionary(); saveDictionary(false);
addMessage('Dictionary Uploaded Successfully'); addMessage('Dictionary Uploaded Successfully');
}, errorData => { }, errorData => {
console.error(errorData); console.error(errorData);
@ -120,7 +120,7 @@ export function syncDetails(remoteDetails = false) {
return uploadDetails(); return uploadDetails();
} else if (direction === 'down') { } else if (direction === 'down') {
window.currentDictionary = Object.assign(window.currentDictionary, remoteDetails); window.currentDictionary = Object.assign(window.currentDictionary, remoteDetails);
saveDictionary(); saveDictionary(false);
} }
addMessage('Dictionary details synchronized'); addMessage('Dictionary details synchronized');
return Promise.resolve(true); return Promise.resolve(true);
@ -173,7 +173,7 @@ export function syncWords(remoteWords, deletedWords) {
window.currentDictionary.words = words; window.currentDictionary.words = words;
sortWords(); sortWords();
saveDictionary(); saveDictionary(false);
if (localWordsToUpload.length > 0) { if (localWordsToUpload.length > 0) {
return uploadWords(words); return uploadWords(words);

View File

@ -81,8 +81,10 @@ export function saveAndCloseEditModal() {
document.getElementById('editModal').style.display = 'none'; document.getElementById('editModal').style.display = 'none';
} }
export function saveDictionary() { export function saveDictionary(triggerLastUpdated = true) {
if (triggerLastUpdated) {
window.currentDictionary.lastUpdated = getTimestampInSeconds(); window.currentDictionary.lastUpdated = getTimestampInSeconds();
}
window.localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(window.currentDictionary)); window.localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(window.currentDictionary));
} }
@ -185,7 +187,7 @@ export function importWords() {
} }
}, },
complete: () => { complete: () => {
saveDictionary(); saveDictionary(false);
renderAll(); renderAll();
importWordsField.value = ''; importWordsField.value = '';
document.getElementById('editModal').style.display = 'none'; document.getElementById('editModal').style.display = 'none';

View File

@ -39,7 +39,7 @@ export function sortWords(render) {
return removeDiacritics(wordA[sortBy]).toLowerCase() > removeDiacritics(wordB[sortBy]).toLowerCase() ? 1 : -1; return removeDiacritics(wordA[sortBy]).toLowerCase() > removeDiacritics(wordB[sortBy]).toLowerCase() ? 1 : -1;
}); });
saveDictionary(); saveDictionary(false);
if (render) { if (render) {
renderWords(); renderWords();