Files
VRCX/src/components/sidebar/GroupsSidebar.vue
pa 51a1897a76 feat: groups sidebar collapsible (#1094)
* wip

* wip

* add prettier formatter config for pug files

* feat: groups sidebar collapsible (#1079)

* rm old code
2025-01-25 05:30:07 +13:00

95 lines
3.4 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div class="x-friend-list" style="padding: 10px 5px">
<template v-for="(group, index) in groupedGroupInstances">
<div
:key="getGroupId(group)"
class="x-friend-group x-link sidebar-group-title"
:style="{ paddingTop: index === 0 ? '0px' : '10px' }"
>
<div @click="toggleGroupSidebarCollapse(getGroupId(group))" style="display: flex; align-items: center">
<i
class="el-icon-arrow-right"
:class="{ rotate: !groupInstancesCfg[getGroupId(group)].isCollapsed }"
></i>
<span style="margin-left: 5px">{{ group[0].group.name }} {{ group.length }}</span>
</div>
</div>
<div
v-if="!groupInstancesCfg[getGroupId(group)].isCollapsed"
v-for="ref in group"
:key="ref.instance.id"
class="x-friend-item"
@click="showGroupDialog(ref.instance.ownerId)"
>
<div class="avatar">
<img v-lazy="ref.group.iconUrl" />
</div>
<div class="detail">
<span class="name">
<span v-text="ref.group.name"></span>
<span style="font-weight: normal; margin-left: 5px"
>({{ ref.instance.userCount }}/{{ ref.instance.capacity }})</span
>
</span>
<location class="extra" :location="ref.instance.location" :link="false" />
</div>
</div>
</template>
</div>
</template>
<script>
export default {
name: 'GroupsSidebar',
props: {
groupInstances: {
type: Array,
default: () => []
}
},
data() {
return {
// temporary, sort feat not yet done
// may be the data structure to be changed
groupInstancesCfg: []
};
},
computed: {
groupedGroupInstances() {
const groupMap = new Map();
this.groupInstances.forEach((ref) => {
const groupId = ref.group.groupId;
if (!groupMap.has(groupId)) {
groupMap.set(groupId, []);
}
groupMap.get(groupId).push(ref);
if (!this.groupInstancesCfg[ref.group?.groupId]) {
this.groupInstancesCfg = {
[ref.group.groupId]: {
isCollapsed: false
},
...this.groupInstancesCfg
};
}
});
return Array.from(groupMap.values());
}
},
methods: {
toggleGroupSidebarCollapse(groupId) {
this.groupInstancesCfg[groupId].isCollapsed = !this.groupInstancesCfg[groupId].isCollapsed;
},
showGroupDialog(ownerId) {
this.$emit('show-group-dialog', ownerId);
},
getGroupId(group) {
return group[0]?.group?.groupId || '';
}
}
};
</script>