Browse Source

Adds method to change saved username.

master
Nero Ignis 5 years ago
parent
commit
543d9ca6ba
  1. 27
      .idea/workspace.xml
  2. 65
      app.js

27
.idea/workspace.xml

@ -7,7 +7,6 @@
<list default="true" id="e3f098f0-e98c-435a-af04-d153c9525633" name="Default Changelist" comment=""> <list default="true" id="e3f098f0-e98c-435a-af04-d153c9525633" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app.js" beforeDir="false" afterPath="$PROJECT_DIR$/app.js" afterDir="false" /> <change beforePath="$PROJECT_DIR$/app.js" beforeDir="false" afterPath="$PROJECT_DIR$/app.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/index.html" beforeDir="false" afterPath="$PROJECT_DIR$/index.html" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -48,7 +47,7 @@
<workItem from="1597348092890" duration="8205000" /> <workItem from="1597348092890" duration="8205000" />
<workItem from="1597530844649" duration="131000" /> <workItem from="1597530844649" duration="131000" />
<workItem from="1597577497243" duration="3353000" /> <workItem from="1597577497243" duration="3353000" />
<workItem from="1597583294362" duration="1455000" /> <workItem from="1597583294362" duration="3872000" />
</task> </task>
<task id="LOCAL-00001" summary="Adds gitignore."> <task id="LOCAL-00001" summary="Adds gitignore.">
<created>1597348071361</created> <created>1597348071361</created>
@ -239,7 +238,14 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1597578975715</updated> <updated>1597578975715</updated>
</task> </task>
<option name="localTasksCounter" value="28" /> <task id="LOCAL-00028" summary="Kara now saves the chat and her saved answers in localstorage.">
<created>1597584801023</created>
<option name="number" value="00028" />
<option name="presentableId" value="LOCAL-00028" />
<option name="project" value="LOCAL" />
<updated>1597584801023</updated>
</task>
<option name="localTasksCounter" value="29" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@ -259,17 +265,18 @@
<MESSAGE value="Remove DB method call." /> <MESSAGE value="Remove DB method call." />
<MESSAGE value="Refactor and added todo." /> <MESSAGE value="Refactor and added todo." />
<MESSAGE value="Move answers to data." /> <MESSAGE value="Move answers to data." />
<option name="LAST_COMMIT_MESSAGE" value="Move answers to data." /> <MESSAGE value="Kara now saves the chat and her saved answers in localstorage." />
<option name="LAST_COMMIT_MESSAGE" value="Kara now saves the chat and her saved answers in localstorage." />
</component> </component>
<component name="WindowStateProjectService"> <component name="WindowStateProjectService">
<state x="278" y="2" width="800" height="718" key="#Plugins" timestamp="1597350105557"> <state x="278" y="2" width="800" height="718" key="#Plugins" timestamp="1597350105557">
<screen x="0" y="0" width="1366" height="720" /> <screen x="0" y="0" width="1366" height="720" />
</state> </state>
<state x="278" y="2" width="800" height="718" key="#Plugins/0.0.1366.720@0.0.1366.720" timestamp="1597350105557" /> <state x="278" y="2" width="800" height="718" key="#Plugins/0.0.1366.720@0.0.1366.720" timestamp="1597350105557" />
<state x="222" y="0" width="912" height="720" key="CommitChangelistDialog2" timestamp="1597578975663"> <state x="222" y="0" width="912" height="720" key="CommitChangelistDialog2" timestamp="1597584800897">
<screen x="0" y="0" width="1366" height="720" /> <screen x="0" y="0" width="1366" height="720" />
</state> </state>
<state x="222" y="0" width="912" height="720" key="CommitChangelistDialog2/0.0.1366.720@0.0.1366.720" timestamp="1597578975663" /> <state x="222" y="0" width="912" height="720" key="CommitChangelistDialog2/0.0.1366.720@0.0.1366.720" timestamp="1597584800897" />
<state x="466" y="118" width="424" height="490" key="FileChooserDialogImpl" timestamp="1597353496276"> <state x="466" y="118" width="424" height="490" key="FileChooserDialogImpl" timestamp="1597353496276">
<screen x="0" y="0" width="1366" height="720" /> <screen x="0" y="0" width="1366" height="720" />
</state> </state>
@ -286,18 +293,18 @@
<screen x="0" y="0" width="1366" height="720" /> <screen x="0" y="0" width="1366" height="720" />
</state> </state>
<state x="172" y="0" key="SettingsEditor/0.0.1366.720@0.0.1366.720" timestamp="1597530949459" /> <state x="172" y="0" key="SettingsEditor/0.0.1366.720@0.0.1366.720" timestamp="1597530949459" />
<state x="278" y="92" width="800" height="542" key="Vcs.Push.Dialog.v2" timestamp="1597578976661"> <state x="278" y="92" width="800" height="542" key="Vcs.Push.Dialog.v2" timestamp="1597584803101">
<screen x="0" y="0" width="1366" height="720" /> <screen x="0" y="0" width="1366" height="720" />
</state> </state>
<state x="278" y="92" width="800" height="542" key="Vcs.Push.Dialog.v2/0.0.1366.720@0.0.1366.720" timestamp="1597578976661" /> <state x="278" y="92" width="800" height="542" key="Vcs.Push.Dialog.v2/0.0.1366.720@0.0.1366.720" timestamp="1597584803101" />
<state x="0" y="0" width="616" height="720" key="find.popup" timestamp="1597346688624"> <state x="0" y="0" width="616" height="720" key="find.popup" timestamp="1597346688624">
<screen x="0" y="0" width="1366" height="720" /> <screen x="0" y="0" width="1366" height="720" />
</state> </state>
<state x="0" y="0" width="616" height="720" key="find.popup/0.0.1366.720@0.0.1366.720" timestamp="1597346688624" /> <state x="0" y="0" width="616" height="720" key="find.popup/0.0.1366.720@0.0.1366.720" timestamp="1597346688624" />
<state width="533" height="302" key="javadoc.popup.new" timestamp="1597349276436"> <state width="533" height="302" key="javadoc.popup.new" timestamp="1597585751908">
<screen x="0" y="0" width="1366" height="720" /> <screen x="0" y="0" width="1366" height="720" />
</state> </state>
<state width="533" height="302" key="javadoc.popup.new/0.0.1366.720@0.0.1366.720" timestamp="1597349276436" /> <state width="533" height="302" key="javadoc.popup.new/0.0.1366.720@0.0.1366.720" timestamp="1597585751908" />
<state x="347" y="155" key="run.anything.popup" timestamp="1597584197904"> <state x="347" y="155" key="run.anything.popup" timestamp="1597584197904">
<screen x="0" y="0" width="1366" height="720" /> <screen x="0" y="0" width="1366" height="720" />
</state> </state>

