Load avatars/worlds on tab click

This commit is contained in:
Natsumi
2021-04-30 15:39:27 +12:00
parent 556cf4c681
commit c920b6607d
2 changed files with 77 additions and 23 deletions
+76 -22
View File
@@ -1421,7 +1421,7 @@ speechSynthesis.getVoices();
} }
} }
var array = Array.from(map.values()); var array = Array.from(map.values());
$app.setUserDialogWorlds(array); $app.sortUserDialogWorlds(array);
} }
}); });
@@ -1816,7 +1816,7 @@ speechSynthesis.getVoices();
} }
} }
var array = Array.from(map.values()); var array = Array.from(map.values());
$app.setUserDialogAvatars(array); $app.sortUserDialogAvatars(array);
} }
}); });
@@ -7667,6 +7667,8 @@ speechSynthesis.getVoices();
D.memo = this.loadMemo(userId); D.memo = this.loadMemo(userId);
D.visible = true; D.visible = true;
D.loading = true; D.loading = true;
D.avatars = [];
D.worlds = [];
API.getCachedUser({ API.getCachedUser({
userId userId
}).catch((err) => { }).catch((err) => {
@@ -7699,23 +7701,27 @@ speechSynthesis.getVoices();
} }
D.isFavorite = API.cachedFavoritesByObjectId.has(D.id); D.isFavorite = API.cachedFavoritesByObjectId.has(D.id);
this.applyUserDialogLocation(); this.applyUserDialogLocation();
var worlds = []; if (this.$refs.userDialogTabs.currentName === '0') {
for (var ref of API.cachedWorlds.values()) { this.userDialogLastActiveTab = 'Info';
if (ref.authorId === D.id) { } else if (this.$refs.userDialogTabs.currentName === '1') {
worlds.push(ref); this.userDialogLastActiveTab = 'Worlds';
this.setUserDialogWorlds(userId);
if (this.userDialogLastWorld !== userId) {
this.userDialogLastWorld = userId;
this.refreshUserDialogWorlds();
}
} else if (this.$refs.userDialogTabs.currentName === '2') {
this.userDialogLastActiveTab = 'Avatars';
this.setUserDialogAvatars(userId);
if (this.userDialogLastAvatar !== userId) {
this.userDialogLastAvatar = userId;
if ((userId === API.currentUser.id) && (D.avatars.length === 0)) {
this.refreshUserDialogAvatars();
} }
} }
this.setUserDialogWorlds(worlds); } else if (this.$refs.userDialogTabs.currentName === '3') {
var avatars = []; this.userDialogLastActiveTab = 'JSON';
for (var ref of API.cachedAvatars.values()) {
if (ref.authorId === D.id) {
avatars.push(ref);
} }
}
this.setUserDialogAvatars(avatars);
D.avatars = avatars;
D.isWorldsLoading = false;
D.isAvatarsLoading = false;
API.getFriendStatus({ API.getFriendStatus({
userId: D.id userId: D.id
}); });
@@ -7836,7 +7842,17 @@ speechSynthesis.getVoices();
} }
}; };
$app.methods.setUserDialogWorlds = function (array) { $app.methods.setUserDialogWorlds = function (userId) {
var worlds = [];
for (var ref of API.cachedWorlds.values()) {
if (ref.authorId === userId) {
worlds.push(ref);
}
}
this.sortUserDialogWorlds(worlds);
};
$app.methods.sortUserDialogWorlds = function (array) {
var D = this.userDialog; var D = this.userDialog;
if (D.worldSorting === 'update') { if (D.worldSorting === 'update') {
array.sort(compareByUpdatedAt); array.sort(compareByUpdatedAt);
@@ -7846,7 +7862,17 @@ speechSynthesis.getVoices();
D.worlds = array; D.worlds = array;
}; };
$app.methods.setUserDialogAvatars = function (array) { $app.methods.setUserDialogAvatars = function (userId) {
var avatars = [];
for (var ref of API.cachedAvatars.values()) {
if (ref.authorId === userId) {
avatars.push(ref);
}
}
this.sortUserDialogAvatars(avatars);
};
$app.methods.sortUserDialogAvatars = function (array) {
var D = this.userDialog; var D = this.userDialog;
if (D.avatarSorting === 'update') { if (D.avatarSorting === 'update') {
array.sort(compareByUpdatedAt); array.sort(compareByUpdatedAt);
@@ -7896,7 +7922,7 @@ speechSynthesis.getVoices();
done: () => { done: () => {
if (D.id === params.userId) { if (D.id === params.userId) {
var array = Array.from(map.values()); var array = Array.from(map.values());
this.setUserDialogWorlds(array); this.sortUserDialogWorlds(array);
} }
D.isWorldsLoading = false; D.isWorldsLoading = false;
} }
@@ -7940,7 +7966,7 @@ speechSynthesis.getVoices();
}, },
done: () => { done: () => {
var array = Array.from(map.values()); var array = Array.from(map.values());
this.setUserDialogAvatars(array); this.sortUserDialogAvatars(array);
D.isAvatarsLoading = false; D.isAvatarsLoading = false;
if (fileId) { if (fileId) {
D.loading = false; D.loading = false;
@@ -8133,12 +8159,12 @@ speechSynthesis.getVoices();
$app.methods.changeUserDialogWorldSorting = function () { $app.methods.changeUserDialogWorldSorting = function () {
var D = this.userDialog; var D = this.userDialog;
this.setUserDialogWorlds(D.worlds); this.sortUserDialogWorlds(D.worlds);
}; };
$app.methods.changeUserDialogAvatarSorting = function () { $app.methods.changeUserDialogAvatarSorting = function () {
var D = this.userDialog; var D = this.userDialog;
this.setUserDialogAvatars(D.avatars); this.sortUserDialogAvatars(D.avatars);
}; };
$app.computed.userDialogAvatars = function () { $app.computed.userDialogAvatars = function () {
@@ -10844,6 +10870,34 @@ speechSynthesis.getVoices();
this.discordNamesDialogVisible = true; this.discordNamesDialogVisible = true;
}; };
// userDialog world/avatar tab click
$app.data.userDialogLastActiveTab = '';
$app.data.userDialogLastAvatar = '';
$app.data.userDialogLastWorld = '';
$app.methods.userDialogTabClick = function (obj) {
var userId = this.userDialog.id;
if (this.userDialogLastActiveTab === obj.label) {
return;
}
if (obj.label === 'Avatars') {
this.setUserDialogAvatars(userId);
if (this.userDialogLastAvatar !== userId) {
if ((userId === API.currentUser.id) && (this.userDialog.avatars.length === 0)) {
this.refreshUserDialogAvatars();
}
}
} else if (obj.label === 'Worlds') {
this.setUserDialogWorlds(userId);
if (this.userDialogLastWorld !== userId) {
this.userDialogLastWorld = userId;
this.refreshUserDialogWorlds();
}
}
this.userDialogLastActiveTab = obj.label;
};
$app = new Vue($app); $app = new Vue($app);
window.$app = $app; window.$app = $app;
}()); }());
+1 -1
View File
@@ -1041,7 +1041,7 @@ html
el-dropdown-item(v-else icon="el-icon-user" command="Hide Avatar") Hide Avatar el-dropdown-item(v-else icon="el-icon-user" command="Hide Avatar") Hide Avatar
template(v-if="userDialog.isFriend") template(v-if="userDialog.isFriend")
el-dropdown-item(icon="el-icon-delete" command="Unfriend" divided) Unfriend el-dropdown-item(icon="el-icon-delete" command="Unfriend" divided) Unfriend
el-tabs el-tabs(ref="userDialogTabs" @tab-click="userDialogTabClick")
el-tab-pane(label="Info") el-tab-pane(label="Info")
div(v-if="userDialog.ref.location" style="display:flex;flex-direction:column;margin-bottom:10px;padding-bottom:10px;border-bottom:1px solid #eee") div(v-if="userDialog.ref.location" style="display:flex;flex-direction:column;margin-bottom:10px;padding-bottom:10px;border-bottom:1px solid #eee")
div(style="flex:none") div(style="flex:none")