Don't upload dictionaries have not been edited

This commit is contained in:
Robbie Antenesse 2019-06-06 16:06:17 -06:00 committed by Robbie Antenesse
parent 74642dcc0a
commit 769c6f0f15
2 changed files with 17 additions and 30 deletions

View File

@ -1,41 +1,14 @@
import { addMessage } from "../utilities";
import { saveDictionary, clearDictionary } from "../dictionaryManagement";
import { request } from "./helpers";
import { saveToken } from "./utilities";
import { saveToken, dictionaryIsDefault } from "./utilities";
import { renderAll } from "../render";
import { sortWords } from "../wordManagement";
import { getLocalDeletedWords, clearLocalDeletedWords, saveDeletedWordsLocally } from "./utilities";
import { renderChangeDictionaryOptions } from "./render";
/* Outline for syncing
login
-> check local dictionary id
(DONE!) ? no id
-> upload dictionary
-> make new dictionary current
(Canceled) ? mismatched id
-> sync local dictionary (see 'same id' below)
-> if no matching remote id, ignore (assume deleted)
-> clear local dictionary
-> insert downloaded dictionary
(DONE!) ? same id
-> compare detail last updated timestamp
? downloaded details are newer
-> replace local details
? local details are newer
-> flag to upload details
-> filter deleted words from current words
-- check id and compare deletedOn with createdOn
-> compare each word and by lastUpdated/createdOn
? downloaded word is newer
-> update local word
? local word is newer
-> put word in an array to upload
-> upload anything that needs update
*/
export function syncDictionary(uploadAsNewIfNoExternalID = true) {
if (!window.currentDictionary.hasOwnProperty('externalID')) {
if (!window.currentDictionary.hasOwnProperty('externalID') && !dictionaryIsDefault()) {
uploadWholeDictionary(uploadAsNewIfNoExternalID);
} else {
addMessage('Syncing...');

View File

@ -1,11 +1,25 @@
import { setCookie } from "../StackOverflow/cookie";
import { DELETED_WORDS_LOCALSTORAGE_KEY } from "./constants";
import { getTimestampInSeconds } from "../../helpers";
import { getTimestampInSeconds, cloneObject } from "../../helpers";
import { DEFAULT_DICTIONARY } from "../../constants";
export function saveToken(token) {
setCookie('token', token, 30);
}
export function dictionaryIsDefault() {
const defaultDictionary = cloneObject(DEFAULT_DICTIONARY);
delete defaultDictionary.lastUpdated;
delete defaultDictionary.createdOn;
delete defaultDictionary.version;
const currentDictionary = cloneObject(window.currentDictionary);
delete currentDictionary.lastUpdated;
delete currentDictionary.createdOn;
delete currentDictionary.version;
console.log(JSON.stringify(defaultDictionary) === JSON.stringify(currentDictionary));
return JSON.stringify(defaultDictionary) === JSON.stringify(currentDictionary);
}
export function saveDeletedWordsLocally(wordIds) {
let storedDeletedWords = getLocalDeletedWords();
wordIds.forEach(wordId => {