65
app.js

@ -5,6 +5,8 @@ let kara = new Vue({
name: 'Kara', name: 'Kara',
chatbox: null, chatbox: null,
isTyping: false, isTyping: false,
askedForName: false,
username: '',
addModal: { addModal: {
includeAll: false, includeAll: false,
keywords: '', keywords: '',
@ -38,15 +40,21 @@ let kara = new Vue({
] ]
}, },
mounted() { mounted() {
if (this.getSavedData() === false) { this.getSavedData();
if (!this.username) {
this.initialGreeting(); this.initialGreeting();
// Todo: add method to ask for and save username this.askForName();
this.isTyping = false;
} else { } else {
this.welcomeBack(); this.welcomeBack();
} }
document.getElementById('chatinput').focus(); document.getElementById('chatinput').focus();
document.title = this.name; document.title = this.name;
this.scrollDown();
}, },
methods: { methods: {
addMessage(body, ai) { addMessage(body, ai) {
@ -109,15 +117,14 @@ let kara = new Vue({
this.isTyping = true; this.isTyping = true;
setTimeout(() => { setTimeout(() => {
this.isTyping = false; if (this.askedForName === true) {
document.getElementById('chatinput').focus(); this.setName(message)
}, 2500); } else {
setTimeout(() => {
let answer = this.getAnswer(message); let answer = this.getAnswer(message);
console.log(answer);
this.aiMessage(answer); this.aiMessage(answer);
}
this.isTyping = false;
this.scrollDown(); this.scrollDown();
}, 3000); }, 3000);
}, },
@ -189,6 +196,11 @@ let kara = new Vue({
let phrases = message.split(' '); let phrases = message.split(' ');
let answer = undefined; let answer = undefined;
if (this.includesAllOf(phrases, ['change', 'my', 'name'])) {
this.askedForName = true;
return "Please tell me how i should call you.";
}
this.answers.forEach((answerOption) => { this.answers.forEach((answerOption) => {
if (answerOption.includeAll === true) { if (answerOption.includeAll === true) {
if ( if (
@ -234,17 +246,17 @@ let kara = new Vue({
}, },
updateStorage() { updateStorage() {
localStorage.setItem('name', this.name); localStorage.setItem('name', this.name);
localStorage.setItem('username', this.username);
localStorage.setItem('messages', JSON.stringify(this.messages)); localStorage.setItem('messages', JSON.stringify(this.messages));
localStorage.setItem('answers', JSON.stringify(this.answers)); localStorage.setItem('answers', JSON.stringify(this.answers));
}, },
getSavedData() { getSavedData() {
let savedName = localStorage.getItem('name') let savedName = localStorage.getItem('name');
if (savedName === '') { this.name = savedName ? savedName : this.name;
return false;
}
this.name = localStorage.getItem('name'); let savedUsername = localStorage.getItem('username');
this.username = savedUsername ? savedUsername : null;
let savedMessages = JSON.parse(localStorage.getItem('messages')); let savedMessages = JSON.parse(localStorage.getItem('messages'));
this.messages = savedMessages ? savedMessages : []; this.messages = savedMessages ? savedMessages : [];
@ -253,6 +265,31 @@ let kara = new Vue({
this.answers = savedAnswers ? savedAnswers : this.answers; this.answers = savedAnswers ? savedAnswers : this.answers;
this.scrollDown(); this.scrollDown();
},
askForName() {
this.aiMessage(
this.oneOf([
'May i ask for your name?',
'Whats your name? :)',
'How can i call you?',
'How did your developers call you? :)'
])
);
this.askedForName = true;
},
setName(message) {
this.username = message.trim();
this.updateStorage();
this.askedForName = false;
this.aiMessage(
this.oneOf([
"That's a beautiful name!",
"Okay, i'll call you " + this.username + " from now on :)",
"Nice to meet you, " + this.username + ". :D"
])
)
} }
} }
}) })
Loading…
Cancel
Save