Skip to content

Commit ddd4ed1

Browse files
Resul AvanResul Avan
Resul Avan
authored and
Resul Avan
committed
loading view when user is loading
1 parent e6d140f commit ddd4ed1

File tree

2 files changed

+37
-24
lines changed

2 files changed

+37
-24
lines changed

src/pages/profile/index.vue

+11-5
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ export default class profile extends Vue {
1818
user: User|null = null
1919
2020
@StateNamespace.auth.Getter readonly authUser: AuthUser;
21+
@StateNamespace.loading.Action saveLoading: (loading: boolean) => Promise<void>
2122
22-
created () {
23+
mounted () {
2324
this.$subscribeTo(profilePhotoObservable.asObservable(), (image: Image) => {
2425
if (this.user) {
2526
this.user.profilePhoto = image
@@ -41,11 +42,16 @@ export default class profile extends Vue {
4142
}
4243
4344
loadUser () {
44-
getUser(this.authUser.userId)
45-
.then((user: User) => {
46-
this.user = user
45+
this.saveLoading(true)
46+
.then(async () => {
47+
await getUser(this.authUser.userId)
48+
.then((user: User) => {
49+
this.user = user
50+
})
51+
.catch(() => sendDangerNotification(this.$store.dispatch, this.$t('notification.profile.canNotLoad')))
4752
})
48-
.catch(() => sendDangerNotification(this.$store.dispatch, this.$t('notification.profile.canNotLoad')))
53+
.catch((error: Error) => console.log('profile.create', error))
54+
.finally(() => this.saveLoading(false))
4955
}
5056
}
5157
</script>

src/pages/u/_username/index.vue

+26-19
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default class profile extends Vue {
2020
user: User|null = null
2121
2222
@StateNamespace.auth.Getter readonly authUser: AuthUser
23+
@StateNamespace.loading.Action saveLoading: (loading: boolean) => Promise<void>
2324
2425
asyncData ({ params }: Context) {
2526
const username = params[RouteParameters.USERNAME]
@@ -29,7 +30,7 @@ export default class profile extends Vue {
2930
}
3031
}
3132
32-
async created () {
33+
mounted () {
3334
this.$subscribeTo(profilePhotoObservable.asObservable(), (image: Image) => {
3435
console.log('profilePhotoObservable called by ', image)
3536
if (this.user) {
@@ -57,26 +58,32 @@ export default class profile extends Vue {
5758
})
5859
}
5960
60-
const user = await this.loadUser()
61-
.catch(() => sendDangerNotification(this.$store.dispatch, this.$t('notification.profile.canNotLoad'))) as User
62-
if (!user) {
63-
return this.$nuxt.error({
64-
message: this.$t('page.notFound') as string,
65-
path: this.$route.fullPath,
66-
statusCode: 404
67-
})
68-
}
61+
this.saveLoading(true)
62+
.then(async () => {
63+
const user = await this.loadUser()
64+
.catch(() => sendDangerNotification(this.$store.dispatch, this.$t('notification.profile.canNotLoad')))
6965
70-
if (this.authUser.username !== this.username &&
71-
((!user?.privacy || user.privacy === PrivacyType.PRIVATE))) {
72-
console.log('PRIVATE user')
73-
this.$nuxt.error({
74-
message: this.$t('page.notFound') as string,
75-
path: this.$route.fullPath,
76-
statusCode: 404
66+
if (!user) {
67+
return this.$nuxt.error({
68+
message: this.$t('page.notFound') as string,
69+
path: this.$route.fullPath,
70+
statusCode: 404
71+
})
72+
}
73+
74+
if (this.authUser.username !== this.username &&
75+
((!user?.privacy || user.privacy === PrivacyType.PRIVATE))) {
76+
console.log('PRIVATE user')
77+
this.$nuxt.error({
78+
message: this.$t('page.notFound') as string,
79+
path: this.$route.fullPath,
80+
statusCode: 404
81+
})
82+
}
83+
this.user = user
7784
})
78-
}
79-
this.user = user
85+
.catch((error: Error) => console.log('profile.create', error))
86+
.finally(() => this.saveLoading(false))
8087
}
8188
8289
async loadUser (): Promise<User> {

0 commit comments

Comments
 (0)