Browse Source

Adds method to change saved username.

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

27
.idea/workspace.xml

@ -7,7 +7,6 @@ @@ -7,7 +7,6 @@
<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$/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>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -48,7 +47,7 @@ @@ -48,7 +47,7 @@
<workItem from="1597348092890" duration="8205000" />
<workItem from="1597530844649" duration="131000" />
<workItem from="1597577497243" duration="3353000" />
<workItem from="1597583294362" duration="1455000" />
<workItem from="1597583294362" duration="3872000" />
</task>
<task id="LOCAL-00001" summary="Adds gitignore.">
<created>1597348071361</created>
@ -239,7 +238,14 @@ @@ -239,7 +238,14 @@
<option name="project" value="LOCAL" />
<updated>1597578975715</updated>
</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 />
</component>
<component name="TypeScriptGeneratedFilesManager">
@ -259,17 +265,18 @@ @@ -259,17 +265,18 @@
<MESSAGE value="Remove DB method call." />
<MESSAGE value="Refactor and added todo." />
<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 name="WindowStateProjectService">
<state x="278" y="2" width="800" height="718" key="#Plugins" timestamp="1597350105557">
<screen x="0" y="0" width="1366" height="720" />
</state>
<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" />
</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">
<screen x="0" y="0" width="1366" height="720" />
</state>
@ -286,18 +293,18 @@ @@ -286,18 +293,18 @@
<screen x="0" y="0" width="1366" height="720" />
</state>
<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" />
</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">
<screen x="0" y="0" width="1366" height="720" />
</state>
<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" />
</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">
<screen x="0" y="0" width="1366" height="720" />
</state>

67
app.js

@ -5,6 +5,8 @@ let kara = new Vue({ @@ -5,6 +5,8 @@ let kara = new Vue({
name: 'Kara',
chatbox: null,
isTyping: false,
askedForName: false,
username: '',
addModal: {
includeAll: false,
keywords: '',
@ -38,15 +40,21 @@ let kara = new Vue({ @@ -38,15 +40,21 @@ let kara = new Vue({
]
},
mounted() {
if (this.getSavedData() === false) {
this.getSavedData();
if (!this.username) {
this.initialGreeting();
// Todo: add method to ask for and save username
this.askForName();
this.isTyping = false;
} else {
this.welcomeBack();
}
document.getElementById('chatinput').focus();
document.title = this.name;
this.scrollDown();
},
methods: {
addMessage(body, ai) {
@ -109,15 +117,14 @@ let kara = new Vue({ @@ -109,15 +117,14 @@ let kara = new Vue({
this.isTyping = true;
setTimeout(() => {
this.isTyping = false;
document.getElementById('chatinput').focus();
}, 2500);
setTimeout(() => {
let answer = this.getAnswer(message);
console.log(answer);
if (this.askedForName === true) {
this.setName(message)
} else {
let answer = this.getAnswer(message);
this.aiMessage(answer);
}
this.aiMessage(answer);
this.isTyping = false;
this.scrollDown();
}, 3000);
},
@ -189,6 +196,11 @@ let kara = new Vue({ @@ -189,6 +196,11 @@ let kara = new Vue({
let phrases = message.split(' ');
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) => {
if (answerOption.includeAll === true) {
if (
@ -234,17 +246,17 @@ let kara = new Vue({ @@ -234,17 +246,17 @@ let kara = new Vue({
},
updateStorage() {
localStorage.setItem('name', this.name);
localStorage.setItem('username', this.username);
localStorage.setItem('messages', JSON.stringify(this.messages));
localStorage.setItem('answers', JSON.stringify(this.answers));
},
getSavedData() {
let savedName = localStorage.getItem('name')
let savedName = localStorage.getItem('name');
if (savedName === '') {
return false;
}
this.name = savedName ? savedName : this.name;
this.name = localStorage.getItem('name');
let savedUsername = localStorage.getItem('username');
this.username = savedUsername ? savedUsername : null;
let savedMessages = JSON.parse(localStorage.getItem('messages'));
this.messages = savedMessages ? savedMessages : [];
@ -253,6 +265,31 @@ let kara = new Vue({ @@ -253,6 +265,31 @@ let kara = new Vue({
this.answers = savedAnswers ? savedAnswers : this.answers;
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