File tree Expand file tree Collapse file tree 6 files changed +27
-17
lines changed
Expand file tree Collapse file tree 6 files changed +27
-17
lines changed Original file line number Diff line number Diff line change 1717
1818<script setup lang="ts">
1919import { useLocalized } from ' @/hooks/useLocalized'
20- import { isOfficial } from ' ~/composables/isOfficial '
20+ import { useRuleChecks } from ' ~/composables/useRuleChecks '
2121import { isAuthor } from ' ~/composables/isAuthor'
2222import { computed } from ' vue'
2323
2424const { message } = useLocalized ()
25+ const { isOfficial } = useRuleChecks ()
2526
2627let { authorId = null , type = null } = defineProps <{
2728 type? : ' official' | ' author' | null
Original file line number Diff line number Diff line change 1414 >
1515 <p >
1616 {{ title }}
17- <ForumRuleBadge :type =" rule" />
17+ <ForumRoleBadge :type =" rule" />
1818 </p >
1919 <p class =" mr-2" v-if =" topic.type" >
2020 <span
9595
9696<script setup lang="ts">
9797import { computed } from ' vue'
98- import ForumRuleBadge from ' ./ForumRuleBadge .vue'
98+ import ForumRoleBadge from ' ./ForumRoleBadge .vue'
9999import ForumTagList from ' ./ForumTagList.vue'
100100import ForumTopicComment from ' ./ForumTopicComment.vue'
101101import ForumTopicMeta from ' ./ForumTopicMeta.vue'
@@ -106,7 +106,7 @@ import { useToggle } from '@vueuse/core'
106106import { useLocalized } from ' @/hooks/useLocalized'
107107import { sessionCacheRedirect } from ' ~/composables/sessionCacheRedirect'
108108import { sanitizeMarkdown } from ' ~/composables/sanitizeMarkdown'
109- import { isOfficial } from ' ~/composables/isOfficial '
109+ import { useRuleChecks } from ' ~/composables/useRuleChecks '
110110
111111import type ForumAPI from ' @/apis/forum/api'
112112
@@ -123,6 +123,7 @@ const topicTypeMap = getTopicTypeMap()
123123const { message } = useLocalized ()
124124
125125const [isExpanded, toggleExpand] = useToggle ()
126+ const { isOfficial } = useRuleChecks ()
126127
127128const renderText = computed (() => {
128129 const contentSanitized = sanitizeMarkdown (topic .contentRaw )
Original file line number Diff line number Diff line change 1717 <div class =" title flex" :class =" style[size].header" >
1818 <p class =" font-size-3.5" >{{ author.username }}</p >
1919
20- <ForumRuleBadge :author-id = " author.id " />
20+ <ForumRoleBadge :type = " rule " />
2121 </div >
2222
2323 <article
5454<script setup lang="ts">
5555import type ForumAPI from ' @/apis/forum/api'
5656import { computed } from ' vue'
57- import ForumRuleBadge from ' ./ForumRuleBadge .vue'
57+ import ForumRoleBadge from ' ./ForumRoleBadge .vue'
5858import { Image } from ' @/components/ui/image'
5959import ForumCommentMeta from ' ./ForumCommentMeta.vue'
6060
6161const {
6262 size = ' normal' ,
6363 repo = ' Feedback' ,
64+ topicAuthorId,
65+ author,
6466 ... props
6567} = defineProps <{
6668 repo: string
@@ -75,6 +77,8 @@ const {
7577 commentClickHandler: Function
7678}>()
7779
80+ const rule = computed (() => (topicAuthorId === author .id ? ' author' : null ))
81+
7882const style = {
7983 small: {
8084 container: ' py-3' ,
Original file line number Diff line number Diff line change 1919 <p class =" mx-2 font-size-3.5 font-[var(--vp-font-family-subtitle)]" >
2020 {{ data?.user.username }}
2121 </p >
22- <ForumRuleBadge :author-id =" data.user.id" />
22+ <ForumRoleBadge :author-id =" data.user.id" />
2323
2424 <span class =" color-[--vp-c-text-3]" >·</span >
2525
@@ -85,7 +85,7 @@ import { computed, watchEffect } from 'vue'
8585import { useRequest } from ' vue-request'
8686import { toast } from ' vue-sonner'
8787import ForumAside from ' ../ForumAside.vue'
88- import ForumRuleBadge from ' ../ForumRuleBadge .vue'
88+ import ForumRoleBadge from ' ../ForumRoleBadge .vue'
8989import ForumTagList from ' ../ForumTagList.vue'
9090import { getTopicNumber , setPageTitle } from ' ../utils'
9191import ForumCommentArea from ' ../ForumCommentArea.vue'
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ const userRolesMap = {
2020type Role = keyof typeof rolesPermissions
2121type Permission = ( typeof rolesPermissions ) [ Role ] [ number ]
2222
23- export const useRuleChecks = ( inputId ? : string | number ) => {
23+ export const useRuleChecks = ( inputId : string | number = '' ) => {
2424 const userInfo = useUserInfoStore ( )
2525 const id = computed ( ( ) => userInfo . info ?. id || 0 )
2626
@@ -31,7 +31,7 @@ export const useRuleChecks = (inputId?: string | number) => {
3131 } )
3232
3333 const userRoles = computed ( ( ) : Array < Role > => {
34- return id . value === String ( userInfo . info ?. id )
34+ return String ( inputId ) === String ( userInfo . info ?. id )
3535 ? [ ...staticRoles . value , 'author' ]
3636 : staticRoles . value
3737 } )
@@ -62,10 +62,21 @@ export const useRuleChecks = (inputId?: string | number) => {
6262 const hasAllRoles = ( ...roles : Role [ ] ) =>
6363 computed ( ( ) => roles . every ( ( role ) => userRoles . value . includes ( role ) ) )
6464
65+ const isOfficial = ( userId : string | number ) => {
66+ return computed ( ( ) => {
67+ userId ??= id . value
68+ return (
69+ userRolesMap . feedbackMember . has ( Number ( userId ) ) ||
70+ userRolesMap . teamMember . has ( Number ( userId ) )
71+ )
72+ } )
73+ }
74+
6575 return {
6676 hasAnyPermissions,
6777 hasAllPermissions,
6878 hasAnyRoles,
6979 hasAllRoles,
80+ isOfficial,
7081 }
7182}
You can’t perform that action at this time.
0 commit comments