Skip to content

Commit 57c894b

Browse files
Resul AvanResul Avan
Resul Avan
authored and
Resul Avan
committed
remove unnecessary async/awaits
1 parent e4a6618 commit 57c894b

File tree

3 files changed

+41
-42
lines changed

3 files changed

+41
-42
lines changed

src/components/profile/header/ProfileFollow.vue

+12-10
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export default class ProfileFollow extends Vue {
101101
@Prop({ type: Object, required: true }) user: User
102102
103103
loading = true
104-
following = false
104+
followedByMe = false
105105
followerCount = 0
106106
followingCount = 0
107107
@@ -111,12 +111,14 @@ export default class ProfileFollow extends Vue {
111111
await Promise.resolve()
112112
.then(async () => {
113113
if (!this.isMyProfile) {
114+
// am i following the user?
114115
await getFollowingByFollowerAndFollowing(this.authUser.userId, this.user.id)
115116
.then((existingFollowing) => {
116-
this.following = !!existingFollowing
117+
this.followedByMe = !!existingFollowing
117118
})
118119
}
119120
121+
// get followers and followings counts
120122
const [
121123
followerCount,
122124
followingCount
@@ -157,22 +159,22 @@ export default class ProfileFollow extends Vue {
157159
}
158160
159161
get icon () {
160-
return this.following ? 'account-remove-outline' : 'account-star'
162+
return this.followedByMe ? 'account-remove-outline' : 'account-star'
161163
}
162164
163165
get buttonText () {
164-
return this.following ? this.$t('common.unfollow') : this.$t('common.follow')
166+
return this.followedByMe ? this.$t('common.unfollow') : this.$t('common.follow')
165167
}
166168
167169
get buttonType () {
168-
return this.following ? 'is-light' : 'is-primary'
170+
return this.followedByMe ? 'is-light' : 'is-primary'
169171
}
170172
171173
followCalled () {
172174
this.loading = true
173175
Promise.resolve()
174176
.then(async () => {
175-
this.following ? await this.unfollow() : await this.follow()
177+
this.followedByMe ? await this.unfollow() : await this.follow()
176178
})
177179
.finally(() => {
178180
this.loading = false
@@ -183,7 +185,7 @@ export default class ProfileFollow extends Vue {
183185
await getFollowingByFollowerAndFollowing(this.authUser.userId, this.user.id as string)
184186
.then(async (existingFollowing) => {
185187
if (existingFollowing) {
186-
this.following = true
188+
this.followedByMe = true
187189
return showInfoToaster(this.$t('notification.follow.alreadyFollowing', { username: this.user.username }))
188190
}
189191
@@ -198,7 +200,7 @@ export default class ProfileFollow extends Vue {
198200
status: PushNotificationStatus.NEW
199201
})
200202
}).then(() => {
201-
this.following = true
203+
this.followedByMe = true
202204
this.followerCount++
203205
})
204206
})
@@ -210,13 +212,13 @@ export default class ProfileFollow extends Vue {
210212
await getFollowingByFollowerAndFollowing(this.authUser.userId, this.user.id as string)
211213
.then(async (existingFollowing) => {
212214
if (!existingFollowing) {
213-
this.following = false
215+
this.followedByMe = false
214216
return showInfoToaster(this.$t('notification.follow.alreadyUnfollowing', { username: this.user.username }))
215217
}
216218
217219
await deleteFollowing(existingFollowing)
218220
.then(() => {
219-
this.following = false
221+
this.followedByMe = false
220222
this.followerCount--
221223
})
222224
})

src/service/firebase/firestore/collection-base-service.ts

+25-25
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ const updateBaseModel = <T extends BaseModel> (model: T) => {
4444
model.updatedBy = auth.currentUser?.uid
4545
}
4646

47-
const set = async <T extends BaseModel> (collection: string, model: T) => {
47+
const set = <T extends BaseModel> (collection: string, model: T) => {
4848
updateBaseModel(model)
4949

5050
const docRef = firestore.collection(collection).doc(model.id)
5151

52-
return await docRef.set(model, {
52+
return docRef.set(model, {
5353
merge: true
5454
})
5555
.then(() => {
@@ -63,65 +63,65 @@ const set = async <T extends BaseModel> (collection: string, model: T) => {
6363
})
6464
}
6565

66-
const add = async <T extends BaseModel> (collection: string, model: T) => {
66+
const add = <T extends BaseModel> (collection: string, model: T) => {
6767
const docRef = firestore.collection(collection).doc()
6868
model.id = docRef.id
6969

70-
return await set(collection, model)
70+
return set(collection, model)
7171
}
7272

73-
export const saveModel = async <T extends BaseModel> (collection: string, model: T) => {
73+
export const saveModel = <T extends BaseModel> (collection: string, model: T) => {
7474
return model.id
75-
? await set(collection, model)
76-
: await add(collection, model)
75+
? set(collection, model)
76+
: add(collection, model)
7777
}
7878

79-
export const deleteModel = async (collection: string, model: BaseModel) => {
80-
return await firestore.collection(collection).doc(model.id).delete()
79+
export const deleteModel = (collection: string, model: BaseModel) => {
80+
return firestore.collection(collection).doc(model.id).delete()
8181
}
8282

83-
export const getCount = async (collection: string): Promise<number> => {
84-
return await firestore.collection(collection)
83+
export const getCount = (collection: string): Promise<number> => {
84+
return firestore.collection(collection)
8585
.get()
8686
.then((querySnapshot) => {
8787
return querySnapshot.size
8888
})
8989
}
9090

91-
export const getCountByWhereClauses = async (
91+
export const getCountByWhereClauses = (
9292
collection: string,
9393
whereClause: WhereClause,
9494
...whereClauses: WhereClause[]): Promise<number> => {
9595
const query = getQueryByWhereClauses(collection, whereClause, ...whereClauses)
9696

97-
return await query.get()
97+
return query.get()
9898
.then((querySnapshot) => {
9999
return querySnapshot.size
100100
})
101101
}
102102

103-
export const getModelById = async (collection: string, id: string): Promise<BaseModel> => {
104-
return await firestore.collection(collection).doc(id).get().then((doc) => {
103+
export const getModelById = (collection: string, id: string): Promise<BaseModel> => {
104+
return firestore.collection(collection).doc(id).get().then((doc) => {
105105
return doc.data() as BaseModel
106106
})
107107
}
108108

109-
export const getModels = async <T extends BaseModel> (collection: string): Promise<T[]> => {
110-
return await firestore.collection(collection).get()
109+
export const getModels = <T extends BaseModel> (collection: string): Promise<T[]> => {
110+
return firestore.collection(collection).get()
111111
.then(querySnapshot => toBaseModelArray(querySnapshot))
112112
}
113113

114-
export const getModelsByWhereClauses = async <T extends BaseModel> (
114+
export const getModelsByWhereClauses = <T extends BaseModel> (
115115
collection: string,
116116
whereClause: WhereClause,
117117
...whereClauses: WhereClause[]): Promise<T[]> => {
118118
const query = getQueryByWhereClauses(collection, whereClause, ...whereClauses)
119119

120-
return await query.get()
120+
return query.get()
121121
.then(querySnapshot => toBaseModelArray(querySnapshot))
122122
}
123123

124-
export const getModelsByWhereClausesAndOrderBy = async <T extends BaseModel> (
124+
export const getModelsByWhereClausesAndOrderBy = <T extends BaseModel> (
125125
collection: string,
126126
orderBy: OrderBy,
127127
whereClause: WhereClause,
@@ -132,11 +132,11 @@ export const getModelsByWhereClausesAndOrderBy = async <T extends BaseModel> (
132132
query = query.orderBy(orderBy.field, orderBy.direction)
133133
}
134134

135-
return await query.get()
135+
return query.get()
136136
.then(querySnapshot => toBaseModelArray(querySnapshot))
137137
}
138138

139-
export const getModelsByWhereClausesAndLimitAndOrderBy = async <T extends BaseModel> (
139+
export const getModelsByWhereClausesAndLimitAndOrderBy = <T extends BaseModel> (
140140
collection: string,
141141
lastVisible: any,
142142
limit: number,
@@ -156,14 +156,14 @@ export const getModelsByWhereClausesAndLimitAndOrderBy = async <T extends BaseMo
156156

157157
query = query.limit(limit)
158158

159-
return await query.get()
159+
return query.get()
160160
.then(querySnapshot => toBaseModelArray(querySnapshot))
161161
}
162162

163-
export const getModelsByFieldAndPaging = async (
163+
export const getModelsByFieldAndPaging = (
164164
collection: string, field: string, value: any, page: number, limit: number
165165
): Promise<PagingResponse<BaseModel>> => {
166-
return await firestore.collection(collection).get()
166+
return firestore.collection(collection).get()
167167
.then((querySnapshot) => {
168168
const docs: BaseModel[] = []
169169

src/service/firebase/firestore/following-collection.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ const followersWhereClause = (user: User): WhereClause => {
2424
}
2525
}
2626

27-
export const saveFollowing = async (following: Following): Promise<Following> => {
28-
return await saveModel(collection.FOLLOWING, following)
27+
export const saveFollowing = (following: Following): Promise<Following> => {
28+
return saveModel(collection.FOLLOWING, following)
2929
}
3030

31-
export const deleteFollowing = async (following: Following) => {
32-
return await deleteModel(collection.FOLLOWING, following)
31+
export const deleteFollowing = (following: Following) => {
32+
return deleteModel(collection.FOLLOWING, following)
3333
}
3434

3535
export const getFollowingByFollowerAndFollowing = async (follower: string, following: string) => {
@@ -50,13 +50,11 @@ export const getFollowingByFollowerAndFollowing = async (follower: string, follo
5050

5151
export const getCountOfFollowers = (user: User) => {
5252
const whereClause = followingWhereClause(user)
53-
5453
return getCountByWhereClauses(collection.FOLLOWING, whereClause)
5554
}
5655

5756
export const getCountOfFollowing = (user: User) => {
5857
const whereClause = followersWhereClause(user)
59-
6058
return getCountByWhereClauses(collection.FOLLOWING, whereClause)
6159
}
6260

@@ -87,7 +85,6 @@ export const searchFollowings = async (user: User, query: string, page: number,
8785
const whereClauseForFollowers = followersWhereClause(user)
8886

8987
const followingList: Following[] = await getModelsByWhereClauses(collection.FOLLOWING, whereClauseForFollowers)
90-
9188
const users: User[] = []
9289

9390
let loadedUser: User|null = null

0 commit comments

Comments
 (0)