Colubrina/frontend/src/components/NicknameDialog.vue

85 lines
2.1 KiB
Vue
Raw Normal View History

2022-07-29 01:12:29 +10:00
<template>
<v-dialog v-model="nickname.dialog" width="500px">
<v-card>
<v-card-title>
<span class="headline">{{ nickname.user.username }}</span>
</v-card-title>
<v-card-text>
<v-text-field
v-model="nickname.nickname"
label="Nickname"
2022-07-29 21:26:18 +10:00
autofocus
2022-07-29 01:12:29 +10:00
@keyup.enter="setFriendNickname"
></v-text-field>
<small>Friend nicknames only show to you.</small>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn
color="blue darken-1"
text
@click="
nickname.dialog = false
nickname.nickname = ''
nickname.user = {}
"
>
Cancel
</v-btn>
<v-btn color="blue darken-1" text @click="setFriendNickname">
Apply
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</template>
<script>
2022-11-03 18:30:37 +11:00
import AjaxErrorHandler from "@/lib/errorHandler.js"
2022-07-29 01:12:29 +10:00
export default {
name: "NicknameDialog",
props: ["nickname"],
methods: {
setFriendNickname() {
this.axios
.post(
process.env.VUE_APP_BASE_URL +
"/api/v1/communications/nickname/" +
this.nickname.user.id,
{
nickname: this.nickname.nickname
}
)
.then((res) => {
this.$store.state.chats.forEach((item) => {
item.chat.associations.forEach((a) => {
if (a.user.id === this.nickname.user.id) {
a.user.nickname = {
nickname: res.data.nickname
}
}
})
item.chat.users.forEach((u) => {
if (u.id === this.nickname.user.id) {
u.nickname = {
nickname: res.data.nickname
}
}
})
})
this.nickname.dialog = false
this.nickname.nickname = ""
this.nickname.user = {}
this.$toast.success("Nickname changed successfully.")
})
.catch((e) => {
AjaxErrorHandler(this.$store)(e)
})
}
}
}
</script>
<style scoped></style>