1
- import { computed , ref } from 'vue' ;
2
- import { useI18n } from 'vue-i18n' ;
1
+ import { computed , ref } from 'vue'
2
+ import { useI18n } from 'vue-i18n'
3
3
import { useMessageRelUserStore } from "../store/messageRelUserStore"
4
4
import { useSecurityStore } from "../store/securityStore"
5
5
import { usePlatformConfig } from "../store/platformConfig"
6
- import axios from 'axios' ;
6
+ import axios from 'axios'
7
7
import { useSocialInfo } from "./useSocialInfo"
8
8
import { storeToRefs } from "pinia"
9
9
@@ -15,60 +15,65 @@ export function useSocialMenuItems() {
15
15
const invitationsCount = ref ( 0 ) ;
16
16
const groupLink = ref ( { name : "UserGroupShow" } ) ;
17
17
18
- const { isCurrentUser} = useSocialInfo ( )
18
+ const { isCurrentUser } = useSocialInfo ( )
19
19
const { user } = storeToRefs ( securityStore )
20
20
21
- const unreadMessagesCount = computed ( ( ) => messageRelUserStore . countUnread ) ;
22
- const globalForumsCourse = computed ( ( ) => platformConfigStore . getSetting ( "forum.global_forums_course_id" ) ) ;
21
+ const unreadMessagesCount = computed ( ( ) => messageRelUserStore . countUnread )
22
+ const globalForumsCourse = computed ( ( ) => platformConfigStore . getSetting ( "forum.global_forums_course_id" ) )
23
+ const hideSocialGroupBlock = computed ( ( ) => platformConfigStore . getSetting ( "social.hide_social_groups_block" ) === "true" )
24
+
23
25
const isValidGlobalForumsCourse = computed ( ( ) => {
24
- const courseId = globalForumsCourse . value ;
25
- return courseId !== null && courseId !== undefined && courseId > 0 ;
26
+ const courseId = globalForumsCourse . value
27
+ return courseId !== null && courseId !== undefined && courseId > 0
26
28
} ) ;
27
29
28
30
const fetchInvitationsCount = async ( userId ) => {
29
- if ( ! userId ) return ;
31
+ if ( ! userId ) return
30
32
try {
31
- const { data } = await axios . get ( `/social-network/invitations/count/${ userId } ` ) ;
32
- invitationsCount . value = data . totalInvitationsCount ;
33
+ const { data } = await axios . get ( `/social-network/invitations/count/${ userId } ` )
34
+ invitationsCount . value = data . totalInvitationsCount
33
35
} catch ( error ) {
34
- console . error ( "Error fetching invitations count:" , error ) ;
36
+ console . error ( "Error fetching invitations count:" , error )
35
37
}
36
38
} ;
37
39
38
40
const getGroupLink = async ( ) => {
39
41
try {
40
- const response = await axios . get ( "/social-network/get-forum-link" ) ;
42
+ const response = await axios . get ( "/social-network/get-forum-link" )
41
43
if ( isValidGlobalForumsCourse . value ) {
42
- groupLink . value = response . data . go_to ;
44
+ groupLink . value = response . data . go_to
43
45
} else {
44
- groupLink . value = { name : "UserGroupList" } ;
46
+ groupLink . value = { name : "UserGroupList" }
45
47
}
46
48
} catch ( error ) {
47
- console . error ( "Error fetching forum link:" , error ) ;
48
- groupLink . value = { name : "UserGroupList" } ;
49
+ console . error ( "Error fetching forum link:" , error )
50
+ groupLink . value = { name : "UserGroupList" }
49
51
}
50
52
} ;
51
53
52
- console . log ( 'user.value ::: ' , user . value . id )
53
-
54
54
if ( user . value && user . value . id ) {
55
- fetchInvitationsCount ( user . value . id ) ;
56
- getGroupLink ( ) ;
55
+ fetchInvitationsCount ( user . value . id )
56
+ getGroupLink ( )
57
57
}
58
58
59
59
const items = computed ( ( ) => {
60
- return isCurrentUser . value ? [
60
+ const menuItems = [
61
61
{ icon : 'mdi mdi-home' , label : t ( "Home" ) , route : '/social' } ,
62
62
{ icon : 'mdi mdi-email' , label : t ( "Messages" ) , route : '/resources/messages' , badgeCount : unreadMessagesCount . value } ,
63
63
{ icon : 'mdi mdi-handshake' , label : t ( "My friends" ) , route : { name : 'UserRelUserList' } } ,
64
- { icon : 'mdi mdi-group' , label : t ( "Social groups" ) , route : groupLink . value , isLink : isValidGlobalForumsCourse . value } ,
65
64
{ icon : 'mdi mdi-briefcase' , label : t ( "My files" ) , route : { name : 'PersonalFileList' , params : { node : securityStore . user . resourceNode . id } } } ,
66
65
{ icon : 'mdi mdi-account' , label : t ( "Personal data" ) , route : '/resources/users/personal_data' } ,
67
- ] : [
66
+ ]
67
+
68
+ if ( ! hideSocialGroupBlock . value ) {
69
+ menuItems . splice ( 3 , 0 , { icon : 'mdi mdi-group' , label : t ( "Social groups" ) , route : groupLink . value , isLink : isValidGlobalForumsCourse . value } )
70
+ }
71
+
72
+ return isCurrentUser . value ? menuItems : [
68
73
{ icon : 'mdi mdi-home' , label : t ( "Home" ) , route : '/social' } ,
69
74
{ icon : 'mdi mdi-email' , label : t ( "Send message" ) , link : `/main/inc/ajax/user_manager.ajax.php?a=get_user_popup&user_id=${ user . value . id } ` , isExternal : true }
70
- ] ;
71
- } ) ;
75
+ ]
76
+ } )
72
77
73
- return { items } ;
78
+ return { items }
74
79
}
0 commit comments