Split component, improve UI, fix and refactor (#1162)

This commit is contained in:
pa
2025-03-01 16:12:21 +09:00
committed by GitHub
parent ef68e40996
commit b988f45f8c
28 changed files with 1098 additions and 791 deletions

View File

@@ -7,8 +7,9 @@
class="location"
:location="activityDetailData[0].location"
is-open-previous-instance-info-dialog
@open-previous-instance-info-dialog="$emit('open-previous-instance-info-dialog', $event)"
></location>
@open-previous-instance-info-dialog="
$emit('open-previous-instance-info-dialog', $event)
"></location>
</transition>
</div>
@@ -19,9 +20,13 @@
<script>
import dayjs from 'dayjs';
import utils from '../../classes/utils';
import Location from '../common/Location.vue';
export default {
name: 'InstanceActivityDetail',
components: {
Location
},
inject: ['API', 'showUserDialog'],
props: {
activityDetailData: {

View File

@@ -0,0 +1,157 @@
<template>
<div>
<span v-if="!text" style="color: transparent">-</span>
<span v-show="text">
<span
:class="{ 'x-link': link && location !== 'private' && location !== 'offline' }"
@click="showWorldDialog">
<i v-if="isTraveling" class="el-icon el-icon-loading" style="display: inline-block"></i>
<span>{{ text }}</span>
</span>
<span v-if="groupName" :class="{ 'x-link': link }" @click="showGroupDialog">({{ groupName }})</span>
<span v-if="region" class="flags" :class="region" style="display: inline-block; margin-left: 5px"></span>
<i v-if="strict" class="el-icon el-icon-lock" style="display: inline-block; margin-left: 5px"></i>
</span>
</div>
</template>
<script>
import utils from '../../classes/utils';
export default {
// eslint-disable-next-line vue/multi-word-component-names
name: 'Location',
inject: ['API'],
props: {
location: String,
traveling: String,
hint: {
type: String,
default: ''
},
grouphint: {
type: String,
default: ''
},
link: {
type: Boolean,
default: true
},
isOpenPreviousInstanceInfoDialog: Boolean
},
data() {
return {
text: '',
region: this.region,
strict: this.strict,
isTraveling: this.isTraveling,
groupName: this.groupName
};
},
watch: {
location() {
this.parse();
}
},
created() {
this.parse();
},
methods: {
parse() {
if (!this.API) return;
this.isTraveling = false;
this.groupName = '';
let instanceId = this.location;
if (typeof this.traveling !== 'undefined' && this.location === 'traveling') {
instanceId = this.traveling;
this.isTraveling = true;
}
const L = utils.parseLocation(instanceId);
if (L.isOffline) {
this.text = 'Offline';
} else if (L.isPrivate) {
this.text = 'Private';
} else if (L.isTraveling) {
this.text = 'Traveling';
} else if (typeof this.hint === 'string' && this.hint !== '') {
if (L.instanceId) {
this.text = `${this.hint} #${L.instanceName} ${L.accessTypeName}`;
} else {
this.text = this.hint;
}
} else if (L.worldId) {
var ref = this.API.cachedWorlds.get(L.worldId);
if (typeof ref === 'undefined') {
// TODO: USE props
$app.getWorldName(L.worldId).then((worldName) => {
if (L.tag === instanceId) {
if (L.instanceId) {
this.text = `${worldName} #${L.instanceName} ${L.accessTypeName}`;
} else {
this.text = worldName;
}
}
});
} else if (L.instanceId) {
this.text = `${ref.name} #${L.instanceName} ${L.accessTypeName}`;
} else {
this.text = ref.name;
}
}
if (this.grouphint) {
this.groupName = this.grouphint;
} else if (L.groupId) {
this.groupName = L.groupId;
// TODO: USE props
$app.getGroupName(instanceId).then((groupName) => {
if (L.tag === instanceId) {
this.groupName = groupName;
}
});
}
this.region = '';
if (!L.isOffline && !L.isPrivate && !L.isTraveling) {
this.region = L.region;
if (!L.region && L.instanceId) {
this.region = 'us';
}
}
this.strict = L.strict;
},
showWorldDialog() {
if (this.link) {
let instanceId = this.location;
if (this.traveling && this.location === 'traveling') {
instanceId = this.traveling;
}
if (!instanceId && this.hint.length === 8) {
// shortName
this.API.$emit('SHOW_WORLD_DIALOG_SHORTNAME', this.hint);
return;
}
if (this.isOpenPreviousInstanceInfoDialog) {
this.$emit('open-previous-instance-info-dialog', instanceId);
} else {
this.API.$emit('SHOW_WORLD_DIALOG', instanceId);
}
}
},
showGroupDialog() {
let location = this.location;
if (this.isTraveling) {
location = this.traveling;
}
if (!location || !this.link) {
return;
}
const L = utils.parseLocation(location);
if (!L.groupId) {
return;
}
this.API.$emit('SHOW_GROUP_DIALOG', L.groupId);
}
}
};
</script>
<style scoped></style>

View File

@@ -0,0 +1,130 @@
<template>
<div class="x-friend-item" @click="$emit('click')">
<template v-if="friend.ref">
<div
class="avatar"
:class="isFriendActiveOrOffline ? undefined : userStatusClass(friend.ref, friend.pendingOffline)">
<img v-lazy="userImage(friend.ref)" />
</div>
<div class="detail">
<span v-if="!hideNicknames && friend.$nickName" class="name" :style="{ color: friend.ref.$userColour }">
{{ friend.ref.displayName }} ({{ friend.$nickName }})
</span>
<span v-else class="name" :style="{ color: friend.ref.$userColour }"
>{{ friend.ref.displayName }}{{ isGroupByInstance && friend.isVIP ? ' ⭐' : '' }}</span
>
<span v-if="isFriendActiveOrOffline" class="extra">{{ friend.ref.statusDescription }}</span>
<template v-else>
<span v-if="friend.pendingOffline" class="extra">
<i class="el-icon-warning-outline" /> {{ $t('side_panel.pending_offline') }}
</span>
<template v-else-if="isGroupByInstance">
<i v-if="isFriendTraveling" class="el-icon el-icon-loading"></i>
<timer
class="extra"
:epoch="epoch"
:style="
isFriendTraveling ? { display: 'inline-block', overflow: 'unset' } : undefined
"></timer>
</template>
<location
v-else
class="extra"
:location="friend.ref.location"
:traveling="friend.ref.travelingToLocation"
:link="false" />
</template>
</div>
</template>
<template v-else-if="!friend.ref && !API.isRefreshFriendsLoading">
<span>{{ friend.name || friend.id }}</span>
<el-button
ttype="text"
icon="el-icon-close"
size="mini"
style="margin-left: 5px"
@click.stop="$emit('confirm-delete-friend', friend.id)">
</el-button>
</template>
<el-skeleton v-else animated class="skeleton" :throttle="100">
<template slot="template">
<div>
<el-skeleton-item variant="circle" />
<div>
<el-skeleton-item variant="text" />
<el-skeleton-item variant="text" />
</div>
</div>
</template>
</el-skeleton>
</div>
</template>
<script>
import Location from '../common/Location.vue';
export default {
name: 'FriendItem',
components: {
Location
},
inject: ['API', 'userImage', 'userStatusClass'],
props: {
friend: {
type: Object,
required: true
},
hideNicknames: {
type: Boolean,
default: false
},
isGroupByInstance: Boolean
},
computed: {
isFriendTraveling() {
return this.friend.ref.location === 'traveling';
},
isFriendActiveOrOffline() {
return this.friend.state === 'active' || this.friend.state === 'offline';
},
epoch() {
return this.isFriendTraveling ? this.friend.ref.$travelingToTime : this.friend.ref.$location_at;
}
}
};
</script>
<style scoped>
.skeleton {
height: 40px;
width: 100%;
::v-deep .el-skeleton {
height: 100%;
> div {
height: 100%;
display: flex;
align-items: center;
> :first-child {
margin-right: 8px;
height: 40px;
width: 40px;
}
> :last-child {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
> :first-child {
width: 50%;
margin-bottom: 4px;
}
> :last-child {
width: 90%;
}
}
}
}
}
</style>

View File

@@ -0,0 +1,373 @@
<template>
<div class="x-friend-list" style="padding: 10px 5px">
<div
class="x-friend-group x-link"
style="padding: 0 0 5px"
@click="
isFriendsGroupMe = !isFriendsGroupMe;
saveFriendsGroupStates();
">
<i class="el-icon-arrow-right" :class="{ rotate: isFriendsGroupMe }"></i>
<span style="margin-left: 5px">{{ $t('side_panel.me') }}</span>
</div>
<div v-show="isFriendsGroupMe">
<div class="x-friend-item" @click="showUserDialog(API.currentUser.id)">
<div class="avatar" :class="userStatusClass(API.currentUser)">
<img v-lazy="userImage(API.currentUser)" />
</div>
<div class="detail">
<span class="name" :style="{ color: API.currentUser.$userColour }">{{
API.currentUser.displayName
}}</span>
<location
v-if="isGameRunning && !gameLogDisabled"
class="extra"
:location="lastLocation.location"
:traveling="lastLocationDestination"
:link="false"></location>
<location
v-else-if="
isRealInstance(API.currentUser.$locationTag) ||
isRealInstance(API.currentUser.$travelingToLocation)
"
class="extra"
:location="API.currentUser.$locationTag"
:traveling="API.currentUser.$travelingToLocation"
:link="false">
</location>
<span v-else class="extra">{{ API.currentUser.statusDescription }}</span>
</div>
</div>
</div>
<div
v-show="vipFriendsByGroupStatus.length"
class="x-friend-group x-link"
@click="
isVIPFriends = !isVIPFriends;
saveFriendsGroupStates();
">
<i class="el-icon-arrow-right" :class="{ rotate: isVIPFriends }"></i>
<span style="margin-left: 5px">
{{ $t('side_panel.favorite') }} &horbar; {{ vipFriendsByGroupStatus.length }}
</span>
</div>
<div v-show="isVIPFriends">
<template v-if="isSidebarDivideByFriendGroup">
<div v-for="group in vipFriendsDivideByGroup" :key="group[0].key">
<transition name="el-fade-in-linear">
<div v-show="group[0].groupName !== ''" style="margin-bottom: 3px">
<span class="extra">{{ group[0].groupName }}</span>
<span class="extra" style="margin-left: 5px">{{ `(${group.length})` }}</span>
</div>
</transition>
<div v-if="group.length" style="margin-bottom: 10px">
<friend-item
v-for="friend in group"
:key="friend.id"
:friend="friend"
:hide-nicknames="hideNicknames"
@click="showUserDialog(friend.id)"
@confirm-delete-friend="$emit('confirm-delete-friend', $event)"></friend-item>
</div>
</div>
</template>
<friend-item
v-for="friend in vipFriendsByGroupStatus"
v-else
:key="friend.id"
:friend="friend"
:hide-nicknames="hideNicknames"
@click="showUserDialog(friend.id)"
@confirm-delete-friend="$emit('confirm-delete-friend', $event)">
</friend-item>
</div>
<template v-if="isSidebarGroupByInstance && friendsInSameInstance.length">
<div class="x-friend-group x-link" @click="toggleSwitchGroupByInstanceCollapsed">
<i class="el-icon-arrow-right" :class="{ rotate: !isSidebarGroupByInstanceCollapsed }"></i>
<span style="margin-left: 5px"
>{{ $t('side_panel.same_instance') }} &horbar; {{ friendsInSameInstance.length }}</span
>
</div>
<div v-show="!isSidebarGroupByInstanceCollapsed">
<div v-for="friendArr in friendsInSameInstance" :key="friendArr[0].ref.$location.tag">
<div style="margin-bottom: 3px">
<location
class="extra"
:location="getFriendsLocations(friendArr)"
style="display: inline"></location>
<span class="extra" style="margin-left: 5px">{{ `(${friendArr.length})` }}</span>
</div>
<div v-if="friendArr && friendArr.length">
<friend-item
v-for="(friend, idx) in friendArr"
:key="friend.id"
:friend="friend"
is-group-by-instance
:style="{ 'margin-bottom': idx === friendArr.length - 1 ? '5px' : undefined }"
@click="showUserDialog(friend.id)"
@confirm-delete-friend="$emit('confirm-delete-friend', $event)">
</friend-item>
</div>
</div>
</div>
</template>
<div
v-show="onlineFriendsByGroupStatus.length"
class="x-friend-group x-link"
@click="
isOnlineFriends = !isOnlineFriends;
saveFriendsGroupStates();
">
<i class="el-icon-arrow-right" :class="{ rotate: isOnlineFriends }"></i>
<span style="margin-left: 5px"
>{{ $t('side_panel.online') }} &horbar; {{ onlineFriendsByGroupStatus.length }}</span
>
</div>
<div v-show="isOnlineFriends">
<friend-item
v-for="friend in onlineFriendsByGroupStatus"
:key="friend.id"
:friend="friend"
:hide-nicknames="hideNicknames"
@click="showUserDialog(friend.id)"
@confirm-delete-friend="$emit('confirm-delete-friend', $event)" />
</div>
<div
v-show="activeFriends.length"
class="x-friend-group x-link"
@click="
isActiveFriends = !isActiveFriends;
saveFriendsGroupStates();
">
<i class="el-icon-arrow-right" :class="{ rotate: isActiveFriends }"></i>
<span style="margin-left: 5px">{{ $t('side_panel.active') }} &horbar; {{ activeFriends.length }}</span>
</div>
<div v-show="isActiveFriends">
<friend-item
v-for="friend in activeFriends"
:key="friend.id"
:friend="friend"
:hide-nicknames="hideNicknames"
@click="showUserDialog(friend.id)"
@confirm-delete-friend="$emit('confirm-delete-friend', $event)"></friend-item>
</div>
<div
v-show="offlineFriends.length"
class="x-friend-group x-link"
@click="
isOfflineFriends = !isOfflineFriends;
saveFriendsGroupStates();
">
<i class="el-icon-arrow-right" :class="{ rotate: isOfflineFriends }"></i>
<span style="margin-left: 5px">{{ $t('side_panel.offline') }} &horbar; {{ offlineFriends.length }}</span>
</div>
<div v-show="isOfflineFriends">
<friend-item
v-for="friend in offlineFriends"
:key="friend.id"
:friend="friend"
:hide-nicknames="hideNicknames"
@click="showUserDialog(friend.id)"
@confirm-delete-friend="$emit('confirm-delete-friend', $event)"></friend-item>
</div>
</div>
</template>
<script>
import FriendItem from './FriendItem.vue';
import Location from '../common/Location.vue';
import configRepository from '../../repository/config';
import utils from '../../classes/utils';
export default {
name: 'FriendsSidebar',
components: {
FriendItem,
Location
},
inject: ['API', 'showUserDialog', 'userImage', 'userStatusClass'],
props: {
// settings
isGameRunning: Boolean,
isSidebarDivideByFriendGroup: Boolean,
isSidebarGroupByInstance: Boolean,
gameLogDisabled: Boolean,
hideNicknames: Boolean,
isHideFriendsInSameInstance: Boolean,
lastLocation: Object,
lastLocationDestination: String,
activeFriends: Array,
offlineFriends: Array,
vipFriends: Array,
onlineFriends: Array,
groupedByGroupKeyFavoriteFriends: Object
},
data() {
return {
isFriendsGroupMe: true,
isVIPFriends: true,
isOnlineFriends: true,
isActiveFriends: true,
isOfflineFriends: true,
isSidebarGroupByInstanceCollapsed: false
};
},
computed: {
friendsInSameInstance() {
const friendsList = {};
const allFriends = [...this.vipFriends, ...this.onlineFriends];
allFriends.forEach((friend) => {
let locationTag;
if (friend.ref?.$location.isRealInstance) {
locationTag = friend.ref.$location.tag;
} else if (this.lastLocation.friendList.has(friend.id)) {
let $location = utils.parseLocation(this.lastLocation.location);
if ($location.isRealInstance) {
if ($location.tag === 'private') {
locationTag = this.lastLocation.name;
} else {
locationTag = $location.tag;
}
}
}
if (!locationTag) {
return;
}
if (!friendsList[locationTag]) {
friendsList[locationTag] = [];
}
friendsList[locationTag].push(friend);
});
const sortedFriendsList = [];
for (const group of Object.values(friendsList)) {
if (group.length > 1) {
sortedFriendsList.push(group.sort((a, b) => a.ref?.$location_at - b.ref?.$location_at));
}
}
return sortedFriendsList.sort((a, b) => b.length - a.length);
},
onlineFriendsByGroupStatus() {
if (
!this.isSidebarGroupByInstance ||
(this.isSidebarGroupByInstance && !this.isHideFriendsInSameInstance)
) {
return this.onlineFriends;
}
const sameInstanceTag = new Set(
this.friendsInSameInstance.flatMap((item) => item.map((friend) => friend.ref?.$location.tag))
);
return this.onlineFriends.filter((item) => !sameInstanceTag.has(item.ref?.$location.tag));
},
vipFriendsByGroupStatus() {
if (
!this.isSidebarGroupByInstance ||
(this.isSidebarGroupByInstance && !this.isHideFriendsInSameInstance)
) {
return this.vipFriends;
}
const sameInstanceTag = new Set(
this.friendsInSameInstance.flatMap((item) => item.map((friend) => friend.ref?.$location.tag))
);
return this.vipFriends.filter((item) => !sameInstanceTag.has(item.ref?.$location.tag));
},
// VIP friends divide by group
vipFriendsDivideByGroup() {
const vipFriendsByGroup = { ...this.groupedByGroupKeyFavoriteFriends };
const result = [];
for (const key in vipFriendsByGroup) {
if (Object.prototype.hasOwnProperty.call(vipFriendsByGroup, key)) {
const groupFriends = vipFriendsByGroup[key];
// sort groupFriends using the order of vipFriends
// avoid unnecessary sorting
let filteredFriends = this.vipFriends.filter((friend) =>
groupFriends.some((item) => item.id === friend.id)
);
if (filteredFriends.length > 0) {
const groupName =
this.API.favoriteFriendGroups.find((item) => item.key === key)?.displayName || '';
result.push(filteredFriends.map((item) => ({ groupName, key, ...item })));
}
}
}
return result.sort((a, b) => a[0].key.localeCompare(b[0].key));
}
},
created() {
configRepository.getBool('VRCX_sidebarGroupByInstanceCollapsed', false).then((value) => {
this.isSidebarGroupByInstanceCollapsed = value;
});
},
methods: {
saveFriendsGroupStates() {
configRepository.setBool('VRCX_isFriendsGroupMe', this.isFriendsGroupMe);
configRepository.setBool('VRCX_isFriendsGroupFavorites', this.isVIPFriends);
configRepository.setBool('VRCX_isFriendsGroupOnline', this.isOnlineFriends);
configRepository.setBool('VRCX_isFriendsGroupActive', this.isActiveFriends);
configRepository.setBool('VRCX_isFriendsGroupOffline', this.isOfflineFriends);
},
async loadFriendsGroupStates() {
this.isFriendsGroupMe = await configRepository.getBool('VRCX_isFriendsGroupMe', true);
this.isVIPFriends = await configRepository.getBool('VRCX_isFriendsGroupFavorites', true);
this.isOnlineFriends = await configRepository.getBool('VRCX_isFriendsGroupOnline', true);
this.isActiveFriends = await configRepository.getBool('VRCX_isFriendsGroupActive', false);
this.isOfflineFriends = await configRepository.getBool('VRCX_isFriendsGroupOffline', false);
},
isRealInstance(locationTag) {
return utils.isRealInstance(locationTag);
},
toggleSwitchGroupByInstanceCollapsed() {
this.isSidebarGroupByInstanceCollapsed = !this.isSidebarGroupByInstanceCollapsed;
configRepository.setBool(
'VRCX_sidebarGroupByInstanceCollapsed',
this.isSidebarGroupByInstanceCollapsed
);
},
getFriendsLocations(friendsArr) {
// prevent the instance title display as "Traveling".
if (!friendsArr?.length) {
return '';
}
for (const friend of friendsArr) {
if (friend.ref?.location !== 'traveling') {
return friend.ref.location;
}
if (utils.isRealInstance(friend.ref?.travelingToLocation)) {
return friend.ref.travelingToLocation;
}
if (this.lastLocation.friendList.has(friend.id)) {
return this.lastLocation.name;
}
}
return friendsArr[0].ref?.location;
}
}
};
</script>
<style scoped>
.x-link:hover {
text-decoration: none;
}
.x-link:hover span {
text-decoration: underline;
}
</style>

View File

@@ -4,47 +4,50 @@
<div
:key="getGroupId(group)"
class="x-friend-group x-link"
:style="{ paddingTop: index === 0 ? '0px' : '10px' }"
>
:style="{ paddingTop: index === 0 ? '0px' : '10px' }">
<div @click="toggleGroupSidebarCollapse(getGroupId(group))" style="display: flex; align-items: center">
<i
class="el-icon-arrow-right"
:style="{
transform: groupInstancesCfg[getGroupId(group)].isCollapsed ? '' : 'rotate(90deg)',
transition: 'transform 0.3s'
}"
></i>
}"></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" />
<template v-if="!groupInstancesCfg[getGroupId(group)].isCollapsed">
<div
v-for="ref in group"
:key="ref.instance.id"
class="x-friend-item"
@click="$emit('show-group-dialog', 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>
<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>
</template>
</div>
</template>
<script>
import Location from '../common/Location.vue';
export default {
name: 'GroupsSidebar',
components: {
Location
},
props: {
groupInstances: {
type: Array,