Skip to content

Commit ade8142

Browse files
committed
* move User.current(AuthorExpGrade|ForumModerator) into forumSpecific and remove current- prefix to match with de936c0 @ api/user.ts & all its usages
* nested destarcturing prop `user`, not destarcturing directly on the `defineProps()` due to https://github.com/orgs/vuejs/discussions/6147 @ `<PostBadgeUser>` @ fe
1 parent 55a0f82 commit ade8142

4 files changed

Lines changed: 24 additions & 19 deletions

File tree

fe/src/api/user.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ export interface User extends TimestampFields {
3131
fansNickname: string | null,
3232
icon: ObjUnknown[] | null,
3333
ipGeolocation: string | null,
34-
currentForumModerator: {
35-
discoveredAt: UnixTimestamp,
36-
moderatorTypes: ForumModeratorType | '' | `${ForumModeratorType},${ForumModeratorType}`
37-
} | null,
38-
currentAuthorExpGrade: {
39-
discoveredAt: UnixTimestamp,
40-
authorExpGrade: AuthorExpGrade
41-
} | null
34+
forumSpecific: {
35+
authorExpGrade: {
36+
discoveredAt: UnixTimestamp,
37+
authorExpGrade: AuthorExpGrade
38+
} | null,
39+
forumModerator: {
40+
discoveredAt: UnixTimestamp,
41+
moderatorTypes: ForumModeratorType | '' | `${ForumModeratorType},${ForumModeratorType}`
42+
} | null
43+
}
4244
}

fe/src/components/post/badge/ThreadAuthorAndLatestReplier.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</NuxtLink>
1010
</span>
1111
<PostBadgeUser
12-
v-if="authorUser.currentForumModerator !== null"
12+
v-if="authorUser.forumSpecific.forumModerator !== null"
1313
:user="authorUser" class="ms-1 user-badge" />
1414
<DefineLatestReplier v-slot="{ users }">
1515
<span class="ms-2">
@@ -26,7 +26,7 @@
2626
<template v-else-if="latestReplier.uid !== null && latestReplier.uid !== authorUid">
2727
<ReuseLatestReplier :users="[{ name: renderUsername(latestReplier.uid), route: toUserRoute(latestReplier.uid) }]" />
2828
<PostBadgeUser
29-
v-if="!_.isNil(latestReplierUser?.currentForumModerator)"
29+
v-if="!_.isNil(latestReplierUser?.forumSpecific.forumModerator)"
3030
:user="latestReplierUser" class="ms-1 user-badge" />
3131
</template>
3232
</template>
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
<template>
22
<div class="btn-group" role="group">
33
<button
4-
v-if="user.uid === threadAuthorUid"
4+
v-if="uid === threadAuthorUid"
55
type="button" class="badge btn btn-success">
66
楼主
77
</button>
88
<button
9-
v-if="user.uid === replyAuthorUid"
9+
v-if="uid === replyAuthorUid"
1010
type="button" class="badge btn btn-info">
1111
层主
1212
</button>
13-
<template v-if="user.currentForumModerator !== null && user.currentForumModerator.moderatorTypes !== ''">
13+
<template v-if="forumModerator !== null && forumModerator.moderatorTypes !== ''">
1414
<button
1515
v-for="[moderator, bootstrapColor] in Object.values(moderators)"
1616
:key="moderator" type="button"
1717
:class="`badge btn btn-${bootstrapColor}`">
1818
{{ moderator }}
1919
</button>
2020
<button v-if="_.isEmpty(moderators)" type="button" class="badge btn btn-info">
21-
{{ user.currentForumModerator.moderatorTypes }}
21+
{{ forumModerator.moderatorTypes }}
2222
</button>
2323
</template>
2424
<button
25-
v-if="user.currentAuthorExpGrade !== null"
25+
v-if="authorExpGrade !== null"
2626
type="button" class="badge btn btn-primary">
27-
{{ user.currentAuthorExpGrade.authorExpGrade }}级
27+
{{ authorExpGrade.authorExpGrade }}级
2828
</button>
2929
</div>
3030
</template>
@@ -37,6 +37,7 @@ const { user } = defineProps<{
3737
threadAuthorUid?: BaiduUserID,
3838
replyAuthorUid?: BaiduUserID
3939
}>();
40+
const { uid, forumSpecific: { authorExpGrade, forumModerator } } = user;
4041
const moderators = computed(() => _.pick(knownModeratorTypes,
41-
user.currentForumModerator?.moderatorTypes.split(',') ?? []));
42+
forumModerator?.moderatorTypes.split(',') ?? []));
4243
</script>

fe/src/utils/user.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ export const baseGetUser = (users: User[]) => {
2525
ipGeolocation: null,
2626
createdAt: 0,
2727
updatedAt: 0,
28-
currentForumModerator: null,
29-
currentAuthorExpGrade: null
28+
forumSpecific: {
29+
authorExpGrade: null,
30+
forumModerator: null
31+
}
3032
};
3133
};
3234
export const baseGetLatestReplier = (latestRepliers: LatestReplier[]) => {

0 commit comments

Comments
 (0)