Skip to content

Commit 934946f

Browse files
Merge pull request #5503 from christianbeeznest/fixes-updates26
Social: Add missing file useSocialMenuItems - refs BT#21101
2 parents 693ac18 + 6c5af9d commit 934946f

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { computed, ref } from 'vue';
2+
import { useI18n } from 'vue-i18n';
3+
import { useMessageRelUserStore } from "../store/messageRelUserStore"
4+
import { useSecurityStore } from "../store/securityStore"
5+
import { usePlatformConfig } from "../store/platformConfig"
6+
import axios from 'axios';
7+
import { useSocialInfo } from "./useSocialInfo"
8+
import { storeToRefs } from "pinia"
9+
10+
export function useSocialMenuItems() {
11+
const { t } = useI18n();
12+
const messageRelUserStore = useMessageRelUserStore();
13+
const securityStore = useSecurityStore();
14+
const platformConfigStore = usePlatformConfig();
15+
const invitationsCount = ref(0);
16+
const groupLink = ref({ name: "UserGroupShow" });
17+
18+
const { isCurrentUser} = useSocialInfo()
19+
const { user } = storeToRefs(securityStore)
20+
21+
const unreadMessagesCount = computed(() => messageRelUserStore.countUnread);
22+
const globalForumsCourse = computed(() => platformConfigStore.getSetting("forum.global_forums_course_id"));
23+
const isValidGlobalForumsCourse = computed(() => {
24+
const courseId = globalForumsCourse.value;
25+
return courseId !== null && courseId !== undefined && courseId > 0;
26+
});
27+
28+
const fetchInvitationsCount = async (userId) => {
29+
if (!userId) return;
30+
try {
31+
const { data } = await axios.get(`/social-network/invitations/count/${userId}`);
32+
invitationsCount.value = data.totalInvitationsCount;
33+
} catch (error) {
34+
console.error("Error fetching invitations count:", error);
35+
}
36+
};
37+
38+
const getGroupLink = async () => {
39+
try {
40+
const response = await axios.get("/social-network/get-forum-link");
41+
if (isValidGlobalForumsCourse.value) {
42+
groupLink.value = response.data.go_to;
43+
} else {
44+
groupLink.value = { name: "UserGroupList" };
45+
}
46+
} catch (error) {
47+
console.error("Error fetching forum link:", error);
48+
groupLink.value = { name: "UserGroupList" };
49+
}
50+
};
51+
52+
console.log('user.value ::: ', user.value.id)
53+
54+
if (user.value && user.value.id) {
55+
fetchInvitationsCount(user.value.id);
56+
getGroupLink();
57+
}
58+
59+
const items = computed(() => {
60+
return isCurrentUser.value ? [
61+
{ icon: 'mdi mdi-home', label: t("Home"), route: '/social' },
62+
{ icon: 'mdi mdi-email', label: t("Messages"), route: '/resources/messages', badgeCount: unreadMessagesCount.value },
63+
{ icon: 'mdi mdi-mailbox', label: t("Invitations"), route: { name: 'Invitations' }, badgeCount: invitationsCount.value },
64+
{ icon: 'mdi mdi-handshake', label: t("My friends"), route: { name: 'UserRelUserList' } },
65+
{ icon: 'mdi mdi-group', label: t("Social groups"), route: groupLink.value, isLink: isValidGlobalForumsCourse.value },
66+
{ icon: 'mdi mdi-magnify', label: t("Search"), route: '/social/search' },
67+
{ icon: 'mdi mdi-briefcase', label: t("My files"), route: { name: 'PersonalFileList', params: { node: securityStore.user.resourceNode.id } } },
68+
{ icon: 'mdi mdi-account', label: t("Personal data"), route: '/resources/users/personal_data' },
69+
{ icon: 'mdi mdi-star', label: t("Promoted messages"), route: { path: '/social', query: { filterType: 'promoted' } } }
70+
] : [
71+
{ icon: 'mdi mdi-home', label: t("Home"), route: '/social' },
72+
{ 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 }
73+
];
74+
});
75+
76+
return { items };
77+
}

0 commit comments

Comments
 (0)