akkoma-fe/src/components/user_finder/user_finder.js

34 lines
802 B
JavaScript
Raw Normal View History

2017-05-12 16:54:12 +00:00
const UserFinder = {
data: () => ({
username: undefined,
2017-09-10 17:46:42 +00:00
hidden: true,
error: false,
loading: false
2017-05-12 16:54:12 +00:00
}),
methods: {
findUser (username) {
2017-11-14 15:03:42 +00:00
username = username[0] === '@' ? username.slice(1) : username
2017-09-10 17:46:42 +00:00
this.loading = true
2017-05-12 16:54:12 +00:00
this.$store.state.api.backendInteractor.externalProfile(username)
.then((user) => {
2017-09-10 17:46:42 +00:00
this.loading = false
this.hidden = true
2017-05-12 16:54:12 +00:00
if (!user.error) {
this.$store.commit('addNewUsers', [user])
this.$router.push({name: 'user-profile', params: {id: user.id}})
2017-09-10 17:46:42 +00:00
} else {
this.error = true
2017-05-12 16:54:12 +00:00
}
})
},
toggleHidden () {
this.hidden = !this.hidden
2017-09-10 17:46:42 +00:00
},
dismissError () {
this.error = false
2017-05-12 16:54:12 +00:00
}
}
}
export default UserFinder