Skip to content

Commit

Permalink
refactor: new UserCard component (#489)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Mar 31, 2024
1 parent c5b2747 commit fd93dde
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
38 changes: 38 additions & 0 deletions src/components/UserCard.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<template>
<v-card
:title="user.user_id"
prepend-icon="mdi-account"
@click="goToUser(user)">
<v-card-text>
<PriceCountChip :count="user.price_count" :withLabel="true"></PriceCountChip>
</v-card-text>
</v-card>
</template>

<script>
import { defineAsyncComponent } from 'vue'
export default {
components: {
'PriceCountChip': defineAsyncComponent(() => import('../components/PriceCountChip.vue')),
},
props: {
user: {
type: Object,
required: true
},
readonly: {
type: Boolean,
default: false
}
},
methods: {
goToUser(user) {
if (this.readonly) {
return
}
this.$router.push({ path: `/users/${user.user_id}` })
},
}
}
</script>
8 changes: 2 additions & 6 deletions src/views/UserDetail.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
<template>
<v-row>
<v-col cols="12" sm="6">
<v-card :title="username" prepend-icon="mdi-account">
<v-card-text>
<PriceCountChip :count="userPriceTotal" :withLabel="true"></PriceCountChip>
</v-card-text>
</v-card>
<UserCard :user="{user_id: username, price_count: userPriceTotal}" readonly></UserCard>
</v-col>
</v-row>

Expand Down Expand Up @@ -49,7 +45,7 @@ import constants from '../constants'
export default {
components: {
'PriceCountChip': defineAsyncComponent(() => import('../components/PriceCountChip.vue')),
'UserCard': defineAsyncComponent(() => import('../components/UserCard.vue')),
'FilterMenu': defineAsyncComponent(() => import('../components/FilterMenu.vue')),
'OrderMenu': defineAsyncComponent(() => import('../components/OrderMenu.vue')),
'PriceCard': defineAsyncComponent(() => import('../components/PriceCard.vue')),
Expand Down
18 changes: 3 additions & 15 deletions src/views/UserList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,7 @@

<v-row class="mt-0">
<v-col cols="12" sm="6" md="4" v-for="user in userList" :key="user">
<v-card
:title="user.user_id"
prepend-icon="mdi-account"
elevation="1"
height="100%"
@click="goToUser(user)">
<v-card-text>
<PriceCountChip :count="user.price_count" :withLabel="true"></PriceCountChip>
</v-card-text>
</v-card>
<UserCard :user="user" height="100%"></UserCard>
</v-col>
</v-row>

Expand All @@ -35,12 +26,12 @@
</template>

<script>
import api from '../services/api'
import { defineAsyncComponent } from 'vue'
import api from '../services/api'
export default {
components: {
'PriceCountChip': defineAsyncComponent(() => import('../components/PriceCountChip.vue')),
'UserCard': defineAsyncComponent(() => import('../components/UserCard.vue')),
},
data() {
return {
Expand Down Expand Up @@ -71,9 +62,6 @@ export default {
this.loading = false
})
},
goToUser(user) {
this.$router.push({ path: `/users/${user.user_id}` })
},
}
}
</script>

0 comments on commit fd93dde

Please sign in to comment.