From 2a79c800f0e19b6311e4a9001fcddb86abdf8c78 Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Sun, 7 Jan 2018 16:37:26 -0700 Subject: [PATCH] Start working on having Updater send data to api! --- src/managers/Updater.js | 51 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/src/managers/Updater.js b/src/managers/Updater.js index 324187f..42135d1 100644 --- a/src/managers/Updater.js +++ b/src/managers/Updater.js @@ -69,12 +69,55 @@ export class Updater { this.dictionary.lastUpdated = timestampInSeconds(); updatedDetails.lastUpdated = this.dictionary.lastUpdated; this.app.setState(updatedDetails, () => { - if (updatedDetails.hasOwnProperty('settings')) { - this.app.updateDisplayedWords(); - } - resolve(); + // if (updatedDetails.hasOwnProperty('settings')) { + // this.app.updateDisplayedWords(); + // } + this.sendDictionaryDetails(this.dictionary.storedData).then(() => { + resolve(); + }) + .catch(reason => { + reject(reason); + }); }); } }); } + + sendDictionaryDetails (dictionaryDetails) { + const request = new Request('./api/', { + method: 'POST', + mode: 'cors', + redirect: 'follow', + headers: new Headers({ + 'Content-Type': 'application/json' + }), + body: JSON.stringify({ + action: 'set-dictionary-details', + token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MTUxLCJpc01lbWJlciI6ZmFsc2UsImRpY3Rpb25hcnkiOjM1M30.4HRuWY8arkjjYLgQ0Cq4a6v-eXwLTD24oENL8E4I5o0', + details: dictionaryDetails, + }), + }); + return fetch(request).then(response => response.json()).then(responseJSON => { + console.log(responseJSON); + }); + } + + sendWords (words) { + const request = new Request('./api/', { + method: 'POST', + mode: 'cors', + redirect: 'follow', + headers: new Headers({ + 'Content-Type': 'application/json' + }), + body: JSON.stringify({ + action: 'set-dictionary-words', + token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MTUxLCJpc01lbWJlciI6ZmFsc2UsImRpY3Rpb25hcnkiOjM1M30.4HRuWY8arkjjYLgQ0Cq4a6v-eXwLTD24oENL8E4I5o0', + words: words, + }), + }); + return fetch(request).then(response => response.json()).then(responseJSON => { + console.log(responseJSON); + }); + } } \ No newline at end of file