diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 6cba226..a460803 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -6,6 +6,8 @@ + + @@ -274,17 +283,18 @@ - - + - + @@ -301,10 +311,10 @@ - + - + @@ -313,13 +323,13 @@ - + - - + + - + \ No newline at end of file diff --git a/app.css b/app.css index 454fe13..ad9d379 100644 --- a/app.css +++ b/app.css @@ -18,7 +18,7 @@ body { max-width: 80%; } -.ai-message { +.bot-message { border-radius: 0px 15px 15px 15px; background-color: lightgreen; } @@ -61,4 +61,8 @@ body { .response-input { margin-bottom: 3px; +} + +.form-button { + width: 100%; } \ No newline at end of file diff --git a/app.js b/app.js index fd0a803..65948f8 100644 --- a/app.js +++ b/app.js @@ -14,6 +14,10 @@ let kara = new Vue({ 'Answer #1' ] }, + settingsModal: { + name: null, + username: null + }, answers: [ { includeAll: false, @@ -42,6 +46,11 @@ let kara = new Vue({ mounted() { this.getSavedData(); + this.settingsModal = { + name: this.name, + username: this.username + }; + if (!this.username) { this.initialGreeting(); this.askForName(); @@ -57,19 +66,15 @@ let kara = new Vue({ this.scrollDown(); }, methods: { - addMessage(body, ai) { + addMessage(body, bot) { this.messages.push({ body: body, - ai: ai, + bot: bot, time: Date.now() }) - - this.updateStorage(); }, - aiMessage(body) { + botMessage(body) { this.addMessage(body, true); - - this.updateStorage(); }, userMessage(body) { this.addMessage(body, false); @@ -77,7 +82,7 @@ let kara = new Vue({ this.updateStorage(); }, initialGreeting() { - this.aiMessage( + this.botMessage( this.oneOf( [ "Hi! I'm " + this.name + ". :)", @@ -89,7 +94,7 @@ let kara = new Vue({ this.updateStorage(); }, welcomeBack() { - this.aiMessage( + this.botMessage( this.oneOf( [ "Hi! Haven't heard of you in a while. :)", @@ -98,8 +103,6 @@ let kara = new Vue({ ] ) ); - - this.updateStorage(); }, sendMessage() { if (this.chatbox.trim() === '') { @@ -110,8 +113,6 @@ let kara = new Vue({ this.scrollDown(); this.react(this.chatbox); this.chatbox = ''; - - this.updateStorage(); }, react(message) { this.isTyping = true; @@ -121,7 +122,11 @@ let kara = new Vue({ this.setName(message) } else { let answer = this.getAnswer(message); - this.aiMessage(answer); + if (answer) { + this.botMessage(answer); + } + + this.updateStorage(); } this.isTyping = false; @@ -130,10 +135,8 @@ let kara = new Vue({ }, scrollDown() { $('#chat-box').stop().animate({ - scrollTop: $('#chat-box')[0].scrollHeight + scrollTop: ($('#chat-box')[0].scrollHeight * 10) }, 800); - - this.updateStorage(); }, oneOf(answers) { let amountOfAnswers = answers.length; @@ -201,6 +204,11 @@ let kara = new Vue({ return "Please tell me how i should call you."; } + if (this.includesAllOf(phrases, ['clear', 'chat'])) { + this.clearChat() + return false; + } + this.answers.forEach((answerOption) => { if (answerOption.includeAll === true) { if ( @@ -267,7 +275,7 @@ let kara = new Vue({ this.scrollDown(); }, askForName() { - this.aiMessage( + this.botMessage( this.oneOf([ 'May i ask for your name?', 'Whats your name? :)', @@ -283,13 +291,25 @@ let kara = new Vue({ this.updateStorage(); this.askedForName = false; - this.aiMessage( + this.botMessage( this.oneOf([ "That's a beautiful name!", "Okay, i'll call you " + this.username + " from now on :)", "Nice to meet you, " + this.username + ". :D" ]) ) + }, + saveSettings() { + this.name = this.settingsModal.name; + this.username = this.settingsModal.username; + this.updateStorage(); + + this.botMessage('Settings saved! :)'); + this.scrollDown(); + }, + clearChat() { + this.messages = []; + this.botMessage('Chat cleared.'); } } }) \ No newline at end of file diff --git a/index.html b/index.html index 99dabd6..7493502 100644 --- a/index.html +++ b/index.html @@ -13,7 +13,10 @@
-
+
+ +
+
@@ -25,7 +28,7 @@
-
+
Loading... @@ -96,6 +99,45 @@
+ +