diff --git a/src/components/feedbackWidget/feedbackWdget.tsx b/src/components/feedbackWidget/feedbackWdget.tsx index 2bc5607..1aeea92 100644 --- a/src/components/feedbackWidget/feedbackWdget.tsx +++ b/src/components/feedbackWidget/feedbackWdget.tsx @@ -10,11 +10,6 @@ import { Component, h, getAssetPath, State, Prop, Element } from '@stencil/core' export class FeedbackWidget { @Element() el; - @State() angryEmoji = "emojiAngry.png"; - @State() emojiHeartEyes = "emojiHeartEyes.png"; - @State() emojiNeutral = "emojiNeutral.png"; - @State() emojiSad = "emojiSad.png"; - @State() emojiSmile = "emojiSmile.png"; @Prop() appName = "Product" @State() quetionsArray = []; @State() feedBackData = []; @@ -24,6 +19,7 @@ export class FeedbackWidget { @State() phaseEnd: boolean = false; @State() textAreaIsActive: boolean = false; @State() textAreaData: string = "" + @State() isCompact: boolean = true; private questionOne = `How satisfied are you with the ${this.appName}'s value for money?` private questionTwo = `How satisfied are you with ${this.appName}'s ease of use?` @@ -33,6 +29,7 @@ export class FeedbackWidget { componentWillLoad() { this.quetionsArray.push(this.questionOne, this.questionTwo, this.questionThree, this.questionFour) + this.checkCookie() } handleProgressBar() { @@ -56,10 +53,9 @@ export class FeedbackWidget { this.phaseTwo = true; this.phaseOne = false; } - + this.handleProgressBar() this.feedBackData.push({question: this.quetionsArray[this.qIndex], rate: e.target.alt}) } - this.handleProgressBar() } userInputText(e) { @@ -96,62 +92,123 @@ export class FeedbackWidget { } handleClosure() { - this.el.remove() + //this.el.remove() + this.isCompact = true; + } + + handleSameUser() { + + } + + handleCompactContainer() { + this.isCompact = false; + } + + setCookie(cname, cvalue, exdays) { + const d = new Date(); + d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); + let expires = "expires="+d.toUTCString(); + document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; + } + + getCookie(cname) { + let name = cname + "="; + let ca = document.cookie.split(';'); + for(let i = 0; i < ca.length; i++) { + let c = ca[i]; + while (c.charAt(0) == ' ') { + c = c.substring(1); + } + if (c.indexOf(name) == 0) { + return c.substring(name.length, c.length); + } + } + return ""; + } + + checkCookie() { + let user = this.getCookie("username"); + if (user != "") { + console.log('welcome back', user) + this.handleSameUser() + } else { + for(let i = 0; i < 19; ++i) user += Math.floor(Math.random() * 10); + if (user != "" && user != null) { + this.setCookie("username", user, 365); + } + } } + + render() { - const angryEmoji = getAssetPath(`../../assets/${this.angryEmoji}`); - const emojiHeartEyes = getAssetPath(`../../assets/${this.emojiHeartEyes}`); - const emojiNeutral = getAssetPath(`../../assets/${this.emojiNeutral}`); - const emojiSad = getAssetPath(`../../assets/${this.emojiSad}`); - const emojiSmile = getAssetPath(`../../assets/${this.emojiSmile}`); + const angryEmoji = getAssetPath(`../../assets/emojiAngry.png`); + const emojiHeartEyes = getAssetPath(`../../assets/emojiHeartEyes.png`); + const emojiNeutral = getAssetPath(`../../assets/emojiNeutral.png`); + const emojiSad = getAssetPath(`../../assets/emojiSad.png`); + const emojiSmile = getAssetPath(`../../assets/emojiSmile.png`); return ( -