Chamilo is a learning management system focused on ease of use and accessibility
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
chamilo-lms/assets/vue/composables/useSocialInfo.js

48 lines
1.1 KiB

import { ref, readonly } from 'vue';
import { useStore } from 'vuex';
import { useRoute } from 'vue-router';
export function useSocialInfo() {
const store = useStore();
const route = useRoute();
const user = ref({});
const isCurrentUser = ref(true);
const groupInfo = ref({});
const isGroup = ref(false);
const loadGroup = async (groupId) => {
if (groupId) {
try {
groupInfo.value = await store.dispatch("usergroups/load", groupId);
isGroup.value = true;
} catch (error) {
groupInfo.value = {};
isGroup.value = false;
}
} else {
isGroup.value = false;
groupInfo.value = {};
}
};
const loadUser = async () => {
if (route.query.id) {
await loadGroup(route.query.id);
isCurrentUser.value = false;
} else {
user.value = store.getters["security/getUser"];
isCurrentUser.value = true;
}
};
return {
user: readonly(user),
isCurrentUser: readonly(isCurrentUser),
groupInfo: readonly(groupInfo),
isGroup: readonly(isGroup),
loadGroup,
loadUser
};
}