From cde119592d928f5a0a7c9397ca8f42cebac649ac Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Mon, 21 Oct 2019 00:22:37 +0200 Subject: [PATCH] Redid the template for profile, regist and siginin to better use the components we have made and to use update function definition. Changed the message system with SeasonedMessages. This means simpler interaction and less duplicate code now that the messagesystem is a separate component that both interface with. --- src/components/Profile.vue | 1 - src/components/Register.vue | 82 ++++--------- src/components/Signin.vue | 85 ++++--------- src/components/ui/SeasonedMessages.vue | 159 +++++++++++++++++++++++++ 4 files changed, 205 insertions(+), 122 deletions(-) create mode 100644 src/components/ui/SeasonedMessages.vue diff --git a/src/components/Profile.vue b/src/components/Profile.vue index 26c4c3c..e3ee9e9 100644 --- a/src/components/Profile.vue +++ b/src/components/Profile.vue @@ -34,7 +34,6 @@ import Settings from '@/components/Settings.vue' import SeasonedButton from '@/components/ui/SeasonedButton.vue' import { getEmoji } from '@/api.js' -// import CreatedLists from './CreatedLists.vue' export default { components: { MoviesList, Settings, SeasonedButton }, diff --git a/src/components/Register.vue b/src/components/Register.vue index 32bc51b..19899f6 100644 --- a/src/components/Register.vue +++ b/src/components/Register.vue @@ -1,41 +1,18 @@ @@ -44,18 +21,16 @@ import axios from 'axios' import storage from '@/storage.js' import SeasonedButton from '@/components/ui/SeasonedButton.vue' import SeasonedInput from '@/components/ui/SeasonedInput.vue' +import SeasonedMessages from '@/components/ui/SeasonedMessages.vue' export default { - components: { SeasonedButton, SeasonedInput }, + components: { SeasonedButton, SeasonedInput, SeasonedMessages }, data(){ return{ - userLoggedIn: '', + messages: [], username: undefined, password: undefined, - passwordRepeat: undefined, - showMessage: false, - messageClass: 'message-success', - messageText: 'hello world' + passwordRepeat: undefined } }, methods: { @@ -71,10 +46,9 @@ export default { username: username, password: password }) - .then(function(resp) { + .then(resp => { let data = resp.data; if (data.success){ - this.msg(data.message, 'success'); localStorage.setItem('token', data.token); localStorage.setItem('username', username); localStorage.setItem('admin', data.admin) @@ -82,13 +56,13 @@ export default { eventHub.$emit('setUserStatus'); this.$router.push({ name: 'profile' }) } - }.bind(this)) - .catch(function(error){ - this.msg(error.response.data.error, 'warning') - }.bind(this)); + }) + .catch(error => { + this.messages.push({ type: 'error', title: 'Unexpected error', message: error.response.data.error }) + }); } else { - this.msg(verifyCredentials.reason, 'warning'); + this.messages.push({ type: 'warning', title: 'Parse error', message: verifyCredentials.reason }) } }, checkCredentials(username, password, password_re) { @@ -111,20 +85,6 @@ export default { } } }, - msg(text, status){ - if (status === 'warning') - this.messageClass = 'message-warning'; - else if (status === 'success') - this.messageClass = 'message-success'; - else - this.messageClass = 'message-info'; - this.messageText = text; - this.showMessage = true; - // setTimeout(() => this.showMessage = false, 3500); - }, - dismissMessage(){ - this.showMessage = false; - }, setValue(l, t) { this[l] = t }, diff --git a/src/components/Signin.vue b/src/components/Signin.vue index 9bcfabb..1be4afc 100644 --- a/src/components/Signin.vue +++ b/src/components/Signin.vue @@ -1,50 +1,34 @@ + + diff --git a/src/components/ui/SeasonedMessages.vue b/src/components/ui/SeasonedMessages.vue new file mode 100644 index 0000000..b68c415 --- /dev/null +++ b/src/components/ui/SeasonedMessages.vue @@ -0,0 +1,159 @@ + + + + + \ No newline at end of file