Create new dictionary if logged in and local has no externalId
This commit is contained in:
parent
654bfab004
commit
d4d46c7afe
|
@ -2,7 +2,7 @@ import { request, saveToken } from "./helpers";
|
|||
import { addMessage } from "../utilities";
|
||||
import { setupLogoutButton } from "./setupListeners";
|
||||
import { renderAccountSettings } from "./render";
|
||||
import { uploadWholeDictionaryAsNew } from "./sync";
|
||||
import { uploadWholeDictionary } from "./sync";
|
||||
|
||||
export function logIn() {
|
||||
const email = document.getElementById('loginEmail').value.trim(),
|
||||
|
@ -88,7 +88,7 @@ export function createAccount() {
|
|||
}, responseData => {
|
||||
saveToken(responseData.token);
|
||||
if (responseData.hasOwnProperty('dictionary')) {
|
||||
uploadWholeDictionaryAsNew(); // Saves external id
|
||||
uploadWholeDictionary(); // Saves external id
|
||||
}
|
||||
return responseData;
|
||||
}, errorData => {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { addMessage } from "../utilities";
|
||||
import { saveDictionary } from "../dictionaryManagement";
|
||||
import { request } from "./helpers";
|
||||
import { request, saveToken } from "./helpers";
|
||||
|
||||
export function syncDictionary() {
|
||||
if (!window.currentDictionary.hasOwnProperty('externalId')) {
|
||||
uploadWholeDictionaryAsNew();
|
||||
uploadWholeDictionary(true);
|
||||
} else {
|
||||
console.log('Do a sync comparison!');
|
||||
// request({
|
||||
|
@ -22,12 +22,25 @@ export function syncDictionary() {
|
|||
}
|
||||
}
|
||||
|
||||
export function uploadWholeDictionaryAsNew() {
|
||||
export function uploadWholeDictionary(asNew = false) {
|
||||
let promise;
|
||||
if (asNew) {
|
||||
promise = request({
|
||||
action: 'create-new-dictionary',
|
||||
}, successData => {
|
||||
saveToken(successData.token);
|
||||
}, errorData => {
|
||||
console.error(errorData);
|
||||
});
|
||||
} else {
|
||||
promise = Promise.resolve();
|
||||
}
|
||||
const dictionary = {
|
||||
details: Object.assign({}, window.currentDictionary),
|
||||
words: window.currentDictionary.words,
|
||||
};
|
||||
delete dictionary.details.words; // Ugly way to easily get the data I need.
|
||||
promise.then(() => {
|
||||
request({
|
||||
action: 'set-whole-current-dictionary',
|
||||
dictionary,
|
||||
|
@ -39,7 +52,9 @@ export function uploadWholeDictionaryAsNew() {
|
|||
console.error(errorData);
|
||||
addMessage(errorData);
|
||||
})
|
||||
.catch(err => console.error(err));
|
||||
.catch(err => console.error('set-whole-current-dictionary: ', err));
|
||||
})
|
||||
.catch(err => console.error('create-new-dictionary: ', err));
|
||||
}
|
||||
|
||||
export function syncDetails(remoteDetails) {
|
||||
|
|
Loading…
Reference in New Issue