From 55f4a7c8096790e56f50bef1c4b99e1f8b78df21 Mon Sep 17 00:00:00 2001 From: Nero Ignis Date: Sat, 19 Sep 2020 17:43:57 +0200 Subject: [PATCH] Save reactions on luna-development.net; --- addReactions.html | 2 +- addReponse.js | 24 ++++++++++-------------- app.js | 23 ++++++++++++++++------- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/addReactions.html b/addReactions.html index 17fb7ed..509a448 100644 --- a/addReactions.html +++ b/addReactions.html @@ -44,7 +44,7 @@
-
diff --git a/addReponse.js b/addReponse.js index 84f1e47..60412c8 100644 --- a/addReponse.js +++ b/addReponse.js @@ -24,28 +24,24 @@ let responses = new Vue({ addResponseToInput() { this.addModal.responses.push(''); }, - addNewResponseContainer() { + addNewReaction() { let includeAll = this.addModal.includeAll; - let keywords = this.cleanupMessage(this.addModal.keywords).split(','); + let keywords = this.addModal.keywords.split(','); let responses = this.addModal.responses; - let newResponse = { + let newReaction = { includeAll: includeAll, keywords: keywords, responses: responses }; - axios.post('/responses/create', newResponse) - .then((response) => { - console.log(response); - }) - .catch((error) => { - console.log(error); - }) - - // this.addModal.includeAll = false; - // this.addModal.keywords = ''; - // this.addModal.responses = ['']; + axios.post('/reactions/create', { + reaction: newReaction + }).then((response) => { + console.log(response); + }).catch((error) => { + console.log(error); + }); }, cleanupMessage(message) { message = message.toLowerCase(); diff --git a/app.js b/app.js index 0daea58..d485796 100644 --- a/app.js +++ b/app.js @@ -3,8 +3,7 @@ let kara = new Vue({ data: { features: { changeName: false, - themes: true, - ownReactions: true, + themes: false, setNameAtStart: true }, messages: [], @@ -32,7 +31,7 @@ let kara = new Vue({ location: '' }, notes: [], - answers: [ + reactions: [ { includeAll: false, keywords: [ @@ -59,6 +58,7 @@ let kara = new Vue({ }, mounted() { this.getSavedData(); + this.getReactions(); if (this.features.themes) { this.getBootswatchThemes(); @@ -277,7 +277,7 @@ let kara = new Vue({ return "It's " + moment().format('dddd') + ", " + moment().format('MMMM Do YYYY') + "."; } - this.answers.forEach((answerOption) => { + this.reactions.forEach((answerOption) => { if (answerOption.includeAll === true) { if (this.includesAllOf(phrases, answerOption.keywords)) { answer = this.oneOf(answerOption.responses); @@ -464,7 +464,7 @@ let kara = new Vue({ this.messages = savedMessages ? savedMessages : []; let savedAnswers = JSON.parse(localStorage.getItem('answers')); - this.answers = savedAnswers !== [] ? savedAnswers : this.answers; + this.reactions = savedAnswers !== [] ? savedAnswers : this.reactions; let savedNotes = JSON.parse(localStorage.getItem('notes')); this.notes = savedNotes ? savedNotes : []; @@ -482,7 +482,7 @@ let kara = new Vue({ localStorage.setItem('username', this.username); localStorage.setItem('activeTheme', this.activeTheme); localStorage.setItem('messages', JSON.stringify(this.messages)); - localStorage.setItem('answers', JSON.stringify(this.answers)); + localStorage.setItem('answers', JSON.stringify(this.reactions)); localStorage.setItem('notes', JSON.stringify(this.notes)); localStorage.setItem('lastMessage', JSON.stringify(this.lastMessage)); localStorage.setItem('location', JSON.stringify(this.location)); @@ -572,7 +572,7 @@ let kara = new Vue({ return includesAllPhrases; }, - // Ajax calls for saving/receiving responses & themes + // Ajax calls for saving/receiving reactions & themes getBootswatchThemes() { let vue = this; @@ -583,6 +583,15 @@ let kara = new Vue({ .catch(function (error) { console.log(error); }) + }, + getReactions() { + let vue = this; + + axios.get('/reactions/get').then((response) => { + this.reactions = response.data; + }).catch((error) => { + console.log(error); + }); } } }) \ No newline at end of file