usercp/deckcp split

This commit is contained in:
Jörn-Michael Miehe 2019-05-27 17:06:10 +02:00
parent 063893e3e8
commit 8d3bddfd5b
7 changed files with 92 additions and 34 deletions

View file

@ -1,5 +1,9 @@
<template>
<Header>
<Header v-if="user">
<v-btn flat :to="{ name: 'deckcp' }">
<v-icon>view_carousel</v-icon> Decks
</v-btn>
<v-btn flat :to="{ name: 'usercp' }">
<v-icon>person</v-icon> {{ user.login }}
</v-btn>
@ -25,10 +29,7 @@
Cancel
</v-btn>
<v-btn
color="success"
@click.native="logout"
>
<v-btn color="success" @click.native="logout">
Confirm
</v-btn>
</v-card-actions>
@ -85,19 +86,21 @@ export default {
asyncComputed: {
user: {
get() {
return axios
.post('/user/info', {
session: this.session
})
.then(response => {
if (response.data.success) {
this.$emit('input', this.session)
return response.data.user
} else {
this.goHome()
return null
}
})},
return axios
.post('/user/info', {
session: this.session
})
.then(response => {
if (response.data.success) {
this.$emit('input', this.session)
this.$emit('user', response.data.user)
return response.data.user
} else {
this.goHome()
return null
}
})
},
default: {
user: 0,
login: '',

View file

@ -0,0 +1,16 @@
<template>
<div>
{{ user.login }}
</div>
</template>
<script>
export default {
name: 'UserInfo',
props: {
session: String,
user: Object
}
}
</script>

View file

@ -64,7 +64,7 @@ export default {
let cookie_data = JSON.parse(response.data.message)
Cookies.set('session', cookie_data.value, cookie_data.properties)
this.$refs.main.showSnackbar('Login successful!', 'success')
this.$router.push('usercp')
this.$router.push('deckcp')
} else {
this.$refs.main.showSnackbar(response.data.message, 'error')
}

View file

@ -22,6 +22,12 @@ export default new Router({
component: () =>
import(/* webpackChunkName: "usercp" */ './views/UserCP.vue')
},
{
path: '/deckcp',
name: 'deckcp',
component: () =>
import(/* webpackChunkName: "deckcp" */ './views/DeckCP.vue')
},
{
path: '/game',
name: 'game',

View file

@ -0,0 +1,29 @@
<template>
<v-content>
<HeaderIntern v-model="session" @user="user = $event" />
<v-container v-if="user">
<h2 class="headline">Your Decks</h2>
<DeckList :session="session" />
</v-container>
</v-content>
</template>
<script>
import HeaderIntern from '@/components/HeaderIntern.vue'
import DeckList from '@/components/DeckList.vue'
export default {
name: 'DeckCP',
components: {
HeaderIntern,
DeckList
},
data: () => ({
session: null,
user: null
})
}
</script>

View file

@ -36,15 +36,17 @@ export default {
mounted() {
this.$nextTick(() => {
axios
.post('/user/login', {
session: this.session
})
.then(response => {
if (response.data.success) {
this.$router.push({ name: 'usercp' })
}
})
if (this.session) {
axios
.post('/user/login', {
session: this.session
})
.then(response => {
if (response.data.success) {
this.$router.push({ name: 'deckcp' })
}
})
}
})
}
}

View file

@ -1,27 +1,29 @@
<template>
<v-content>
<v-container>
<HeaderIntern v-model="session" />
<HeaderIntern v-model="session" @user="user = $event" />
<DeckList :session="session" />
<v-container v-if="user">
<h2 class="headline">User Info</h2>
<UserInfo :session="session" :user="user" />
</v-container>
</v-content>
</template>
<script>
import HeaderIntern from '@/components/HeaderIntern.vue'
import DeckList from '@/components/DeckList.vue'
import UserInfo from '@/components/UserInfo.vue'
export default {
name: 'UserCP',
components: {
HeaderIntern,
DeckList
UserInfo
},
data: () => ({
session: ''
session: null,
user: null
})
}
</script>