refactor: app.js (#1291)

* refactor: frontend

* Fix avatar gallery sort

* Update .NET dependencies

* Update npm dependencies

electron v37.1.0

* bulkRefreshFriends

* fix dark theme

* Remove crowdin

* Fix config.json dialog not updating

* VRCX log file fixes & add Cef log

* Remove SharedVariable, fix startup

* Revert init theme change

* Logging date not working? Fix WinformThemer designer error

* Add Cef request hander, no more escaping main page

* clean

* fix

* fix

* clean

* uh

* Apply thememode at startup, fixes random user colours

* Split database into files

* Instance info remove empty lines

* Open external VRC links with VRCX

* Electron fixes

* fix userdialog style

* ohhhh

* fix store

* fix store

* fix: load all group members after kicking a user

* fix: world dialog favorite button style

* fix: Clear VRCX Cache Timer input value

* clean

* Fix VR overlay

* Fix VR overlay 2

* Fix Discord discord rich presence for RPC worlds

* Clean up age verified user tags

* Fix playerList being occupied after program reload

* no `this`

* Fix login stuck loading

* writable: false

* Hide dialogs on logout

* add flush sync option

* rm LOGIN event

* rm LOGOUT event

* remove duplicate event listeners

* remove duplicate event listeners

* clean

* remove duplicate event listeners

* clean

* fix theme style

* fix t

* clearable

* clean

* fix ipcEvent

* Small changes

* Popcorn Palace support

* Remove checkActiveFriends

* Clean up

* Fix dragEnterCef

* Block API requests when not logged in

* Clear state on login & logout

* Fix worldDialog instances not updating

* use <script setup>

* Fix avatar change event, CheckGameRunning at startup

* Fix image dragging

* fix

* Remove PWI

* fix updateLoop

* add webpack-dev-server to dev environment

* rm unnecessary chunks

* use <script setup>

* webpack-dev-server changes

* use <script setup>

* use <script setup>

* Fix UGC text size

* Split login event

* t

* use <script setup>

* fix

* Update .gitignore and enable checkJs in jsconfig

* fix i18n t

* use <script setup>

* use <script setup>

* clean

* global types

* fix

* use checkJs for debugging

* Add watchState for login watchers

* fix .vue template

* type fixes

* rm Vue.filter

* Cef v138.0.170, VC++ 2022

* Settings fixes

* Remove 'USER:CURRENT'

* clean up 2FA callbacks

* remove userApply

* rm i18n import

* notification handling to use notification store methods

* refactor favorite handling to use favorite store methods and clean up event emissions

* refactor moderation handling to use dedicated functions for player moderation events

* refactor friend handling to use dedicated functions for friend events

* Fix program startup, move lang init

* Fix friend state

* Fix status change error

* Fix user notes diff

* fix

* rm group event

* rm auth event

* rm avatar event

* clean

* clean

* getUser

* getFriends

* getFavoriteWorlds, getFavoriteAvatars

* AvatarGalleryUpload btn style & package.json update

* Fix friend requests

* Apply user

* Apply world

* Fix note diff

* Fix VR overlay

* Fixes

* Update build scripts

* Apply avatar

* Apply instance

* Apply group

* update hidden VRC+ badge

* Fix sameInstance "private"

* fix 502/504 API errors

* fix 502/504 API errors

* clean

* Fix friend in same instance on orange showing twice in friends list

* Add back in broken friend state repair methods

* add types

---------

Co-authored-by: Natsumi <cmcooper123@hotmail.com>
This commit is contained in:
pa
2025-07-14 12:00:08 +09:00
committed by GitHub
parent 952fd77ed5
commit f4f78bb5ec
323 changed files with 47745 additions and 43326 deletions
+184 -279
View File
@@ -2,317 +2,222 @@
<div v-show="menuActiveIndex === 'favorite'" class="x-container">
<div style="font-size: 13px; position: absolute; display: flex; right: 0; z-index: 1; margin-right: 15px">
<div v-if="editFavoritesMode" style="display: inline-block; margin-right: 10px">
<el-button size="small" @click="clearBulkFavoriteSelection">{{ $t('view.favorite.clear') }}</el-button>
<el-button size="small" @click="bulkCopyFavoriteSelection">{{ $t('view.favorite.copy') }}</el-button>
<el-button size="small" @click="clearBulkFavoriteSelection">{{ t('view.favorite.clear') }}</el-button>
<el-button size="small" @click="bulkCopyFavoriteSelection">{{ t('view.favorite.copy') }}</el-button>
<el-button size="small" @click="showBulkUnfavoriteSelectionConfirm">{{
$t('view.favorite.bulk_unfavorite')
t('view.favorite.bulk_unfavorite')
}}</el-button>
</div>
<div style="display: flex; align-items: center; margin-right: 10px">
<span class="name">{{ $t('view.favorite.edit_mode') }}</span>
<span class="name">{{ t('view.favorite.edit_mode') }}</span>
<el-switch v-model="editFavoritesMode" style="margin-left: 5px"></el-switch>
</div>
<el-tooltip placement="bottom" :content="$t('view.favorite.refresh_tooltip')" :disabled="hideTooltips">
<el-tooltip placement="bottom" :content="t('view.favorite.refresh_tooltip')" :disabled="hideTooltips">
<el-button
type="default"
:loading="API.isFavoriteLoading"
@click="
API.refreshFavorites();
getLocalWorldFavorites();
"
:loading="isFavoriteLoading"
size="small"
icon="el-icon-refresh"
circle></el-button>
circle
@click="
refreshFavorites();
getLocalWorldFavorites();
"></el-button>
</el-tooltip>
</div>
<el-tabs v-model="currentTabName" v-loading="API.isFavoriteLoading" type="card" style="height: 100%">
<el-tab-pane name="friend" :label="$t('view.favorite.friends.header')" lazy>
<el-tabs v-model="currentTabName" v-loading="isFavoriteLoading" type="card" style="height: 100%">
<el-tab-pane name="friend" :label="t('view.favorite.friends.header')">
<FavoritesFriendTab
:favorite-friends="favoriteFriends"
:sort-favorites.sync="isSortByTime"
:hide-tooltips="hideTooltips"
:grouped-by-group-key-favorite-friends="groupedByGroupKeyFavoriteFriends"
:edit-favorites-mode="editFavoritesMode"
@show-friend-import-dialog="showFriendImportDialog"
@save-sort-favorites-option="saveSortFavoritesOption"
@change-favorite-group-name="changeFavoriteGroupName" />
</el-tab-pane>
<el-tab-pane name="world" :label="$t('view.favorite.worlds.header')" lazy>
<el-tab-pane name="world" :label="t('view.favorite.worlds.header')" lazy>
<FavoritesWorldTab
@show-world-import-dialog="showWorldImportDialog"
@save-sort-favorites-option="saveSortFavoritesOption"
@change-favorite-group-name="changeFavoriteGroupName"
@new-instance-self-invite="newInstanceSelfInvite"
@refresh-local-world-favorite="refreshLocalWorldFavorites"
@delete-local-world-favorite-group="deleteLocalWorldFavoriteGroup"
@remove-local-world-favorite="removeLocalWorldFavorite"
@rename-local-world-favorite-group="renameLocalWorldFavoriteGroup"
@new-local-world-favorite-group="newLocalWorldFavoriteGroup"
:sort-favorites.sync="isSortByTime"
:hide-tooltips="hideTooltips"
:favorite-worlds="favoriteWorlds"
:edit-favorites-mode="editFavoritesMode"
:shift-held="shiftHeld"
:refresh-local-world-favorites="refreshLocalWorldFavorites"
:local-world-favorite-groups="localWorldFavoriteGroups"
:local-world-favorites="localWorldFavorites"
:local-world-favorites-list="localWorldFavoritesList" />
</el-tab-pane>
<el-tab-pane name="avatar" :label="$t('view.favorite.avatars.header')" lazy>
<FavoritesAvatarTab
:sort-favorites.sync="isSortByTime"
:hide-tooltips="hideTooltips"
:shift-held="shiftHeld"
:edit-favorites-mode="editFavoritesMode"
:avatar-history-array="avatarHistoryArray"
:refreshing-local-favorites="refreshingLocalFavorites"
:local-avatar-favorite-groups="localAvatarFavoriteGroups"
:local-avatar-favorites="localAvatarFavorites"
:favorite-avatars="favoriteAvatars"
:local-avatar-favorites-list="localAvatarFavoritesList"
@show-avatar-import-dialog="showAvatarImportDialog"
@save-sort-favorites-option="saveSortFavoritesOption"
@change-favorite-group-name="changeFavoriteGroupName"
@remove-local-avatar-favorite="removeLocalAvatarFavorite"
@select-avatar-with-confirmation="selectAvatarWithConfirmation"
@prompt-clear-avatar-history="promptClearAvatarHistory"
@prompt-new-local-avatar-favorite-group="promptNewLocalAvatarFavoriteGroup"
@refresh-local-avatar-favorites="refreshLocalAvatarFavorites"
@prompt-local-avatar-favorite-group-rename="promptLocalAvatarFavoriteGroupRename"
@prompt-local-avatar-favorite-group-delete="promptLocalAvatarFavoriteGroupDelete" />
@refresh-local-world-favorite="refreshLocalWorldFavorites" />
</el-tab-pane>
<el-tab-pane name="avatar" :label="t('view.favorite.avatars.header')" lazy>
<FavoritesAvatarTab
:hide-tooltips="hideTooltips"
:edit-favorites-mode="editFavoritesMode"
:refreshing-local-favorites="refreshingLocalFavorites"
@change-favorite-group-name="changeFavoriteGroupName"
@refresh-local-avatar-favorites="refreshLocalAvatarFavorites" />
</el-tab-pane>
</el-tabs>
</div>
</template>
<script>
<script setup>
import { ref, getCurrentInstance } from 'vue';
import { storeToRefs } from 'pinia';
import { useI18n } from 'vue-i18n-bridge';
import * as workerTimers from 'worker-timers';
import { avatarRequest, favoriteRequest, worldRequest } from '../../api';
import { useAppearanceSettingsStore, useFavoriteStore, useUiStore, useAvatarStore } from '../../stores';
import FavoritesAvatarTab from './components/FavoritesAvatarTab.vue';
import FavoritesFriendTab from './components/FavoritesFriendTab.vue';
import FavoritesWorldTab from './components/FavoritesWorldTab.vue';
import FavoritesAvatarTab from './components/FavoritesAvatarTab.vue';
import { avatarRequest, favoriteRequest, worldRequest } from '../../api';
import * as workerTimers from 'worker-timers';
export default {
name: 'FavoritesTab',
components: {
FavoritesFriendTab,
FavoritesWorldTab,
FavoritesAvatarTab
},
inject: ['API'],
props: {
menuActiveIndex: String,
hideTooltips: Boolean,
shiftHeld: Boolean,
favoriteFriends: Array,
sortFavorites: Boolean,
groupedByGroupKeyFavoriteFriends: Object,
favoriteWorlds: Array,
localWorldFavoriteGroups: Array,
localWorldFavorites: Object,
avatarHistoryArray: Array,
localAvatarFavoriteGroups: Array,
localAvatarFavorites: Object,
favoriteAvatars: Array,
localAvatarFavoritesList: Array,
localWorldFavoritesList: Array
},
data() {
return {
editFavoritesMode: false,
refreshingLocalFavorites: false,
currentTabName: 'friend'
};
},
computed: {
isSortByTime: {
get() {
return this.sortFavorites;
},
set(value) {
this.$emit('update:sort-favorites', value);
}
}
},
methods: {
showBulkUnfavoriteSelectionConfirm() {
const elementsTicked = [];
// check favorites type
for (const ctx of this.favoriteFriends) {
if (ctx.$selected) {
elementsTicked.push(ctx.id);
}
}
for (const ctx of this.favoriteWorlds) {
if (ctx.$selected) {
elementsTicked.push(ctx.id);
}
}
for (const ctx of this.favoriteAvatars) {
if (ctx.$selected) {
elementsTicked.push(ctx.id);
}
}
if (elementsTicked.length === 0) {
return;
}
this.$confirm(
`Are you sure you want to unfavorite ${elementsTicked.length} favorites?
This action cannot be undone.`,
`Delete ${elementsTicked.length} favorites?`,
{
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel',
type: 'info',
callback: (action) => {
if (action === 'confirm') {
this.bulkUnfavoriteSelection(elementsTicked);
}
}
}
);
},
const { t } = useI18n();
const { proxy } = getCurrentInstance();
const { hideTooltips } = storeToRefs(useAppearanceSettingsStore());
const {
favoriteFriends,
favoriteWorlds,
favoriteAvatars,
isFavoriteLoading,
localAvatarFavoritesList,
localWorldFavoritesList
} = storeToRefs(useFavoriteStore());
const {
refreshFavorites,
refreshFavoriteGroups,
clearBulkFavoriteSelection,
bulkCopyFavoriteSelection,
getLocalWorldFavorites,
handleFavoriteGroup
} = useFavoriteStore();
const { menuActiveIndex } = storeToRefs(useUiStore());
const { applyAvatar } = useAvatarStore();
bulkUnfavoriteSelection(elementsTicked) {
for (const id of elementsTicked) {
favoriteRequest.deleteFavorite({
objectId: id
});
}
this.editFavoritesMode = false;
},
changeFavoriteGroupName(ctx) {
this.$prompt(
$t('prompt.change_favorite_group_name.description'),
$t('prompt.change_favorite_group_name.header'),
{
distinguishCancelAndClose: true,
cancelButtonText: $t('prompt.change_favorite_group_name.cancel'),
confirmButtonText: $t('prompt.change_favorite_group_name.change'),
inputPlaceholder: $t('prompt.change_favorite_group_name.input_placeholder'),
inputValue: ctx.displayName,
inputPattern: /\S+/,
inputErrorMessage: $t('prompt.change_favorite_group_name.input_error'),
callback: (action, instance) => {
if (action === 'confirm') {
favoriteRequest
.saveFavoriteGroup({
type: ctx.type,
group: ctx.name,
displayName: instance.inputValue
})
.then(() => {
this.$message({
message: $t('prompt.change_favorite_group_name.message.success'),
type: 'success'
});
// load new group name
this.API.refreshFavoriteGroups();
});
}
}
}
);
},
const editFavoritesMode = ref(false);
const refreshingLocalFavorites = ref(false);
const currentTabName = ref('friend');
async refreshLocalAvatarFavorites() {
if (this.refreshingLocalFavorites) {
return;
}
this.refreshingLocalFavorites = true;
for (const avatarId of this.localAvatarFavoritesList) {
if (!this.refreshingLocalFavorites) {
break;
}
try {
await avatarRequest.getAvatar({
avatarId
});
} catch (err) {
console.error(err);
}
await new Promise((resolve) => {
workerTimers.setTimeout(resolve, 1000);
});
}
this.refreshingLocalFavorites = false;
},
async refreshLocalWorldFavorites() {
if (this.refreshingLocalFavorites) {
return;
}
this.refreshingLocalFavorites = true;
for (const worldId of this.localWorldFavoritesList) {
if (!this.refreshingLocalFavorites) {
break;
}
try {
await worldRequest.getWorld({
worldId
});
} catch (err) {
console.error(err);
}
await new Promise((resolve) => {
workerTimers.setTimeout(resolve, 1000);
});
}
this.refreshingLocalFavorites = false;
},
clearBulkFavoriteSelection() {
this.$emit('clear-bulk-favorite-selection');
},
bulkCopyFavoriteSelection() {
this.$emit('bulk-copy-favorite-selection', this.currentTabName);
},
getLocalWorldFavorites() {
this.$emit('get-local-world-favorites');
},
showFriendImportDialog() {
this.$emit('show-friend-import-dialog');
},
saveSortFavoritesOption() {
this.$emit('save-sort-favorites-option');
},
showWorldImportDialog() {
this.$emit('show-world-import-dialog');
},
newInstanceSelfInvite(worldId) {
this.$emit('new-instance-self-invite', worldId);
},
deleteLocalWorldFavoriteGroup(group) {
this.$emit('delete-local-world-favorite-group', group);
},
removeLocalWorldFavorite(worldId, group) {
this.$emit('remove-local-world-favorite', worldId, group);
},
showAvatarImportDialog() {
this.$emit('show-avatar-import-dialog');
},
removeLocalAvatarFavorite(avatarId, group) {
this.$emit('remove-local-avatar-favorite', avatarId, group);
},
selectAvatarWithConfirmation(id) {
this.$emit('select-avatar-with-confirmation', id);
},
promptClearAvatarHistory() {
this.$emit('prompt-clear-avatar-history');
},
promptNewLocalAvatarFavoriteGroup() {
this.$emit('prompt-new-local-avatar-favorite-group');
},
promptLocalAvatarFavoriteGroupRename(group) {
this.$emit('prompt-local-avatar-favorite-group-rename', group);
},
promptLocalAvatarFavoriteGroupDelete(group) {
this.$emit('prompt-local-avatar-favorite-group-delete', group);
},
renameLocalWorldFavoriteGroup(inputValue, group) {
this.$emit('rename-local-world-favorite-group', inputValue, group);
},
newLocalWorldFavoriteGroup(inputValue) {
this.$emit('new-local-world-favorite-group', inputValue);
function showBulkUnfavoriteSelectionConfirm() {
const elementsTicked = [];
// check favorites type
for (const ctx of favoriteFriends.value) {
if (ctx.$selected) {
elementsTicked.push(ctx.id);
}
}
};
for (const ctx of favoriteWorlds.value) {
if (ctx.$selected) {
elementsTicked.push(ctx.id);
}
}
for (const ctx of favoriteAvatars.value) {
if (ctx.$selected) {
elementsTicked.push(ctx.id);
}
}
if (elementsTicked.length === 0) {
return;
}
proxy.$confirm(
`Are you sure you want to unfavorite ${elementsTicked.length} favorites?
This action cannot be undone.`,
`Delete ${elementsTicked.length} favorites?`,
{
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel',
type: 'info',
callback: (action) => {
if (action === 'confirm') {
bulkUnfavoriteSelection(elementsTicked);
}
}
}
);
}
function bulkUnfavoriteSelection(elementsTicked) {
for (const id of elementsTicked) {
favoriteRequest.deleteFavorite({
objectId: id
});
}
editFavoritesMode.value = false;
}
function changeFavoriteGroupName(ctx) {
proxy.$prompt(
t('prompt.change_favorite_group_name.description'),
t('prompt.change_favorite_group_name.header'),
{
distinguishCancelAndClose: true,
cancelButtonText: t('prompt.change_favorite_group_name.cancel'),
confirmButtonText: t('prompt.change_favorite_group_name.change'),
inputPlaceholder: t('prompt.change_favorite_group_name.input_placeholder'),
inputValue: ctx.displayName,
inputPattern: /\S+/,
inputErrorMessage: t('prompt.change_favorite_group_name.input_error'),
callback: (action, instance) => {
if (action === 'confirm') {
favoriteRequest
.saveFavoriteGroup({
type: ctx.type,
group: ctx.name,
displayName: instance.inputValue
})
.then((args) => {
handleFavoriteGroup({
json: args.json,
params: {
favoriteGroupId: args.json.id
}
});
proxy.$message({
message: t('prompt.change_favorite_group_name.message.success'),
type: 'success'
});
// load new group name
refreshFavoriteGroups();
});
}
}
}
);
}
async function refreshLocalAvatarFavorites() {
if (refreshingLocalFavorites.value) {
return;
}
refreshingLocalFavorites.value = true;
for (const avatarId of localAvatarFavoritesList.value) {
if (!refreshingLocalFavorites.value) {
break;
}
try {
const args = await avatarRequest.getAvatar({
avatarId
});
applyAvatar(args.json);
} catch (err) {
console.error(err);
}
await new Promise((resolve) => {
workerTimers.setTimeout(resolve, 1000);
});
}
refreshingLocalFavorites.value = false;
}
async function refreshLocalWorldFavorites() {
if (refreshingLocalFavorites.value) {
return;
}
refreshingLocalFavorites.value = true;
for (const worldId of localWorldFavoritesList.value) {
if (!refreshingLocalFavorites.value) {
break;
}
try {
await worldRequest.getWorld({
worldId
});
} catch (err) {
console.error(err);
}
await new Promise((resolve) => {
workerTimers.setTimeout(resolve, 1000);
});
}
refreshingLocalFavorites.value = false;
}
</script>
@@ -16,7 +16,7 @@
</el-tooltip>
<el-dropdown-menu slot="dropdown">
<template
v-for="groupAPI in API.favoriteAvatarGroups"
v-for="groupAPI in favoriteAvatarGroups"
v-if="isLocalFavorite || groupAPI.name !== group.name">
<el-dropdown-item
:key="groupAPI.name"
@@ -36,22 +36,22 @@
<el-tooltip
v-if="favorite.deleted"
placement="left"
:content="$t('view.favorite.unavailable_tooltip')">
:content="t('view.favorite.unavailable_tooltip')">
<i class="el-icon-warning" style="color: #f56c6c; margin-left: 5px"></i>
</el-tooltip>
<el-tooltip
v-if="favorite.ref.releaseStatus === 'private'"
placement="left"
:content="$t('view.favorite.private')">
:content="t('view.favorite.private')">
<i class="el-icon-warning" style="color: #e6a23c; margin-left: 5px"></i>
</el-tooltip>
<el-tooltip
v-if="favorite.ref.releaseStatus !== 'private' && !favorite.deleted"
placement="left"
:content="$t('view.favorite.select_avatar_tooltip')"
:content="t('view.favorite.select_avatar_tooltip')"
:disabled="hideTooltips">
<el-button
:disabled="API.currentUser.currentAvatar === favorite.id"
:disabled="currentUser.currentAvatar === favorite.id"
size="mini"
icon="el-icon-check"
circle
@@ -60,7 +60,7 @@
</el-tooltip>
<el-tooltip
placement="right"
:content="$t('view.favorite.unfavorite_tooltip')"
:content="t('view.favorite.unfavorite_tooltip')"
:disabled="hideTooltips">
<el-button
v-if="shiftHeld"
@@ -82,10 +82,10 @@
<template v-else>
<el-tooltip
placement="left"
:content="$t('view.favorite.select_avatar_tooltip')"
:content="t('view.favorite.select_avatar_tooltip')"
:disabled="hideTooltips">
<el-button
:disabled="API.currentUser.currentAvatar === favorite.id"
:disabled="currentUser.currentAvatar === favorite.id"
size="mini"
circle
style="margin-left: 5px"
@@ -96,7 +96,7 @@
<el-tooltip
v-if="isLocalFavorite"
placement="right"
:content="$t('view.favorite.unfavorite_tooltip')"
:content="t('view.favorite.unfavorite_tooltip')"
:disabled="hideTooltips">
<el-button
v-if="shiftHeld"
@@ -139,104 +139,84 @@
</div>
</template>
<script>
<script setup>
import { storeToRefs } from 'pinia';
import { computed } from 'vue';
import { useI18n } from 'vue-i18n-bridge';
import { favoriteRequest } from '../../../api';
import { $app } from '../../../app';
import {
useAppearanceSettingsStore,
useAvatarStore,
useFavoriteStore,
useUiStore,
useUserStore
} from '../../../stores';
export default {
name: 'FavoritesAvatarItem',
inject: ['API', 'showFavoriteDialog'],
props: {
favorite: Object,
group: [Object, String],
editFavoritesMode: Boolean,
shiftHeld: Boolean,
hideTooltips: Boolean,
isLocalFavorite: Boolean
},
computed: {
isSelected: {
get() {
return this.favorite.$selected;
},
set(value) {
this.$emit('handle-select', value);
}
},
localFavFakeRef() {
// local favorite no "ref" property
return this.isLocalFavorite ? this.favorite : this.favorite.ref;
},
tooltipContent() {
return $t(this.isLocalFavorite ? 'view.favorite.copy_tooltip' : 'view.favorite.move_tooltip');
},
smallThumbnail() {
return (
this.localFavFakeRef.thumbnailImageUrl.replace('256', '128') ||
this.localFavFakeRef.thumbnailImageUrl
);
}
},
methods: {
moveFavorite(ref, group, type) {
favoriteRequest
.deleteFavorite({
objectId: ref.id
})
.then(() => {
favoriteRequest.addFavorite({
type,
favoriteId: ref.id,
tags: group.name
});
});
},
selectAvatarWithConfirmation() {
this.$emit('select-avatar-with-confirmation', this.favorite.id);
},
deleteFavorite(objectId) {
favoriteRequest.deleteFavorite({
objectId
const props = defineProps({
favorite: Object,
group: [Object, String],
editFavoritesMode: Boolean,
isLocalFavorite: Boolean
});
const emit = defineEmits(['click', 'handle-select']);
const { t } = useI18n();
const { hideTooltips } = storeToRefs(useAppearanceSettingsStore());
const { favoriteAvatarGroups } = storeToRefs(useFavoriteStore());
const { removeLocalAvatarFavorite, showFavoriteDialog } = useFavoriteStore();
const { selectAvatarWithConfirmation } = useAvatarStore();
const { shiftHeld } = storeToRefs(useUiStore());
const { currentUser } = storeToRefs(useUserStore());
const isSelected = computed({
get: () => props.favorite.$selected,
set: (value) => emit('handle-select', value)
});
const localFavFakeRef = computed(() => (props.isLocalFavorite ? props.favorite : props.favorite.ref));
const tooltipContent = computed(() =>
t(props.isLocalFavorite ? 'view.favorite.copy_tooltip' : 'view.favorite.move_tooltip')
);
const smallThumbnail = computed(
() => localFavFakeRef.value.thumbnailImageUrl.replace('256', '128') || localFavFakeRef.value.thumbnailImageUrl
);
function moveFavorite(ref, group, type) {
favoriteRequest.deleteFavorite({ objectId: ref.id }).then(() => {
favoriteRequest.addFavorite({
type,
favoriteId: ref.id,
tags: group.name
});
});
}
function deleteFavorite(objectId) {
favoriteRequest.deleteFavorite({ objectId });
}
function addFavoriteAvatar(groupAPI) {
return favoriteRequest
.addFavorite({
type: 'avatar',
favoriteId: props.favorite.id,
tags: groupAPI.name
})
.then((args) => {
$app.$message({
message: 'Avatar added to favorites',
type: 'success'
});
// FIXME: 메시지 수정
// this.$confirm('Continue? Delete Favorite', 'Confirm', {
// confirmButtonText: 'Confirm',
// cancelButtonText: 'Cancel',
// type: 'info',
// callback: (action) => {
// if (action === 'confirm') {
// API.deleteFavorite({
// objectId
// });
// }
// }
// });
},
addFavoriteAvatar(groupAPI) {
return favoriteRequest
.addFavorite({
type: 'avatar',
favoriteId: this.favorite.id,
tags: groupAPI.name
})
.then((args) => {
this.$message({
message: 'Avatar added to favorites',
type: 'success'
});
return args;
});
}
return args;
});
},
handleDropdownItemClick(groupAPI) {
if (this.isLocalFavorite) {
this.addFavoriteAvatar(groupAPI);
} else {
this.moveFavorite(this.favorite.ref, groupAPI, 'avatar');
}
},
removeLocalAvatarFavorite() {
this.$emit('remove-local-avatar-favorite', this.favorite.id, this.group);
}
function handleDropdownItemClick(groupAPI) {
if (props.isLocalFavorite) {
addFavoriteAvatar(groupAPI);
} else {
moveFavorite(props.favorite.ref, groupAPI, 'avatar');
}
};
}
</script>
@@ -8,16 +8,16 @@
<span class="name" v-text="favorite.name"></span>
<span class="extra" v-text="favorite.authorName"></span>
</div>
<el-tooltip placement="left" :content="$t('view.favorite.select_avatar_tooltip')" :disabled="hideTooltips">
<el-tooltip placement="left" :content="t('view.favorite.select_avatar_tooltip')" :disabled="hideTooltips">
<el-button
:disabled="API.currentUser.currentAvatar === favorite.id"
:disabled="currentUser.currentAvatar === favorite.id"
size="mini"
icon="el-icon-check"
circle
style="margin-left: 5px"
@click.stop="selectAvatarWithConfirmation"></el-button>
</el-tooltip>
<template v-if="API.cachedFavoritesByObjectId.has(favorite.id)">
<template v-if="cachedFavoritesByObjectId.has(favorite.id)">
<el-tooltip placement="right" content="Unfavorite" :disabled="hideTooltips">
<el-button
type="default"
@@ -43,26 +43,28 @@
</div>
</template>
<script>
export default {
name: 'FavoritesAvatarLocalHistoryItem',
inject: ['API', 'showFavoriteDialog'],
props: {
favorite: {
type: Object,
required: true
},
hideTooltips: Boolean
},
computed: {
smallThumbnail() {
return this.favorite.thumbnailImageUrl.replace('256', '128') || this.favorite.thumbnailImageUrl;
}
},
methods: {
selectAvatarWithConfirmation() {
this.$emit('select-avatar-with-confirmation', this.favorite.id);
}
<script setup>
import { storeToRefs } from 'pinia';
import { computed } from 'vue';
import { useI18n } from 'vue-i18n-bridge';
import { useAppearanceSettingsStore, useAvatarStore, useFavoriteStore, useUserStore } from '../../../stores';
const { t } = useI18n();
const { hideTooltips } = storeToRefs(useAppearanceSettingsStore());
const { cachedFavoritesByObjectId } = storeToRefs(useFavoriteStore());
const { showFavoriteDialog } = useFavoriteStore();
const { selectAvatarWithConfirmation } = useAvatarStore();
const { currentUser } = storeToRefs(useUserStore());
const props = defineProps({
favorite: {
type: Object,
required: true
}
};
});
const smallThumbnail = computed(() => {
return props.favorite.thumbnailImageUrl.replace('256', '128') || props.favorite.thumbnailImageUrl;
});
</script>
@@ -3,29 +3,29 @@
<div style="display: flex; align-items: center; justify-content: space-between">
<div>
<el-button size="small" @click="showAvatarExportDialog">
{{ $t('view.favorite.export') }}
{{ t('view.favorite.export') }}
</el-button>
<el-button size="small" style="margin-left: 5px" @click="showAvatarImportDialog">
{{ $t('view.favorite.import') }}
{{ t('view.favorite.import') }}
</el-button>
</div>
<div style="display: flex; align-items: center; font-size: 13px; margin-right: 10px">
<span class="name" style="margin-right: 5px; line-height: 10px">
{{ $t('view.favorite.sort_by') }}
{{ t('view.favorite.sort_by') }}
</span>
<el-radio-group v-model="sortFav" style="margin-right: 12px" @change="saveSortFavoritesOption">
<el-radio :label="false">
{{ $t('view.settings.appearance.appearance.sort_favorite_by_name') }}
{{ t('view.settings.appearance.appearance.sort_favorite_by_name') }}
</el-radio>
<el-radio :label="true">
{{ $t('view.settings.appearance.appearance.sort_favorite_by_date') }}
{{ t('view.settings.appearance.appearance.sort_favorite_by_date') }}
</el-radio>
</el-radio-group>
<el-input
v-model="avatarFavoriteSearch"
clearable
size="mini"
:placeholder="$t('view.favorite.avatars.search')"
:placeholder="t('view.favorite.avatars.search')"
style="width: 200px"
@input="searchAvatarFavorites" />
</div>
@@ -56,16 +56,16 @@
</div>
</div>
<span style="display: block; margin-top: 20px">
{{ $t('view.favorite.avatars.vrchat_favorites') }}
{{ t('view.favorite.avatars.vrchat_favorites') }}
</span>
<el-collapse style="border: 0">
<el-collapse-item v-for="group in API.favoriteAvatarGroups" :key="group.name">
<el-collapse-item v-for="group in favoriteAvatarGroups" :key="group.name">
<template slot="title">
<span style="font-weight: bold; font-size: 14px; margin-left: 10px" v-text="group.displayName" />
<span style="color: #909399; font-size: 12px; margin-left: 10px">
{{ group.count }}/{{ group.capacity }}
</span>
<el-tooltip placement="top" :content="$t('view.favorite.rename_tooltip')" :disabled="hideTooltips">
<el-tooltip placement="top" :content="t('view.favorite.rename_tooltip')" :disabled="hideTooltips">
<el-button
size="mini"
icon="el-icon-edit"
@@ -73,7 +73,7 @@
style="margin-left: 10px"
@click.stop="changeFavoriteGroupName(group)" />
</el-tooltip>
<el-tooltip placement="right" :content="$t('view.favorite.clear_tooltip')" :disabled="hideTooltips">
<el-tooltip placement="right" :content="t('view.favorite.clear_tooltip')" :disabled="hideTooltips">
<el-button
size="mini"
icon="el-icon-delete"
@@ -89,12 +89,9 @@
:favorite="favorite"
:group="group"
:hide-tooltips="hideTooltips"
:shift-held="shiftHeld"
:edit-favorites-mode="editFavoritesMode"
style="display: inline-block; width: 300px; margin-right: 15px"
@handle-select="favorite.$selected = $event"
@remove-local-avatar-favorite="removeLocalAvatarFavorite"
@select-avatar-with-confirmation="selectAvatarWithConfirmation"
@click="showAvatarDialog(favorite.id)" />
</div>
<div
@@ -132,7 +129,6 @@
style="display: inline-block; width: 300px; margin-right: 15px"
:favorite="favorite"
:hide-tooltips="hideTooltips"
@select-avatar-with-confirmation="selectAvatarWithConfirmation"
@click="showAvatarDialog(favorite.id)" />
</div>
<div
@@ -148,21 +144,21 @@
<span>No Data</span>
</div>
</el-collapse-item>
<span style="display: block; margin-top: 20px">{{ $t('view.favorite.avatars.local_favorites') }}</span>
<span style="display: block; margin-top: 20px">{{ t('view.favorite.avatars.local_favorites') }}</span>
<br />
<el-button size="small" :disabled="!isLocalUserVrcplusSupporter" @click="promptNewLocalAvatarFavoriteGroup">
{{ $t('view.favorite.avatars.new_group') }}
{{ t('view.favorite.avatars.new_group') }}
</el-button>
<el-button
v-if="!refreshingLocalFavorites"
size="small"
style="margin-left: 5px"
@click="refreshLocalAvatarFavorites">
{{ $t('view.favorite.avatars.refresh') }}
{{ t('view.favorite.avatars.refresh') }}
</el-button>
<el-button v-else size="small" style="margin-left: 5px" @click="refreshingLocalFavorites = false">
<i class="el-icon-loading" style="margin-right: 5px"></i>
<span>{{ $t('view.favorite.avatars.cancel_refresh') }}</span>
<span>{{ t('view.favorite.avatars.cancel_refresh') }}</span>
</el-button>
<el-collapse-item
v-for="group in localAvatarFavoriteGroups"
@@ -173,7 +169,7 @@
<span :style="{ color: '#909399', fontSize: '12px', marginLeft: '10px' }">{{
getLocalAvatarFavoriteGroupLength(group)
}}</span>
<el-tooltip placement="top" :content="$t('view.favorite.rename_tooltip')" :disabled="hideTooltips">
<el-tooltip placement="top" :content="t('view.favorite.rename_tooltip')" :disabled="hideTooltips">
<el-button
size="mini"
icon="el-icon-edit"
@@ -181,10 +177,7 @@
:style="{ marginLeft: '5px' }"
@click.stop="promptLocalAvatarFavoriteGroupRename(group)"></el-button>
</el-tooltip>
<el-tooltip
placement="right"
:content="$t('view.favorite.delete_tooltip')"
:disabled="hideTooltips">
<el-tooltip placement="right" :content="t('view.favorite.delete_tooltip')" :disabled="hideTooltips">
<el-button
size="mini"
icon="el-icon-delete"
@@ -202,11 +195,8 @@
:favorite="favorite"
:group="group"
:hide-tooltips="hideTooltips"
:shift-held="shiftHeld"
:edit-favorites-mode="editFavoritesMode"
@handle-select="favorite.$selected = $event"
@remove-local-avatar-favorite="removeLocalAvatarFavorite"
@select-avatar-with-confirmation="selectAvatarWithConfirmation"
@click="showAvatarDialog(favorite.id)" />
</div>
<div
@@ -223,178 +213,205 @@
</div>
</el-collapse-item>
</el-collapse>
<AvatarExportDialog
:avatar-export-dialog-visible.sync="avatarExportDialogVisible"
:favorite-avatars="favoriteAvatars"
:local-avatar-favorite-groups="localAvatarFavoriteGroups"
:local-avatar-favorites="localAvatarFavorites"
:local-avatar-favorites-list="localAvatarFavoritesList" />
<AvatarExportDialog :avatar-export-dialog-visible.sync="avatarExportDialogVisible" />
</div>
</template>
<script>
<script setup>
import { ref, computed, getCurrentInstance } from 'vue';
import { storeToRefs } from 'pinia';
import { useI18n } from 'vue-i18n-bridge';
import { favoriteRequest } from '../../../api';
import { useAppearanceSettingsStore, useAvatarStore, useFavoriteStore, useUserStore } from '../../../stores';
import AvatarExportDialog from '../dialogs/AvatarExportDialog.vue';
import FavoritesAvatarItem from './FavoritesAvatarItem.vue';
import FavoritesAvatarLocalHistoryItem from './FavoritesAvatarLocalHistoryItem.vue';
import AvatarExportDialog from '../dialogs/AvatarExportDialog.vue';
import { favoriteRequest } from '../../../api';
export default {
name: 'FavoritesAvatarTab',
components: { FavoritesAvatarItem, FavoritesAvatarLocalHistoryItem, AvatarExportDialog },
inject: ['API', 'showAvatarDialog'],
props: {
sortFavorites: Boolean,
hideTooltips: Boolean,
shiftHeld: Boolean,
editFavoritesMode: Boolean,
avatarHistoryArray: Array,
refreshingLocalFavorites: Boolean,
localAvatarFavoriteGroups: Array,
localAvatarFavorites: Object,
favoriteAvatars: Array,
localAvatarFavoritesList: Array
defineProps({
editFavoritesMode: {
type: Boolean,
default: false
},
data() {
return {
avatarExportDialogVisible: false,
avatarFavoriteSearch: '',
avatarFavoriteSearchResults: []
};
refreshingLocalFavorites: {
type: Boolean,
default: false
}
});
const { proxy } = getCurrentInstance();
const emit = defineEmits(['change-favorite-group-name', 'refresh-local-avatar-favorites']);
const { hideTooltips, sortFavorites } = storeToRefs(useAppearanceSettingsStore());
const { setSortFavorites } = useAppearanceSettingsStore();
const { favoriteAvatars, favoriteAvatarGroups, localAvatarFavorites, localAvatarFavoriteGroups } =
storeToRefs(useFavoriteStore());
const {
showAvatarImportDialog,
getLocalAvatarFavoriteGroupLength,
deleteLocalAvatarFavoriteGroup,
renameLocalAvatarFavoriteGroup,
newLocalAvatarFavoriteGroup,
saveSortFavoritesOption
} = useFavoriteStore();
const { avatarHistoryArray } = storeToRefs(useAvatarStore());
const { promptClearAvatarHistory, showAvatarDialog } = useAvatarStore();
const { currentUser } = storeToRefs(useUserStore());
const { t } = useI18n();
const avatarExportDialogVisible = ref(false);
const avatarFavoriteSearch = ref('');
const avatarFavoriteSearchResults = ref([]);
const sortFav = computed({
get() {
return sortFavorites.value;
},
computed: {
sortFav: {
get() {
return this.sortFavorites;
},
set(value) {
this.$emit('update:sort-favorites', value);
set() {
setSortFavorites();
}
});
const groupedByGroupKeyFavoriteAvatars = computed(() => {
const groupedByGroupKeyFavoriteAvatars = {};
favoriteAvatars.value.forEach((avatar) => {
if (avatar.groupKey) {
if (!groupedByGroupKeyFavoriteAvatars[avatar.groupKey]) {
groupedByGroupKeyFavoriteAvatars[avatar.groupKey] = [];
}
},
groupedByGroupKeyFavoriteAvatars() {
const groupedByGroupKeyFavoriteAvatars = {};
this.favoriteAvatars.forEach((avatar) => {
if (avatar.groupKey) {
if (!groupedByGroupKeyFavoriteAvatars[avatar.groupKey]) {
groupedByGroupKeyFavoriteAvatars[avatar.groupKey] = [];
}
groupedByGroupKeyFavoriteAvatars[avatar.groupKey].push(avatar);
}
});
return groupedByGroupKeyFavoriteAvatars;
},
isLocalUserVrcplusSupporter() {
return this.API.currentUser.$isVRCPlus;
groupedByGroupKeyFavoriteAvatars[avatar.groupKey].push(avatar);
}
},
methods: {
getLocalAvatarFavoriteGroupLength(group) {
const favoriteGroup = this.localAvatarFavorites[group];
if (!favoriteGroup) {
return 0;
}
return favoriteGroup.length;
},
searchAvatarFavorites() {
let ref = null;
const search = this.avatarFavoriteSearch.toLowerCase();
if (search.length < 3) {
this.avatarFavoriteSearchResults = [];
return;
}
});
const results = [];
for (let i = 0; i < this.localAvatarFavoriteGroups.length; ++i) {
const group = this.localAvatarFavoriteGroups[i];
if (!this.localAvatarFavorites[group]) {
continue;
}
for (let j = 0; j < this.localAvatarFavorites[group].length; ++j) {
ref = this.localAvatarFavorites[group][j];
if (
!ref ||
typeof ref.id === 'undefined' ||
typeof ref.name === 'undefined' ||
typeof ref.authorName === 'undefined'
) {
continue;
}
if (ref.name.toLowerCase().includes(search) || ref.authorName.toLowerCase().includes(search)) {
if (!results.some((r) => r.id === ref.id)) {
results.push(ref);
}
}
return groupedByGroupKeyFavoriteAvatars;
});
const isLocalUserVrcplusSupporter = computed(() => currentUser.value.$isVRCPlus);
function searchAvatarFavorites() {
let ref = null;
const search = avatarFavoriteSearch.value.toLowerCase();
if (search.length < 3) {
avatarFavoriteSearchResults.value = [];
return;
}
const results = [];
for (let i = 0; i < localAvatarFavoriteGroups.value.length; ++i) {
const group = localAvatarFavoriteGroups.value[i];
if (!localAvatarFavorites.value[group]) {
continue;
}
for (let j = 0; j < localAvatarFavorites.value[group].length; ++j) {
ref = localAvatarFavorites.value[group][j];
if (
!ref ||
typeof ref.id === 'undefined' ||
typeof ref.name === 'undefined' ||
typeof ref.authorName === 'undefined'
) {
continue;
}
if (ref.name.toLowerCase().includes(search) || ref.authorName.toLowerCase().includes(search)) {
if (!results.some((r) => r.id === ref.id)) {
results.push(ref);
}
}
for (let i = 0; i < this.favoriteAvatars.length; ++i) {
ref = this.favoriteAvatars[i].ref;
if (
!ref ||
typeof ref.id === 'undefined' ||
typeof ref.name === 'undefined' ||
typeof ref.authorName === 'undefined'
) {
continue;
}
if (ref.name.toLowerCase().includes(search) || ref.authorName.toLowerCase().includes(search)) {
if (!results.some((r) => r.id === ref.id)) {
results.push(ref);
}
}
}
this.avatarFavoriteSearchResults = results;
},
clearFavoriteGroup(ctx) {
// FIXME: 메시지 수정
this.$confirm('Continue? Clear Group', 'Confirm', {
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel',
type: 'info',
callback: (action) => {
if (action === 'confirm') {
favoriteRequest.clearFavoriteGroup({
type: ctx.type,
group: ctx.name
});
}
}
});
},
showAvatarExportDialog() {
this.avatarExportDialogVisible = true;
},
showAvatarImportDialog() {
this.$emit('show-avatar-import-dialog');
},
saveSortFavoritesOption() {
this.$emit('save-sort-favorites-option');
},
changeFavoriteGroupName(group) {
this.$emit('change-favorite-group-name', group);
},
removeLocalAvatarFavorite(id, group) {
this.$emit('remove-local-avatar-favorite', id, group);
},
selectAvatarWithConfirmation(id) {
this.$emit('select-avatar-with-confirmation', id);
},
promptClearAvatarHistory() {
this.$emit('prompt-clear-avatar-history');
},
promptNewLocalAvatarFavoriteGroup() {
this.$emit('prompt-new-local-avatar-favorite-group');
},
refreshLocalAvatarFavorites() {
this.$emit('refresh-local-avatar-favorites');
},
promptLocalAvatarFavoriteGroupRename(group) {
this.$emit('prompt-local-avatar-favorite-group-rename', group);
},
promptLocalAvatarFavoriteGroupDelete(group) {
this.$emit('prompt-local-avatar-favorite-group-delete', group);
}
}
};
for (let i = 0; i < favoriteAvatars.value.length; ++i) {
ref = favoriteAvatars.value[i].ref;
if (
!ref ||
typeof ref.id === 'undefined' ||
typeof ref.name === 'undefined' ||
typeof ref.authorName === 'undefined'
) {
continue;
}
if (ref.name.toLowerCase().includes(search) || ref.authorName.toLowerCase().includes(search)) {
if (!results.some((r) => r.id === ref.id)) {
results.push(ref);
}
}
}
avatarFavoriteSearchResults.value = results;
}
function clearFavoriteGroup(ctx) {
proxy.$confirm('Continue? Clear Group', 'Confirm', {
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel',
type: 'info',
callback: (action) => {
if (action === 'confirm') {
favoriteRequest.clearFavoriteGroup({
type: ctx.type,
group: ctx.name
});
}
}
});
}
function showAvatarExportDialog() {
avatarExportDialogVisible.value = true;
}
function changeFavoriteGroupName(group) {
emit('change-favorite-group-name', group);
}
function promptNewLocalAvatarFavoriteGroup() {
proxy.$prompt(t('prompt.new_local_favorite_group.description'), t('prompt.new_local_favorite_group.header'), {
distinguishCancelAndClose: true,
confirmButtonText: t('prompt.new_local_favorite_group.ok'),
cancelButtonText: t('prompt.new_local_favorite_group.cancel'),
inputPattern: /\S+/,
inputErrorMessage: t('prompt.new_local_favorite_group.input_error'),
callback: (action, instance) => {
if (action === 'confirm' && instance.inputValue) {
newLocalAvatarFavoriteGroup(instance.inputValue);
}
}
});
}
function refreshLocalAvatarFavorites() {
emit('refresh-local-avatar-favorites');
}
function promptLocalAvatarFavoriteGroupRename(group) {
proxy.$prompt(
t('prompt.local_favorite_group_rename.description'),
t('prompt.local_favorite_group_rename.header'),
{
distinguishCancelAndClose: true,
confirmButtonText: t('prompt.local_favorite_group_rename.save'),
cancelButtonText: t('prompt.local_favorite_group_rename.cancel'),
inputPattern: /\S+/,
inputErrorMessage: t('prompt.local_favorite_group_rename.input_error'),
inputValue: group,
callback: (action, instance) => {
if (action === 'confirm' && instance.inputValue) {
renameLocalAvatarFavoriteGroup(instance.inputValue, group);
}
}
}
);
}
function promptLocalAvatarFavoriteGroupDelete(group) {
proxy.$confirm(`Delete Group? ${group}`, 'Confirm', {
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel',
type: 'info',
callback: (action) => {
if (action === 'confirm') {
deleteLocalAvatarFavoriteGroup(group);
}
}
});
}
</script>
@@ -10,12 +10,12 @@
class="name"
:style="{ color: favorite.ref.$userColour }"
v-text="favorite.ref.displayName"></span>
<location
<Location
class="extra"
v-if="favorite.ref.location !== 'offline'"
:location="favorite.ref.location"
:traveling="favorite.ref.travelingToLocation"
:link="false"></location>
:link="false" />
<span v-else v-text="favorite.ref.statusDescription"></span>
</div>
<template v-if="editFavoritesMode">
@@ -27,7 +27,7 @@
<el-button type="default" icon="el-icon-back" size="mini" circle></el-button>
</el-tooltip>
<el-dropdown-menu slot="dropdown">
<template v-for="groupAPI in API.favoriteFriendGroups">
<template v-for="groupAPI in favoriteFriendGroups">
<el-dropdown-item
v-if="groupAPI.name !== group.name"
:key="groupAPI.name"
@@ -82,63 +82,36 @@
</div>
</template>
<script>
import Location from '../../../components/Location.vue';
<script setup>
import { storeToRefs } from 'pinia';
import { favoriteRequest } from '../../../api';
export default {
components: { Location },
inject: ['showUserDialog', 'userImage', 'userStatusClass', 'API', 'showFavoriteDialog'],
props: {
favorite: {
type: Object,
required: true
},
hideTooltips: {
type: Boolean,
default: false
},
shiftHeld: {
type: Boolean,
default: false
},
group: {
type: Object,
required: true
},
editFavoritesMode: Boolean
},
methods: {
moveFavorite(ref, group, type) {
favoriteRequest
.deleteFavorite({
objectId: ref.id
})
.then(() => {
favoriteRequest.addFavorite({
type,
favoriteId: ref.id,
tags: group.name
});
});
},
deleteFavorite(objectId) {
favoriteRequest.deleteFavorite({
objectId
});
// FIXME: 메시지 수정
// this.$confirm('Continue? Delete Favorite', 'Confirm', {
// confirmButtonText: 'Confirm',
// cancelButtonText: 'Cancel',
// type: 'info',
// callback: (action) => {
// if (action === 'confirm') {
// API.deleteFavorite({
// objectId
// });
// }
// }
// });
}
}
};
import { userImage, userStatusClass } from '../../../shared/utils';
import { useAppearanceSettingsStore, useFavoriteStore, useUiStore } from '../../../stores';
defineProps({
favorite: { type: Object, required: true },
group: { type: Object, required: true },
editFavoritesMode: Boolean
});
defineEmits(['click']);
const { hideTooltips } = storeToRefs(useAppearanceSettingsStore());
const { favoriteFriendGroups } = storeToRefs(useFavoriteStore());
const { showFavoriteDialog } = useFavoriteStore();
const { shiftHeld } = storeToRefs(useUiStore());
function moveFavorite(ref, group, type) {
favoriteRequest.deleteFavorite({ objectId: ref.id }).then(() => {
favoriteRequest.addFavorite({
type,
favoriteId: ref.id,
tags: group.name
});
});
}
function deleteFavorite(objectId) {
favoriteRequest.deleteFavorite({ objectId });
}
</script>
@@ -21,7 +21,7 @@
</div>
<span style="display: block; margin-top: 30px">{{ $t('view.favorite.avatars.vrchat_favorites') }}</span>
<el-collapse style="border: 0">
<el-collapse-item v-for="group in API.favoriteFriendGroups" :key="group.name">
<el-collapse-item v-for="group in favoriteFriendGroups" :key="group.name">
<template slot="title">
<span
style="font-weight: bold; font-size: 14px; margin-left: 10px"
@@ -70,73 +70,67 @@
</div>
</el-collapse-item>
</el-collapse>
<FriendExportDialog
:friend-export-dialog-visible.sync="friendExportDialogVisible"
:favorite-friends="favoriteFriends" />
<FriendExportDialog :friend-export-dialog-visible.sync="friendExportDialogVisible" />
</div>
</template>
<script>
import FavoritesFriendItem from './FavoritesFriendItem.vue';
import FriendExportDialog from '../dialogs/FriendExportDialog.vue';
<script setup>
import { ref, getCurrentInstance, computed } from 'vue';
import { storeToRefs } from 'pinia';
import { favoriteRequest } from '../../../api';
import { useAppearanceSettingsStore, useFavoriteStore, useUserStore } from '../../../stores';
import FriendExportDialog from '../dialogs/FriendExportDialog.vue';
import FavoritesFriendItem from './FavoritesFriendItem.vue';
export default {
name: 'FavoritesFriendTab',
components: { FriendExportDialog, FavoritesFriendItem },
inject: ['showUserDialog', 'API'],
props: {
favoriteFriends: Array,
sortFavorites: Boolean,
hideTooltips: Boolean,
groupedByGroupKeyFavoriteFriends: Object,
editFavoritesMode: Boolean
defineProps({
editFavoritesMode: {
type: Boolean,
default: false
}
});
const emit = defineEmits(['change-favorite-group-name']);
const { proxy } = getCurrentInstance();
const { hideTooltips, sortFavorites } = storeToRefs(useAppearanceSettingsStore());
const { setSortFavorites } = useAppearanceSettingsStore();
const { showUserDialog } = useUserStore();
const { favoriteFriendGroups, groupedByGroupKeyFavoriteFriends } = storeToRefs(useFavoriteStore());
const { showFriendImportDialog, saveSortFavoritesOption } = useFavoriteStore();
const friendExportDialogVisible = ref(false);
const sortFav = computed({
get() {
return sortFavorites.value;
},
data() {
return {
friendExportDialogVisible: false
};
},
computed: {
sortFav: {
get() {
return this.sortFavorites;
},
set(value) {
this.$emit('update:sort-favorites', value);
set(value) {
setSortFavorites(value);
}
});
function showFriendExportDialog() {
friendExportDialogVisible.value = true;
}
function clearFavoriteGroup(ctx) {
proxy.$confirm('Continue? Clear Group', 'Confirm', {
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel',
type: 'info',
callback: (action) => {
if (action === 'confirm') {
favoriteRequest.clearFavoriteGroup({
type: ctx.type,
group: ctx.name
});
}
}
},
methods: {
showFriendExportDialog() {
this.friendExportDialogVisible = true;
},
showFriendImportDialog() {
this.$emit('show-friend-import-dialog');
},
saveSortFavoritesOption() {
this.$emit('save-sort-favorites-option');
},
});
}
clearFavoriteGroup(ctx) {
// FIXME: 메시지 수정
this.$confirm('Continue? Clear Group', 'Confirm', {
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel',
type: 'info',
callback: (action) => {
if (action === 'confirm') {
favoriteRequest.clearFavoriteGroup({
type: ctx.type,
group: ctx.name
});
}
}
});
},
changeFavoriteGroupName(group) {
this.$emit('change-favorite-group-name', group);
}
}
};
function changeFavoriteGroupName(group) {
emit('change-favorite-group-name', group);
}
</script>
@@ -6,11 +6,11 @@
<img v-lazy="smallThumbnail" />
</div>
<div class="detail">
<span class="name">{{ localFavFakeRef.name }}</span>
<span v-if="localFavFakeRef.occupants" class="extra"
<span class="name" v-once>{{ localFavFakeRef.name }}</span>
<span v-if="localFavFakeRef.occupants" class="extra" v-once
>{{ localFavFakeRef.authorName }} ({{ localFavFakeRef.occupants }})</span
>
<span v-else class="extra">{{ localFavFakeRef.authorName }}</span>
<span v-else class="extra" v-once>{{ localFavFakeRef.authorName }}</span>
</div>
<template v-if="editFavoritesMode">
<el-dropdown trigger="click" size="mini" style="margin-left: 5px" @click.native.stop>
@@ -21,7 +21,7 @@
<el-button type="default" icon="el-icon-back" size="mini" circle></el-button>
</el-tooltip>
<el-dropdown-menu slot="dropdown">
<template v-for="groupAPI in API.favoriteWorldGroups">
<template v-for="groupAPI in favoriteWorldGroups">
<el-dropdown-item
v-if="isLocalFavorite || groupAPI.name !== group.name"
:key="groupAPI.name"
@@ -59,7 +59,7 @@
size="mini"
icon="el-icon-message"
style="margin-left: 5px"
@click.stop="$emit('new-instance-self-invite', favorite.id)"
@click.stop="newInstanceSelfInvite(favorite.id)"
circle></el-button>
</el-tooltip>
<el-tooltip
@@ -109,7 +109,7 @@
<template v-else>
<div class="avatar"></div>
<div class="detail">
<span>{{ favorite.name || favorite.id }}</span>
<span v-once>{{ favorite.name || favorite.id }}</span>
<el-tooltip
v-if="!isLocalFavorite && favorite.deleted"
placement="left"
@@ -128,104 +128,82 @@
</div>
</template>
<script>
<script setup>
import { storeToRefs } from 'pinia';
import { computed, getCurrentInstance } from 'vue';
import { favoriteRequest } from '../../../api';
import { useAppearanceSettingsStore, useFavoriteStore, useInviteStore, useUiStore } from '../../../stores';
export default {
name: 'FavoritesWorldItem',
inject: ['API', 'showFavoriteDialog'],
props: {
group: [Object, String],
favorite: Object,
editFavoritesMode: Boolean,
hideTooltips: Boolean,
shiftHeld: Boolean,
isLocalFavorite: { type: Boolean, required: false }
},
computed: {
isSelected: {
get() {
return this.favorite.$selected;
},
set(value) {
this.$emit('handle-select', value);
}
},
localFavFakeRef() {
// local favorite no "ref" property
return this.isLocalFavorite ? this.favorite : this.favorite.ref;
},
smallThumbnail() {
return (
this.localFavFakeRef.thumbnailImageUrl.replace('256', '128') ||
this.localFavFakeRef.thumbnailImageUrl
);
}
},
methods: {
handleDropdownItemClick(groupAPI) {
if (this.isLocalFavorite) {
this.addFavoriteWorld(this.localFavFakeRef, groupAPI, true);
} else {
this.moveFavorite(this.localFavFakeRef, groupAPI, 'world');
}
},
handleDeleteFavorite() {
if (this.isLocalFavorite) {
this.$emit('remove-local-world-favorite', this.favorite.id, this.group);
} else {
this.deleteFavorite(this.favorite.id);
}
},
moveFavorite(ref, group, type) {
favoriteRequest
.deleteFavorite({
objectId: ref.id
})
.then(() => {
favoriteRequest.addFavorite({
type,
favoriteId: ref.id,
tags: group.name
});
});
},
deleteFavorite(objectId) {
favoriteRequest.deleteFavorite({
objectId
});
// FIXME: 메시지 수정
// this.$confirm('Continue? Delete Favorite', 'Confirm', {
// confirmButtonText: 'Confirm',
// cancelButtonText: 'Cancel',
// type: 'info',
// callback: (action) => {
// if (action === 'confirm') {
// API.deleteFavorite({
// objectId
// });
// }
// }
// });
},
addFavoriteWorld(ref, group, message) {
// wait API splitting PR Merged
return favoriteRequest
.addFavorite({
type: 'world',
favoriteId: ref.id,
tags: group.name
})
.then((args) => {
if (message) {
this.$message({
message: 'World added to favorites',
type: 'success'
});
}
return args;
});
}
const props = defineProps({
group: [Object, String],
favorite: Object,
editFavoritesMode: Boolean,
isLocalFavorite: { type: Boolean, default: false }
});
const emit = defineEmits(['handle-select', 'remove-local-world-favorite', 'click']);
const { proxy } = getCurrentInstance();
const { hideTooltips } = storeToRefs(useAppearanceSettingsStore());
const { favoriteWorldGroups } = storeToRefs(useFavoriteStore());
const { showFavoriteDialog } = useFavoriteStore();
const { newInstanceSelfInvite } = useInviteStore();
const { shiftHeld } = storeToRefs(useUiStore());
const isSelected = computed({
get: () => props.favorite.$selected,
set: (value) => emit('handle-select', value)
});
const localFavFakeRef = computed(() => (props.isLocalFavorite ? props.favorite : props.favorite.ref));
const smallThumbnail = computed(() => {
const url = localFavFakeRef.value.thumbnailImageUrl.replace('256', '128');
return url || localFavFakeRef.value.thumbnailImageUrl;
});
function handleDropdownItemClick(groupAPI) {
if (props.isLocalFavorite) {
addFavoriteWorld(localFavFakeRef.value, groupAPI, true);
} else {
moveFavorite(localFavFakeRef.value, groupAPI, 'world');
}
};
}
function handleDeleteFavorite() {
if (props.isLocalFavorite) {
emit('remove-local-world-favorite', props.favorite.id, props.group);
} else {
deleteFavorite(props.favorite.id);
}
}
function moveFavorite(refObj, group, type) {
favoriteRequest.deleteFavorite({ objectId: refObj.id }).then(() => {
favoriteRequest.addFavorite({
type,
favoriteId: refObj.id,
tags: group.name
});
});
}
function deleteFavorite(objectId) {
favoriteRequest.deleteFavorite({ objectId });
}
function addFavoriteWorld(refObj, group, message) {
return favoriteRequest
.addFavorite({
type: 'world',
favoriteId: refObj.id,
tags: group.name
})
.then((args) => {
if (message) {
proxy.$message({ message: 'World added to favorites', type: 'success' });
}
return args;
});
}
</script>
@@ -3,16 +3,13 @@
<div style="display: flex; align-items: center; justify-content: space-between">
<div>
<el-button size="small" @click="showExportDialog">{{ $t('view.favorite.export') }}</el-button>
<el-button size="small" style="margin-left: 5px" @click="$emit('show-world-import-dialog')">{{
<el-button size="small" style="margin-left: 5px" @click="showWorldImportDialog">{{
$t('view.favorite.import')
}}</el-button>
</div>
<div style="display: flex; align-items: center; font-size: 13px; margin-right: 10px">
<span class="name" style="margin-right: 5px; line-height: 10px">{{ $t('view.favorite.sort_by') }}</span>
<el-radio-group
v-model="sortFav"
style="margin-right: 12px"
@change="$emit('save-sort-favorites-option')">
<el-radio-group v-model="sortFav" style="margin-right: 12px" @change="saveSortFavoritesOption">
<el-radio :label="false">{{
$t('view.settings.appearance.appearance.sort_favorite_by_name')
}}</el-radio>
@@ -59,7 +56,7 @@
</div>
<span style="display: block; margin-top: 20px">{{ $t('view.favorite.worlds.vrchat_favorites') }}</span>
<el-collapse style="border: 0">
<el-collapse-item v-for="group in API.favoriteWorldGroups" :key="group.name">
<el-collapse-item v-for="group in favoriteWorldGroups" :key="group.name">
<template slot="title">
<div style="display: flex; align-items: center">
<span
@@ -125,10 +122,8 @@
:favorite="favorite"
:edit-favorites-mode="editFavoritesMode"
:hide-tooltips="hideTooltips"
:shift-held="shiftHeld"
@click="showWorldDialog(favorite.id)"
@handle-select="favorite.$selected = $event"
@new-instance-self-invite="newInstanceSelfInvite" />
@handle-select="favorite.$selected = $event" />
</div>
<div
v-else
@@ -153,7 +148,7 @@
v-if="!refreshingLocalFavorites"
size="small"
style="margin-left: 5px"
@click="$emit('refresh-local-world-favorite')"
@click="refreshLocalWorldFavorite"
>{{ $t('view.favorite.worlds.refresh') }}</el-button
>
<el-button v-else size="small" style="margin-left: 5px" @click="refreshingLocalFavorites = false">
@@ -196,9 +191,7 @@
:favorite="favorite"
:edit-favorites-mode="editFavoritesMode"
:hide-tooltips="hideTooltips"
:shift-held="shiftHeld"
@click="showWorldDialog(favorite.id)"
@new-instance-self-invite="newInstanceSelfInvite"
@remove-local-world-favorite="removeLocalWorldFavorite" />
</div>
<div
@@ -215,236 +208,247 @@
</div>
</el-collapse-item>
</el-collapse>
<WorldExportDialog
:favorite-worlds="favoriteWorlds"
:world-export-dialog-visible.sync="worldExportDialogVisible"
:local-world-favorites="localWorldFavorites"
:local-world-favorite-groups="localWorldFavoriteGroups"
:local-world-favorites-list="localWorldFavoritesList" />
<WorldExportDialog :world-export-dialog-visible.sync="worldExportDialogVisible" />
</div>
</template>
<script>
import FavoritesWorldItem from './FavoritesWorldItem.vue';
import WorldExportDialog from '../dialogs/WorldExportDialog.vue';
<script setup>
import { computed, ref, getCurrentInstance } from 'vue';
import { storeToRefs } from 'pinia';
import { useI18n } from 'vue-i18n-bridge';
import { favoriteRequest } from '../../../api';
import { useAppearanceSettingsStore, useFavoriteStore, useWorldStore } from '../../../stores';
import WorldExportDialog from '../dialogs/WorldExportDialog.vue';
import FavoritesWorldItem from './FavoritesWorldItem.vue';
export default {
name: 'FavoritesWorldTab',
components: {
FavoritesWorldItem,
WorldExportDialog
defineProps({
editFavoritesMode: {
type: Boolean,
default: false
},
inject: ['API', 'showWorldDialog'],
props: {
sortFavorites: Boolean,
hideTooltips: Boolean,
favoriteWorlds: Array,
editFavoritesMode: Boolean,
shiftHeld: Boolean,
refreshingLocalFavorites: Boolean,
localWorldFavoriteGroups: Array,
localWorldFavorites: Object,
localWorldFavoritesList: Array
},
data() {
return {
worldGroupVisibilityOptions: ['private', 'friends', 'public'],
worldFavoriteSearch: '',
worldExportDialogVisible: false,
worldFavoriteSearchResults: []
};
},
computed: {
groupedByGroupKeyFavoriteWorlds() {
const groupedByGroupKeyFavoriteWorlds = {};
refreshingLocalFavorites: {
type: Boolean,
default: false
}
});
this.favoriteWorlds.forEach((world) => {
if (world.groupKey) {
if (!groupedByGroupKeyFavoriteWorlds[world.groupKey]) {
groupedByGroupKeyFavoriteWorlds[world.groupKey] = [];
}
groupedByGroupKeyFavoriteWorlds[world.groupKey].push(world);
}
});
const emit = defineEmits([
'change-favorite-group-name',
'save-sort-favorites-option',
'refresh-local-world-favorite'
]);
return groupedByGroupKeyFavoriteWorlds;
},
sortFav: {
get() {
return this.sortFavorites;
},
set(value) {
this.$emit('update:sort-favorites', value);
const { proxy } = getCurrentInstance();
const { t } = useI18n();
const { hideTooltips, sortFavorites } = storeToRefs(useAppearanceSettingsStore());
const { setSortFavorites } = useAppearanceSettingsStore();
const { favoriteWorlds, favoriteWorldGroups, localWorldFavorites, localWorldFavoriteGroups } =
storeToRefs(useFavoriteStore());
const {
showWorldImportDialog,
getLocalWorldFavoriteGroupLength,
deleteLocalWorldFavoriteGroup,
renameLocalWorldFavoriteGroup,
removeLocalWorldFavorite,
newLocalWorldFavoriteGroup,
handleFavoriteGroup
} = useFavoriteStore();
const { showWorldDialog } = useWorldStore();
const worldGroupVisibilityOptions = ref(['private', 'friends', 'public']);
const worldExportDialogVisible = ref(false);
const worldFavoriteSearch = ref('');
const worldFavoriteSearchResults = ref([]);
const groupedByGroupKeyFavoriteWorlds = computed(() => {
const groupedByGroupKeyFavoriteWorlds = {};
favoriteWorlds.value.forEach((world) => {
if (world.groupKey) {
if (!groupedByGroupKeyFavoriteWorlds[world.groupKey]) {
groupedByGroupKeyFavoriteWorlds[world.groupKey] = [];
}
groupedByGroupKeyFavoriteWorlds[world.groupKey].push(world);
}
});
return groupedByGroupKeyFavoriteWorlds;
});
const sortFav = computed({
get() {
return sortFavorites.value;
},
set() {
setSortFavorites();
}
});
function showExportDialog() {
worldExportDialogVisible.value = true;
}
function userFavoriteWorldsStatusForFavTab(visibility) {
let style = '';
if (visibility === 'public') {
style = '';
} else if (visibility === 'friends') {
style = 'success';
} else {
style = 'info';
}
return style;
}
function changeWorldGroupVisibility(name, visibility) {
const params = {
type: 'world',
group: name,
visibility
};
favoriteRequest.saveFavoriteGroup(params).then((args) => {
handleFavoriteGroup({
json: args.json,
params: {
favoriteGroupId: args.json.id
}
});
proxy.$message({
message: 'Group visibility changed',
type: 'success'
});
return args;
});
}
function promptNewLocalWorldFavoriteGroup() {
proxy.$prompt(t('prompt.new_local_favorite_group.description'), t('prompt.new_local_favorite_group.header'), {
distinguishCancelAndClose: true,
confirmButtonText: t('prompt.new_local_favorite_group.ok'),
cancelButtonText: t('prompt.new_local_favorite_group.cancel'),
inputPattern: /\S+/,
inputErrorMessage: t('prompt.new_local_favorite_group.input_error'),
callback: (action, instance) => {
if (action === 'confirm' && instance.inputValue) {
newLocalWorldFavoriteGroup(instance.inputValue);
}
}
},
methods: {
showExportDialog() {
this.worldExportDialogVisible = true;
},
});
}
userFavoriteWorldsStatusForFavTab(visibility) {
let style = '';
if (visibility === 'public') {
style = '';
} else if (visibility === 'friends') {
style = 'success';
} else {
style = 'info';
function promptLocalWorldFavoriteGroupRename(group) {
proxy.$prompt(
t('prompt.local_favorite_group_rename.description'),
t('prompt.local_favorite_group_rename.header'),
{
distinguishCancelAndClose: true,
confirmButtonText: t('prompt.local_favorite_group_rename.save'),
cancelButtonText: t('prompt.local_favorite_group_rename.cancel'),
inputPattern: /\S+/,
inputErrorMessage: t('prompt.local_favorite_group_rename.input_error'),
inputValue: group,
callback: (action, instance) => {
if (action === 'confirm' && instance.inputValue) {
renameLocalWorldFavoriteGroup(instance.inputValue, group);
}
}
return style;
},
changeWorldGroupVisibility(name, visibility) {
const params = {
type: 'world',
group: name,
visibility
};
favoriteRequest.saveFavoriteGroup(params).then((args) => {
this.$message({
message: 'Group visibility changed',
type: 'success'
}
);
}
function promptLocalWorldFavoriteGroupDelete(group) {
proxy.$confirm(`Delete Group? ${group}`, 'Confirm', {
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel',
type: 'info',
callback: (action) => {
if (action === 'confirm') {
deleteLocalWorldFavoriteGroup(group);
}
}
});
}
function clearFavoriteGroup(ctx) {
proxy.$confirm('Continue? Clear Group', 'Confirm', {
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel',
type: 'info',
callback: (action) => {
if (action === 'confirm') {
favoriteRequest.clearFavoriteGroup({
type: ctx.type,
group: ctx.name
});
return args;
});
},
promptNewLocalWorldFavoriteGroup() {
this.$prompt(
$t('prompt.new_local_favorite_group.description'),
$t('prompt.new_local_favorite_group.header'),
{
distinguishCancelAndClose: true,
confirmButtonText: $t('prompt.new_local_favorite_group.ok'),
cancelButtonText: $t('prompt.new_local_favorite_group.cancel'),
inputPattern: /\S+/,
inputErrorMessage: $t('prompt.new_local_favorite_group.input_error'),
callback: (action, instance) => {
if (action === 'confirm' && instance.inputValue) {
this.$emit('new-local-world-favorite-group', instance.inputValue);
}
}
}
);
},
promptLocalWorldFavoriteGroupRename(group) {
this.$prompt(
$t('prompt.local_favorite_group_rename.description'),
$t('prompt.local_favorite_group_rename.header'),
{
distinguishCancelAndClose: true,
confirmButtonText: $t('prompt.local_favorite_group_rename.save'),
cancelButtonText: $t('prompt.local_favorite_group_rename.cancel'),
inputPattern: /\S+/,
inputErrorMessage: $t('prompt.local_favorite_group_rename.input_error'),
inputValue: group,
callback: (action, instance) => {
if (action === 'confirm' && instance.inputValue) {
this.$emit('rename-local-world-favorite-group', instance.inputValue, group);
}
}
}
);
},
promptLocalWorldFavoriteGroupDelete(group) {
this.$confirm(`Delete Group? ${group}`, 'Confirm', {
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel',
type: 'info',
callback: (action) => {
if (action === 'confirm') {
this.$emit('delete-local-world-favorite-group', group);
}
}
});
},
getLocalWorldFavoriteGroupLength(group) {
const favoriteGroup = this.localWorldFavorites[group];
if (!favoriteGroup) {
return 0;
}
return favoriteGroup.length;
},
}
});
}
clearFavoriteGroup(ctx) {
// FIXME: 메시지 수정
this.$confirm('Continue? Clear Group', 'Confirm', {
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel',
type: 'info',
callback: (action) => {
if (action === 'confirm') {
favoriteRequest.clearFavoriteGroup({
type: ctx.type,
group: ctx.name
});
}
}
});
},
searchWorldFavorites(worldFavoriteSearch) {
let ref = null;
const search = worldFavoriteSearch.toLowerCase();
if (search.length < 3) {
this.worldFavoriteSearchResults = [];
return;
function searchWorldFavorites(worldFavoriteSearch) {
let ref = null;
const search = worldFavoriteSearch.toLowerCase();
if (search.length < 3) {
worldFavoriteSearchResults.value = [];
return;
}
const results = [];
for (let i = 0; i < localWorldFavoriteGroups.value.length; ++i) {
const group = localWorldFavoriteGroups.value[i];
if (!localWorldFavorites.value[group]) {
continue;
}
for (let j = 0; j < localWorldFavorites.value[group].length; ++j) {
ref = localWorldFavorites.value[group][j];
if (
!ref ||
typeof ref.id === 'undefined' ||
typeof ref.name === 'undefined' ||
typeof ref.authorName === 'undefined'
) {
continue;
}
const results = [];
for (let i = 0; i < this.localWorldFavoriteGroups.length; ++i) {
const group = this.localWorldFavoriteGroups[i];
if (!this.localWorldFavorites[group]) {
continue;
}
for (let j = 0; j < this.localWorldFavorites[group].length; ++j) {
ref = this.localWorldFavorites[group][j];
if (
!ref ||
typeof ref.id === 'undefined' ||
typeof ref.name === 'undefined' ||
typeof ref.authorName === 'undefined'
) {
continue;
}
if (ref.name.toLowerCase().includes(search) || ref.authorName.toLowerCase().includes(search)) {
if (!results.some((r) => r.id === ref.id)) {
results.push(ref);
}
}
if (ref.name.toLowerCase().includes(search) || ref.authorName.toLowerCase().includes(search)) {
if (!results.some((r) => r.id === ref.id)) {
results.push(ref);
}
}
for (let i = 0; i < this.favoriteWorlds.length; ++i) {
ref = this.favoriteWorlds[i].ref;
if (
!ref ||
typeof ref.id === 'undefined' ||
typeof ref.name === 'undefined' ||
typeof ref.authorName === 'undefined'
) {
continue;
}
if (ref.name.toLowerCase().includes(search) || ref.authorName.toLowerCase().includes(search)) {
if (!results.some((r) => r.id === ref.id)) {
results.push(ref);
}
}
}
this.worldFavoriteSearchResults = results;
},
changeFavoriteGroupName(group) {
this.$emit('change-favorite-group-name', group);
},
newInstanceSelfInvite(event) {
this.$emit('new-instance-self-invite', event);
},
removeLocalWorldFavorite(param1, param2) {
this.$emit('remove-local-world-favorite', param1, param2);
}
}
};
for (let i = 0; i < favoriteWorlds.value.length; ++i) {
ref = favoriteWorlds.value[i].ref;
if (
!ref ||
typeof ref.id === 'undefined' ||
typeof ref.name === 'undefined' ||
typeof ref.authorName === 'undefined'
) {
continue;
}
if (ref.name.toLowerCase().includes(search) || ref.authorName.toLowerCase().includes(search)) {
if (!results.some((r) => r.id === ref.id)) {
results.push(ref);
}
}
}
worldFavoriteSearchResults.value = results;
}
function changeFavoriteGroupName(group) {
emit('change-favorite-group-name', group);
}
function refreshLocalWorldFavorite() {
emit('refresh-local-world-favorite');
}
function saveSortFavoritesOption() {
emit('save-sort-favorites-option');
}
</script>
<style scoped></style>
+145 -138
View File
@@ -1,5 +1,5 @@
<template>
<safe-dialog :visible.sync="isDialogVisible" :title="$t('dialog.avatar_export.header')" width="650px">
<safe-dialog :visible.sync="isDialogVisible" :title="t('dialog.avatar_export.header')" width="650px">
<el-checkbox-group
v-model="exportSelectedOptions"
style="margin-bottom: 10px"
@@ -26,7 +26,7 @@
<el-dropdown-item style="display: block; margin: 10px 0" @click.native="selectAvatarExportGroup(null)">
All Favorites
</el-dropdown-item>
<template v-for="groupAPI in API.favoriteAvatarGroups">
<template v-for="groupAPI in favoriteAvatarGroups">
<el-dropdown-item
:key="groupAPI.name"
style="display: block; margin: 10px 0"
@@ -79,145 +79,152 @@
</safe-dialog>
</template>
<script>
export default {
name: 'AvatarExportDialog',
inject: ['API'],
props: {
avatarExportDialogVisible: Boolean,
favoriteAvatars: Array,
localAvatarFavoriteGroups: Array,
localAvatarFavorites: Object,
localAvatarFavoritesList: Array
},
data() {
return {
avatarExportContent: '',
avatarExportFavoriteGroup: null,
avatarExportLocalFavoriteGroup: null,
exportSelectedOptions: ['ID', 'Name'],
exportSelectOptions: [
{ label: 'ID', value: 'id' },
{ label: 'Name', value: 'name' },
{ label: 'Author ID', value: 'authorId' },
{ label: 'Author Name', value: 'authorName' },
{ label: 'Thumbnail', value: 'thumbnailImageUrl' }
]
};
},
computed: {
isDialogVisible: {
get() {
return this.avatarExportDialogVisible;
},
set(value) {
this.$emit('update:avatar-export-dialog-visible', value);
}
}
},
watch: {
avatarExportDialogVisible(visible) {
if (visible) {
this.showAvatarExportDialog();
}
}
},
methods: {
showAvatarExportDialog() {
this.avatarExportFavoriteGroup = null;
this.avatarExportLocalFavoriteGroup = null;
this.updateAvatarExportDialog();
},
handleCopyAvatarExportData(event) {
if (event.target.tagName === 'TEXTAREA') {
event.target.select();
}
navigator.clipboard
.writeText(this.avatarExportContent)
.then(() => {
this.$message({
message: 'Copied successfully!',
type: 'success',
duration: 2000
});
})
.catch((err) => {
console.error('Copy failed:', err);
this.$message.error('Copy failed!');
});
},
updateAvatarExportDialog() {
const formatter = function (str) {
if (/[\x00-\x1f,"]/.test(str) === true) {
return `"${str.replace(/"/g, '""')}"`;
}
return str;
};
const propsForQuery = this.exportSelectOptions
.filter((option) => this.exportSelectedOptions.includes(option.label))
.map((option) => option.value);
<script setup>
import { ref, computed, watch, getCurrentInstance } from 'vue';
import { useI18n } from 'vue-i18n-bridge';
import { storeToRefs } from 'pinia';
import { useAvatarStore, useFavoriteStore } from '../../../stores';
function resText(ref) {
let resArr = [];
propsForQuery.forEach((e) => {
resArr.push(formatter(ref?.[e]));
});
return resArr.join(',');
}
const { t } = useI18n();
const { proxy } = getCurrentInstance();
const lines = [this.exportSelectedOptions.join(',')];
const props = defineProps({
avatarExportDialogVisible: {
type: Boolean,
required: true
}
});
if (this.avatarExportFavoriteGroup) {
this.API.favoriteAvatarGroups.forEach((group) => {
if (!this.avatarExportFavoriteGroup || this.avatarExportFavoriteGroup === group) {
this.favoriteAvatars.forEach((ref) => {
if (group.key === ref.groupKey) {
lines.push(resText(ref.ref));
}
});
}
});
} else if (this.avatarExportLocalFavoriteGroup) {
const favoriteGroup = this.localAvatarFavorites[this.avatarExportLocalFavoriteGroup];
if (!favoriteGroup) {
return;
}
for (let i = 0; i < favoriteGroup.length; ++i) {
const ref = favoriteGroup[i];
lines.push(resText(ref));
}
} else {
// export all
this.favoriteAvatars.forEach((ref) => {
lines.push(resText(ref.ref));
});
for (let i = 0; i < this.localAvatarFavoritesList.length; ++i) {
const avatarId = this.localAvatarFavoritesList[i];
const ref = this.API.cachedAvatars.get(avatarId);
if (typeof ref !== 'undefined') {
lines.push(resText(ref));
}
}
}
this.avatarExportContent = lines.join('\n');
},
selectAvatarExportGroup(group) {
this.avatarExportFavoriteGroup = group;
this.avatarExportLocalFavoriteGroup = null;
this.updateAvatarExportDialog();
},
selectAvatarExportLocalGroup(group) {
this.avatarExportLocalFavoriteGroup = group;
this.avatarExportFavoriteGroup = null;
this.updateAvatarExportDialog();
},
getLocalAvatarFavoriteGroupLength(group) {
const favoriteGroup = this.localAvatarFavorites[group];
if (!favoriteGroup) {
return 0;
}
return favoriteGroup.length;
const emit = defineEmits(['update:avatarExportDialogVisible']);
const favoriteStore = useFavoriteStore();
const {
favoriteAvatars,
favoriteAvatarGroups,
localAvatarFavorites,
localAvatarFavoritesList,
localAvatarFavoriteGroups
} = storeToRefs(favoriteStore);
const { getLocalAvatarFavoriteGroupLength } = favoriteStore;
const avatarStore = useAvatarStore();
const { cachedAvatars } = storeToRefs(avatarStore);
const avatarExportContent = ref('');
const avatarExportFavoriteGroup = ref(null);
const avatarExportLocalFavoriteGroup = ref(null);
const exportSelectedOptions = ref(['ID', 'Name']);
const exportSelectOptions = ref([
{ label: 'ID', value: 'id' },
{ label: 'Name', value: 'name' },
{ label: 'Author ID', value: 'authorId' },
{ label: 'Author Name', value: 'authorName' },
{ label: 'Thumbnail', value: 'thumbnailImageUrl' }
]);
const isDialogVisible = computed({
get() {
return props.avatarExportDialogVisible;
},
set(value) {
emit('update:avatarExportDialogVisible', value);
}
});
watch(
() => props.avatarExportDialogVisible,
(value) => {
if (value) {
showAvatarExportDialog();
}
}
};
);
function showAvatarExportDialog() {
avatarExportFavoriteGroup.value = null;
avatarExportLocalFavoriteGroup.value = null;
updateAvatarExportDialog();
}
function handleCopyAvatarExportData(event) {
if (event.target.tagName === 'TEXTAREA') {
event.target.select();
}
navigator.clipboard
.writeText(avatarExportContent.value)
.then(() => {
proxy.$message({
message: 'Copied successfully!',
type: 'success',
duration: 2000
});
})
.catch((err) => {
console.error('Copy failed:', err);
proxy.$message.error('Copy failed!');
});
}
function updateAvatarExportDialog() {
const formatter = function (str) {
if (/[\x00-\x1f,"]/.test(str) === true) {
return `"${str.replace(/"/g, '""')}"`;
}
return str;
};
const propsForQuery = exportSelectOptions.value
.filter((option) => exportSelectedOptions.value.includes(option.label))
.map((option) => option.value);
function resText(ref) {
let resArr = [];
propsForQuery.forEach((e) => {
resArr.push(formatter(ref?.[e]));
});
return resArr.join(',');
}
const lines = [exportSelectedOptions.value.join(',')];
if (avatarExportFavoriteGroup.value) {
favoriteAvatarGroups.value.forEach((group) => {
if (!avatarExportFavoriteGroup.value || avatarExportFavoriteGroup.value === group) {
favoriteAvatars.value.forEach((ref) => {
if (group.key === ref.groupKey) {
lines.push(resText(ref.ref));
}
});
}
});
} else if (avatarExportLocalFavoriteGroup.value) {
const favoriteGroup = localAvatarFavorites.value[avatarExportLocalFavoriteGroup.value];
if (!favoriteGroup) {
return;
}
for (let i = 0; i < favoriteGroup.length; ++i) {
const ref = favoriteGroup[i];
lines.push(resText(ref));
}
} else {
// export all
favoriteAvatars.value.forEach((ref) => {
lines.push(resText(ref.ref));
});
for (let i = 0; i < localAvatarFavoritesList.value.length; ++i) {
const avatarId = localAvatarFavoritesList.value[i];
const ref = cachedAvatars.value.get(avatarId);
if (typeof ref !== 'undefined') {
lines.push(resText(ref));
}
}
}
avatarExportContent.value = lines.join('\n');
}
function selectAvatarExportGroup(group) {
avatarExportFavoriteGroup.value = group;
avatarExportLocalFavoriteGroup.value = null;
updateAvatarExportDialog();
}
function selectAvatarExportLocalGroup(group) {
avatarExportLocalFavoriteGroup.value = group;
avatarExportFavoriteGroup.value = null;
updateAvatarExportDialog();
}
</script>
+198 -193
View File
@@ -1,22 +1,22 @@
<template>
<safe-dialog
ref="avatarImportDialog"
ref="avatarImportDialogRef"
:visible.sync="isVisible"
:title="$t('dialog.avatar_import.header')"
:title="t('dialog.avatar_import.header')"
width="650px">
<div style="display: flex; align-items: center; justify-content: space-between">
<div style="font-size: 12px">{{ $t('dialog.avatar_import.description') }}</div>
<div style="font-size: 12px">{{ t('dialog.avatar_import.description') }}</div>
<div style="display: flex; align-items: center">
<div v-if="avatarImportDialog.progress">
{{ $t('dialog.avatar_import.process_progress') }} {{ avatarImportDialog.progress }} /
{{ t('dialog.avatar_import.process_progress') }} {{ avatarImportDialog.progress }} /
{{ avatarImportDialog.progressTotal }}
<i class="el-icon-loading" style="margin: 0 5px"></i>
</div>
<el-button v-if="avatarImportDialog.loading" size="small" @click="cancelAvatarImport">
{{ $t('dialog.avatar_import.cancel') }}
{{ t('dialog.avatar_import.cancel') }}
</el-button>
<el-button v-else size="small" :disabled="!avatarImportDialog.input" @click="processAvatarImportList">
{{ $t('dialog.avatar_import.process_list') }}
{{ t('dialog.avatar_import.process_list') }}
</el-button>
</div>
</div>
@@ -38,12 +38,12 @@
<i class="el-icon-arrow-down el-icon--right"></i>
</span>
<span v-else>
{{ $t('dialog.avatar_import.select_group_placeholder') }}
{{ t('dialog.avatar_import.select_group_placeholder') }}
<i class="el-icon-arrow-down el-icon--right"></i>
</span>
</el-button>
<el-dropdown-menu slot="dropdown">
<template v-for="groupAPI in API.favoriteAvatarGroups">
<template v-for="groupAPI in favoriteAvatarGroups">
<el-dropdown-item
:key="groupAPI.name"
style="display: block; margin: 10px 0"
@@ -63,7 +63,7 @@
<i class="el-icon-arrow-down el-icon--right"></i>
</span>
<span v-else>
{{ $t('dialog.avatar_import.select_group_placeholder') }}
{{ t('dialog.avatar_import.select_group_placeholder') }}
<i class="el-icon-arrow-down el-icon--right"></i>
</span>
</el-button>
@@ -88,7 +88,7 @@
</div>
<div>
<el-button size="small" @click="clearAvatarImportTable">
{{ $t('dialog.avatar_import.clear_table') }}
{{ t('dialog.avatar_import.clear_table') }}
</el-button>
<el-button
size="small"
@@ -100,27 +100,27 @@
!avatarImportDialog.avatarImportLocalFavoriteGroup)
"
@click="importAvatarImportTable">
{{ $t('dialog.avatar_import.import') }}
{{ t('dialog.avatar_import.import') }}
</el-button>
</div>
</div>
<span v-if="avatarImportDialog.importProgress" style="margin: 10px">
<i class="el-icon-loading" style="margin-right: 5px"></i>
{{ $t('dialog.avatar_import.import_progress') }}
{{ t('dialog.avatar_import.import_progress') }}
{{ avatarImportDialog.importProgress }}/{{ avatarImportDialog.importProgressTotal }}
</span>
<br />
<template v-if="avatarImportDialog.errors">
<el-button size="small" @click="avatarImportDialog.errors = ''">
{{ $t('dialog.avatar_import.clear_errors') }}
{{ t('dialog.avatar_import.clear_errors') }}
</el-button>
<h2 style="font-weight: bold; margin: 5px 0">
{{ $t('dialog.avatar_import.errors') }}
{{ t('dialog.avatar_import.errors') }}
</h2>
<pre style="white-space: pre-wrap; font-size: 12px" v-text="avatarImportDialog.errors"></pre>
</template>
<data-tables v-loading="avatarImportDialog.loading" v-bind="avatarImportTable" style="margin-top: 10px">
<el-table-column :label="$t('table.import.image')" width="70" prop="thumbnailImageUrl">
<el-table-column :label="t('table.import.image')" width="70" prop="thumbnailImageUrl">
<template slot-scope="scope">
<el-popover placement="right" height="500px" trigger="hover">
<img slot="reference" v-lazy="scope.row.thumbnailImageUrl" class="friends-list-avatar" />
@@ -132,21 +132,21 @@
</el-popover>
</template>
</el-table-column>
<el-table-column :label="$t('table.import.name')" prop="name">
<el-table-column :label="t('table.import.name')" prop="name">
<template slot-scope="scope">
<span class="x-link" @click="showAvatarDialog(scope.row.id)">
{{ scope.row.name }}
</span>
</template>
</el-table-column>
<el-table-column :label="$t('table.import.author')" width="120" prop="authorName">
<el-table-column :label="t('table.import.author')" width="120" prop="authorName">
<template slot-scope="scope">
<span class="x-link" @click="showUserDialog(scope.row.authorId)">
{{ scope.row.authorName }}
</span>
</template>
</el-table-column>
<el-table-column :label="$t('table.import.status')" width="70" prop="releaseStatus">
<el-table-column :label="t('table.import.status')" width="70" prop="releaseStatus">
<template slot-scope="scope">
<span
:style="{
@@ -161,7 +161,7 @@
</span>
</template>
</el-table-column>
<el-table-column :label="$t('table.import.action')" width="90" align="right">
<el-table-column :label="t('table.import.action')" width="90" align="right">
<template slot-scope="scope">
<el-button type="text" icon="el-icon-close" size="mini" @click="deleteItemAvatarImport(scope.row)">
</el-button>
@@ -171,186 +171,191 @@
</safe-dialog>
</template>
<script>
<script setup>
import { ref, computed, watch, getCurrentInstance } from 'vue';
import { useI18n } from 'vue-i18n-bridge';
import { storeToRefs } from 'pinia';
import { avatarRequest, favoriteRequest } from '../../../api';
import utils from '../../../classes/utils';
import { adjustDialogZ, removeFromArray } from '../../../shared/utils';
import { useAvatarStore, useFavoriteStore, useGalleryStore, useUserStore } from '../../../stores';
export default {
name: 'AvatarImportDialog',
inject: ['API', 'adjustDialogZ', 'showFullscreenImageDialog', 'showUserDialog', 'showAvatarDialog'],
props: {
getLocalAvatarFavoriteGroupLength: Function,
localAvatarFavoriteGroups: Array,
avatarImportDialogInput: String,
avatarImportDialogVisible: Boolean
const emit = defineEmits(['update:avatarImportDialogInput']);
const { t } = useI18n();
const { proxy } = getCurrentInstance();
const { showUserDialog } = useUserStore();
const { favoriteAvatarGroups, avatarImportDialogInput, avatarImportDialogVisible, localAvatarFavoriteGroups } =
storeToRefs(useFavoriteStore());
const { addLocalAvatarFavorite, getLocalAvatarFavoriteGroupLength } = useFavoriteStore();
const { showAvatarDialog, applyAvatar } = useAvatarStore();
const { showFullscreenImageDialog } = useGalleryStore();
const avatarImportDialog = ref({
loading: false,
progress: 0,
progressTotal: 0,
input: '',
avatarIdList: new Set(),
errors: '',
avatarImportFavoriteGroup: null,
avatarImportLocalFavoriteGroup: null,
importProgress: 0,
importProgressTotal: 0
});
const avatarImportTable = ref({
data: [],
tableProps: {
stripe: true,
size: 'mini'
},
data() {
return {
avatarImportDialog: {
loading: false,
progress: 0,
progressTotal: 0,
input: '',
avatarIdList: new Set(),
errors: '',
avatarImportFavoriteGroup: null,
avatarImportLocalFavoriteGroup: null,
importProgress: 0,
importProgressTotal: 0
},
avatarImportTable: {
data: [],
tableProps: {
stripe: true,
size: 'mini'
},
layout: 'table'
}
};
layout: 'table'
});
const avatarImportDialogRef = ref(null);
const isVisible = computed({
get() {
return avatarImportDialogVisible.value;
},
computed: {
isVisible: {
get() {
return this.avatarImportDialogVisible;
},
set(value) {
this.$emit('update:avatar-import-dialog-visible', value);
}
}
},
watch: {
avatarImportDialogVisible(value) {
if (value) {
this.adjustDialogZ(this.$refs.avatarImportDialog.$el);
this.clearAvatarImportTable();
this.resetAvatarImport();
if (this.avatarImportDialogInput) {
this.avatarImportDialog.input = this.avatarImportDialogInput;
this.processAvatarImportList();
this.$emit('update:avatar-import-dialog-input', '');
}
}
}
},
methods: {
async processAvatarImportList() {
const D = this.avatarImportDialog;
D.loading = true;
const regexAvatarId = /avtr_[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}/g;
let match = [];
const avatarIdList = new Set();
while ((match = regexAvatarId.exec(D.input)) !== null) {
avatarIdList.add(match[0]);
}
D.input = '';
D.errors = '';
D.progress = 0;
D.progressTotal = avatarIdList.size;
const data = Array.from(avatarIdList);
for (let i = 0; i < data.length; ++i) {
if (!this.isVisible) {
this.resetAvatarImport();
}
if (!D.loading || !this.isVisible) {
break;
}
const avatarId = data[i];
if (!D.avatarIdList.has(avatarId)) {
try {
const args = await avatarRequest.getAvatar({
avatarId
});
this.avatarImportTable.data.push(args.ref);
D.avatarIdList.add(avatarId);
} catch (err) {
D.errors = D.errors.concat(`AvatarId: ${avatarId}\n${err}\n\n`);
}
}
D.progress++;
if (D.progress === avatarIdList.size) {
D.progress = 0;
}
}
D.loading = false;
},
set(value) {
avatarImportDialogVisible.value = value;
}
});
deleteItemAvatarImport(ref) {
utils.removeFromArray(this.avatarImportTable.data, ref);
this.avatarImportDialog.avatarIdList.delete(ref.id);
},
resetAvatarImport() {
this.avatarImportDialog.input = '';
this.avatarImportDialog.errors = '';
},
clearAvatarImportTable() {
this.avatarImportTable.data = [];
this.avatarImportDialog.avatarIdList = new Set();
},
selectAvatarImportGroup(group) {
this.avatarImportDialog.avatarImportLocalFavoriteGroup = null;
this.avatarImportDialog.avatarImportFavoriteGroup = group;
},
selectAvatarImportLocalGroup(group) {
this.avatarImportDialog.avatarImportFavoriteGroup = null;
this.avatarImportDialog.avatarImportLocalFavoriteGroup = group;
},
cancelAvatarImport() {
this.avatarImportDialog.loading = false;
},
addFavoriteAvatar(ref, group, message) {
return favoriteRequest
.addFavorite({
type: 'avatar',
favoriteId: ref.id,
tags: group.name
})
.then((args) => {
if (message) {
this.$message({
message: 'Avatar added to favorites',
type: 'success'
});
}
return args;
});
},
async importAvatarImportTable() {
const D = this.avatarImportDialog;
if (!D.avatarImportFavoriteGroup && !D.avatarImportLocalFavoriteGroup) {
return;
}
D.loading = true;
const data = [...this.avatarImportTable.data].reverse();
D.importProgressTotal = data.length;
let ref = '';
try {
for (let i = data.length - 1; i >= 0; i--) {
if (!D.loading || !this.isVisible) {
break;
}
ref = data[i];
if (D.avatarImportFavoriteGroup) {
await this.addFavoriteAvatar(ref, D.avatarImportFavoriteGroup, false);
} else if (D.avatarImportLocalFavoriteGroup) {
this.$emit('addLocalAvatarFavorite', ref.id, D.avatarImportLocalFavoriteGroup);
}
utils.removeFromArray(this.avatarImportTable.data, ref);
D.avatarIdList.delete(ref.id);
D.importProgress++;
}
} catch (err) {
D.errors = `Name: ${ref.name}\nAvatarId: ${ref.id}\n${err}\n\n`;
} finally {
D.importProgress = 0;
D.importProgressTotal = 0;
D.loading = false;
watch(
() => avatarImportDialogVisible.value,
(value) => {
if (value) {
adjustDialogZ(avatarImportDialogRef.value.$el);
clearAvatarImportTable();
resetAvatarImport();
if (avatarImportDialogInput.value) {
avatarImportDialog.value.input = avatarImportDialogInput.value;
processAvatarImportList();
emit('update:avatarImportDialogInput', '');
}
}
}
};
);
async function processAvatarImportList() {
const D = avatarImportDialog.value;
D.loading = true;
const regexAvatarId = /avtr_[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}/g;
let match = [];
const avatarIdList = new Set();
while ((match = regexAvatarId.exec(D.input)) !== null) {
avatarIdList.add(match[0]);
}
D.input = '';
D.errors = '';
D.progress = 0;
D.progressTotal = avatarIdList.size;
const data = Array.from(avatarIdList);
for (let i = 0; i < data.length; ++i) {
if (!isVisible.value) {
resetAvatarImport();
}
if (!D.loading || !isVisible.value) {
break;
}
const avatarId = data[i];
if (!D.avatarIdList.has(avatarId)) {
try {
const args = await avatarRequest.getAvatar({
avatarId
});
const ref = applyAvatar(args.json);
avatarImportTable.value.data.push(ref);
D.avatarIdList.add(avatarId);
} catch (err) {
D.errors = D.errors.concat(`AvatarId: ${avatarId}\n${err}\n\n`);
}
}
D.progress++;
if (D.progress === avatarIdList.size) {
D.progress = 0;
}
}
D.loading = false;
}
function deleteItemAvatarImport(ref) {
removeFromArray(avatarImportTable.value.data, ref);
avatarImportDialog.value.avatarIdList.delete(ref.id);
}
function resetAvatarImport() {
avatarImportDialog.value.input = '';
avatarImportDialog.value.errors = '';
}
function clearAvatarImportTable() {
avatarImportTable.value.data = [];
avatarImportDialog.value.avatarIdList = new Set();
}
function selectAvatarImportGroup(group) {
avatarImportDialog.value.avatarImportLocalFavoriteGroup = null;
avatarImportDialog.value.avatarImportFavoriteGroup = group;
}
function selectAvatarImportLocalGroup(group) {
avatarImportDialog.value.avatarImportFavoriteGroup = null;
avatarImportDialog.value.avatarImportLocalFavoriteGroup = group;
}
function cancelAvatarImport() {
avatarImportDialog.value.loading = false;
}
function addFavoriteAvatar(ref, group, message) {
return favoriteRequest
.addFavorite({
type: 'avatar',
favoriteId: ref.id,
tags: group.name
})
.then((args) => {
if (message) {
proxy.$message({
message: 'Avatar added to favorites',
type: 'success'
});
}
return args;
});
}
async function importAvatarImportTable() {
const D = avatarImportDialog.value;
if (!D.avatarImportFavoriteGroup && !D.avatarImportLocalFavoriteGroup) {
return;
}
D.loading = true;
const data = [...avatarImportTable.value.data].reverse();
D.importProgressTotal = data.length;
let ref = '';
try {
for (let i = data.length - 1; i >= 0; i--) {
if (!D.loading || !isVisible.value) {
break;
}
ref = data[i];
if (D.avatarImportFavoriteGroup) {
await addFavoriteAvatar(ref, D.avatarImportFavoriteGroup, false);
} else if (D.avatarImportLocalFavoriteGroup) {
addLocalAvatarFavorite(ref.id, D.avatarImportLocalFavoriteGroup);
}
removeFromArray(avatarImportTable.value.data, ref);
D.avatarIdList.delete(ref.id);
D.importProgress++;
}
} catch (err) {
D.errors = `Name: ${ref.name}\nAvatarId: ${ref.id}\n${err}\n\n`;
} finally {
D.importProgress = 0;
D.importProgressTotal = 0;
D.loading = false;
}
}
</script>
@@ -2,7 +2,7 @@
<safe-dialog
:visible.sync="isDialogVisible"
class="x-dialog"
:title="$t('dialog.friend_export.header')"
:title="t('dialog.friend_export.header')"
width="650px"
destroy-on-close>
<el-dropdown trigger="click" size="small" @click.native.stop>
@@ -19,7 +19,7 @@
<el-dropdown-item style="display: block; margin: 10px 0" @click.native="selectFriendExportGroup(null)">
All Favorites
</el-dropdown-item>
<template v-for="groupAPI in API.favoriteFriendGroups">
<template v-for="groupAPI in favoriteFriendGroups">
<el-dropdown-item
:key="groupAPI.name"
style="display: block; margin: 10px 0"
@@ -42,86 +42,94 @@
</safe-dialog>
</template>
<script>
export default {
name: 'FriendExportDialog',
inject: ['API'],
props: {
friendExportDialogVisible: Boolean,
favoriteFriends: Array
},
data() {
return {
friendExportFavoriteGroup: null,
friendExportContent: ''
};
},
computed: {
isDialogVisible: {
get() {
return this.friendExportDialogVisible;
},
set(value) {
this.$emit('update:friend-export-dialog-visible', value);
}
}
},
watch: {
friendExportDialogVisible(value) {
if (value) {
this.showFriendExportDialog();
}
}
},
methods: {
showFriendExportDialog() {
this.friendExportFavoriteGroup = null;
this.updateFriendExportDialog();
},
<script setup>
import { ref, computed, watch, getCurrentInstance } from 'vue';
import { useI18n } from 'vue-i18n-bridge';
import { storeToRefs } from 'pinia';
import { useFavoriteStore } from '../../../stores';
handleCopyFriendExportData(event) {
if (event.target.tagName === 'TEXTAREA') {
event.target.select();
}
navigator.clipboard
.writeText(this.friendExportContent)
.then(() => {
this.$message({
message: 'Copied successfully!',
type: 'success',
duration: 2000
});
})
.catch((err) => {
console.error('Copy failed:', err);
this.$message.error('Copy failed!');
});
},
const { t } = useI18n();
const { proxy } = getCurrentInstance();
updateFriendExportDialog() {
const _ = function (str) {
if (/[\x00-\x1f,"]/.test(str) === true) {
return `"${str.replace(/"/g, '""')}"`;
}
return str;
};
const lines = ['UserID,Name'];
this.API.favoriteFriendGroups.forEach((group) => {
if (!this.friendExportFavoriteGroup || this.friendExportFavoriteGroup === group) {
this.favoriteFriends.forEach((ref) => {
if (group.key === ref.groupKey) {
lines.push(`${_(ref.id)},${_(ref.name)}`);
}
});
}
});
this.friendExportContent = lines.join('\n');
},
const props = defineProps({
friendExportDialogVisible: {
type: Boolean,
required: true
}
});
selectFriendExportGroup(group) {
this.friendExportFavoriteGroup = group;
this.updateFriendExportDialog();
const emit = defineEmits(['update:friendExportDialogVisible']);
const favoriteStore = useFavoriteStore();
const { favoriteFriends, favoriteFriendGroups } = storeToRefs(favoriteStore);
const friendExportFavoriteGroup = ref(null);
const friendExportContent = ref('');
const isDialogVisible = computed({
get() {
return props.friendExportDialogVisible;
},
set(value) {
emit('update:friendExportDialogVisible', value);
}
});
watch(
() => props.friendExportDialogVisible,
(value) => {
if (value) {
showFriendExportDialog();
}
}
};
);
function showFriendExportDialog() {
friendExportFavoriteGroup.value = null;
updateFriendExportDialog();
}
function handleCopyFriendExportData(event) {
if (event.target.tagName === 'TEXTAREA') {
event.target.select();
}
navigator.clipboard
.writeText(friendExportContent.value)
.then(() => {
proxy.$message({
message: 'Copied successfully!',
type: 'success',
duration: 2000
});
})
.catch((err) => {
console.error('Copy failed:', err);
proxy.$message.error('Copy failed!');
});
}
function updateFriendExportDialog() {
const _ = function (str) {
if (/[\x00-\x1f,"]/.test(str) === true) {
return `"${str.replace(/"/g, '""')}"`;
}
return str;
};
const lines = ['UserID,Name'];
favoriteFriendGroups.value.forEach((group) => {
if (!friendExportFavoriteGroup.value || friendExportFavoriteGroup.value === group) {
favoriteFriends.value.forEach((ref) => {
if (group.key === ref.groupKey) {
lines.push(`${_(ref.id)},${_(ref.name)}`);
}
});
}
});
friendExportContent.value = lines.join('\n');
}
function selectFriendExportGroup(group) {
friendExportFavoriteGroup.value = group;
updateFriendExportDialog();
}
</script>
+179 -180
View File
@@ -1,22 +1,22 @@
<template>
<safe-dialog
ref="friendImportDialog"
ref="friendImportDialogRef"
:visible.sync="isVisible"
:title="$t('dialog.friend_import.header')"
:title="t('dialog.friend_import.header')"
width="650px">
<div style="display: flex; align-items: center; justify-content: space-between">
<div style="font-size: 12px">{{ $t('dialog.friend_import.description') }}</div>
<div style="font-size: 12px">{{ t('dialog.friend_import.description') }}</div>
<div style="display: flex; align-items: center">
<div v-if="friendImportDialog.progress">
{{ $t('dialog.friend_import.process_progress') }} {{ friendImportDialog.progress }} /
{{ t('dialog.friend_import.process_progress') }} {{ friendImportDialog.progress }} /
{{ friendImportDialog.progressTotal }}
<i class="el-icon-loading" style="margin: 0 5px"></i>
</div>
<el-button v-if="friendImportDialog.loading" size="small" @click="cancelFriendImport">
{{ $t('dialog.friend_import.cancel') }}
{{ t('dialog.friend_import.cancel') }}
</el-button>
<el-button v-else size="small" :disabled="!friendImportDialog.input" @click="processFriendImportList">
{{ $t('dialog.friend_import.process_list') }}
{{ t('dialog.friend_import.process_list') }}
</el-button>
</div>
</div>
@@ -38,12 +38,12 @@
<i class="el-icon-arrow-down el-icon--right"></i>
</span>
<span v-else
>{{ $t('dialog.friend_import.select_group_placeholder') }}
>{{ t('dialog.friend_import.select_group_placeholder') }}
<i class="el-icon-arrow-down el-icon--right"></i
></span>
</el-button>
<el-dropdown-menu slot="dropdown">
<template v-for="groupAPI in API.favoriteFriendGroups">
<template v-for="groupAPI in favoriteFriendGroups">
<el-dropdown-item
:key="groupAPI.name"
style="display: block; margin: 10px 0"
@@ -64,7 +64,7 @@
</div>
<div>
<el-button size="small" :disabled="friendImportTable.data.length === 0" @click="clearFriendImportTable">
{{ $t('dialog.friend_import.clear_table') }}
{{ t('dialog.friend_import.clear_table') }}
</el-button>
<el-button
size="small"
@@ -72,26 +72,26 @@
style="margin: 5px"
:disabled="friendImportTable.data.length === 0 || !friendImportDialog.friendImportFavoriteGroup"
@click="importFriendImportTable">
{{ $t('dialog.friend_import.import') }}
{{ t('dialog.friend_import.import') }}
</el-button>
</div>
</div>
<span v-if="friendImportDialog.importProgress" style="margin: 10px">
<i class="el-icon-loading" style="margin-right: 5px"></i>
{{ $t('dialog.friend_import.import_progress') }} {{ friendImportDialog.importProgress }}/{{
{{ t('dialog.friend_import.import_progress') }} {{ friendImportDialog.importProgress }}/{{
friendImportDialog.importProgressTotal
}}
</span>
<br />
<template v-if="friendImportDialog.errors">
<el-button size="small" @click="friendImportDialog.errors = ''">
{{ $t('dialog.friend_import.clear_errors') }}
{{ t('dialog.friend_import.clear_errors') }}
</el-button>
<h2 style="font-weight: bold; margin: 5px 0">{{ $t('dialog.friend_import.errors') }}</h2>
<h2 style="font-weight: bold; margin: 5px 0">{{ t('dialog.friend_import.errors') }}</h2>
<pre style="white-space: pre-wrap; font-size: 12px" v-text="friendImportDialog.errors"></pre>
</template>
<data-tables v-loading="friendImportDialog.loading" v-bind="friendImportTable" style="margin-top: 10px">
<el-table-column :label="$t('table.import.image')" width="70" prop="currentAvatarThumbnailImageUrl">
<el-table-column :label="t('table.import.image')" width="70" prop="currentAvatarThumbnailImageUrl">
<template slot-scope="scope">
<el-popover placement="right" height="500px" trigger="hover">
<template slot="reference">
@@ -105,14 +105,14 @@
</el-popover>
</template>
</el-table-column>
<el-table-column :label="$t('table.import.name')" prop="displayName">
<el-table-column :label="t('table.import.name')" prop="displayName">
<template slot-scope="scope">
<span class="x-link" :title="scope.row.displayName" @click="showUserDialog(scope.row.id)">
{{ scope.row.displayName }}
</span>
</template>
</el-table-column>
<el-table-column :label="$t('table.import.action')" width="90" align="right">
<el-table-column :label="t('table.import.action')" width="90" align="right">
<template slot-scope="scope">
<el-button type="text" icon="el-icon-close" size="mini" @click="deleteItemFriendImport(scope.row)">
</el-button>
@@ -122,175 +122,174 @@
</safe-dialog>
</template>
<script>
import utils from '../../../classes/utils';
<script setup>
import { ref, computed, watch, getCurrentInstance } from 'vue';
import { storeToRefs } from 'pinia';
import { useI18n } from 'vue-i18n-bridge';
import { favoriteRequest, userRequest } from '../../../api';
import { adjustDialogZ, removeFromArray, userImage, userImageFull } from '../../../shared/utils';
import { useFavoriteStore, useGalleryStore, useUserStore } from '../../../stores';
export default {
name: 'FriendImportDialog',
inject: ['API', 'userImage', 'userImageFull', 'showFullscreenImageDialog', 'showUserDialog', 'adjustDialogZ'],
props: {
friendImportDialogVisible: {
type: Boolean,
required: true
},
friendImportDialogInput: {
type: String,
required: false,
default: ''
}
const { proxy } = getCurrentInstance();
const { t } = useI18n();
const emit = defineEmits(['update:friendImportDialogInput']);
const { showUserDialog } = useUserStore();
const { favoriteFriendGroups, friendImportDialogInput, friendImportDialogVisible } =
storeToRefs(useFavoriteStore());
const { showFullscreenImageDialog } = useGalleryStore();
const friendImportDialog = ref({
loading: false,
progress: 0,
progressTotal: 0,
input: '',
userIdList: new Set(),
errors: '',
friendImportFavoriteGroup: null,
importProgress: 0,
importProgressTotal: 0
});
const friendImportTable = ref({
data: [],
tableProps: {
stripe: true,
size: 'mini'
},
data() {
return {
friendImportDialog: {
loading: false,
progress: 0,
progressTotal: 0,
input: '',
userIdList: new Set(),
errors: '',
friendImportFavoriteGroup: null,
importProgress: 0,
importProgressTotal: 0
},
friendImportTable: {
data: [],
tableProps: {
stripe: true,
size: 'mini'
},
layout: 'table'
}
};
layout: 'table'
});
const friendImportDialogRef = ref(null);
const isVisible = computed({
get() {
return friendImportDialogVisible.value;
},
computed: {
isVisible: {
get() {
return this.friendImportDialogVisible;
},
set(value) {
this.$emit('update:friend-import-dialog-visible', value);
set(value) {
friendImportDialogVisible.value = value;
}
});
watch(
() => friendImportDialogVisible.value,
(value) => {
if (value) {
adjustDialogZ(friendImportDialogRef.value.$el);
clearFriendImportTable();
resetFriendImport();
if (friendImportDialogInput.value) {
friendImportDialog.value.input = friendImportDialogInput.value;
processFriendImportList();
emit('update:friendImportDialogInput', '');
}
}
},
watch: {
friendImportDialogVisible(value) {
if (value) {
this.adjustDialogZ(this.$refs.friendImportDialog.$el);
this.clearFriendImportTable();
this.resetFriendImport();
if (this.friendImportDialogInput) {
this.friendImportDialog.input = this.friendImportDialogInput;
this.processFriendImportList();
this.$emit('update:friend-import-dialog-input', '');
}
}
}
},
methods: {
cancelFriendImport() {
this.friendImportDialog.loading = false;
},
deleteItemFriendImport(ref) {
utils.removeFromArray(this.friendImportTable.data, ref);
this.friendImportDialog.userIdList.delete(ref.id);
},
clearFriendImportTable() {
this.friendImportTable.data = [];
this.friendImportDialog.userIdList = new Set();
},
selectFriendImportGroup(group) {
this.friendImportDialog.friendImportFavoriteGroup = group;
},
async importFriendImportTable() {
const D = this.friendImportDialog;
D.loading = true;
if (!D.friendImportFavoriteGroup) {
return;
}
const data = [...this.friendImportTable.data].reverse();
D.importProgressTotal = data.length;
let ref = '';
try {
for (let i = data.length - 1; i >= 0; i--) {
if (!D.loading || !this.isVisible) {
break;
}
ref = data[i];
await this.addFavoriteUser(ref, D.friendImportFavoriteGroup, false);
utils.removeFromArray(this.friendImportTable.data, ref);
D.userIdList.delete(ref.id);
D.importProgress++;
}
} catch (err) {
D.errors = `Name: ${ref.displayName}\nUserId: ${ref.id}\n${err}\n\n`;
} finally {
D.importProgress = 0;
D.importProgressTotal = 0;
D.loading = false;
}
},
addFavoriteUser(ref, group, message) {
return favoriteRequest
.addFavorite({
type: 'friend',
favoriteId: ref.id,
tags: group.name
})
.then((args) => {
if (message) {
this.$message({
message: 'Friend added to favorites',
type: 'success'
});
}
return args;
});
},
async processFriendImportList() {
const D = this.friendImportDialog;
D.loading = true;
const regexFriendId = /usr_[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}/g;
let match = [];
const userIdList = new Set();
while ((match = regexFriendId.exec(D.input)) !== null) {
userIdList.add(match[0]);
}
D.input = '';
D.errors = '';
D.progress = 0;
D.progressTotal = userIdList.size;
const data = Array.from(userIdList);
for (let i = 0; i < data.length; ++i) {
if (!this.isVisible) {
this.resetFriendImport();
}
if (!D.loading || !this.isVisible) {
break;
}
const userId = data[i];
if (!D.userIdList.has(userId)) {
try {
const args = await userRequest.getUser({
userId
});
this.friendImportTable.data.push(args.ref);
D.userIdList.add(userId);
} catch (err) {
D.errors = D.errors.concat(`UserId: ${userId}\n${err}\n\n`);
}
}
D.progress++;
if (D.progress === userIdList.size) {
D.progress = 0;
}
}
D.loading = false;
},
resetFriendImport() {
this.friendImportDialog.input = '';
this.friendImportDialog.errors = '';
}
}
};
);
function cancelFriendImport() {
friendImportDialog.value.loading = false;
}
function deleteItemFriendImport(ref) {
removeFromArray(friendImportTable.value.data, ref);
friendImportDialog.value.userIdList.delete(ref.id);
}
function clearFriendImportTable() {
friendImportTable.value.data = [];
friendImportDialog.value.userIdList = new Set();
}
function selectFriendImportGroup(group) {
friendImportDialog.value.friendImportFavoriteGroup = group;
}
async function importFriendImportTable() {
const D = friendImportDialog.value;
D.loading = true;
if (!D.friendImportFavoriteGroup) {
return;
}
const data = [...friendImportTable.value.data].reverse();
D.importProgressTotal = data.length;
let ref = '';
try {
for (let i = data.length - 1; i >= 0; i--) {
if (!D.loading || !isVisible.value) {
break;
}
ref = data[i];
await addFavoriteUser(ref, D.friendImportFavoriteGroup, false);
removeFromArray(friendImportTable.value.data, ref);
D.userIdList.delete(ref.id);
D.importProgress++;
}
} catch (err) {
D.errors = `Name: ${ref.displayName}\nUserId: ${ref.id}\n${err}\n\n`;
} finally {
D.importProgress = 0;
D.importProgressTotal = 0;
D.loading = false;
}
}
function addFavoriteUser(ref, group, message) {
return favoriteRequest
.addFavorite({
type: 'friend',
favoriteId: ref.id,
tags: group.name
})
.then((args) => {
if (message) {
proxy.$message({
message: 'Friend added to favorites',
type: 'success'
});
}
return args;
});
}
async function processFriendImportList() {
const D = friendImportDialog.value;
D.loading = true;
const regexFriendId = /usr_[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}/g;
let match = [];
const userIdList = new Set();
while ((match = regexFriendId.exec(D.input)) !== null) {
userIdList.add(match[0]);
}
D.input = '';
D.errors = '';
D.progress = 0;
D.progressTotal = userIdList.size;
const data = Array.from(userIdList);
for (let i = 0; i < data.length; ++i) {
if (!isVisible.value) {
resetFriendImport();
}
if (!D.loading || !isVisible.value) {
break;
}
const userId = data[i];
if (!D.userIdList.has(userId)) {
try {
const args = await userRequest.getUser({
userId
});
friendImportTable.value.data.push(args.ref);
D.userIdList.add(userId);
} catch (err) {
D.errors = D.errors.concat(`UserId: ${userId}\n${err}\n\n`);
}
}
D.progress++;
if (D.progress === userIdList.size) {
D.progress = 0;
}
}
D.loading = false;
}
function resetFriendImport() {
friendImportDialog.value.input = '';
friendImportDialog.value.errors = '';
}
</script>
+151 -145
View File
@@ -1,5 +1,5 @@
<template>
<safe-dialog :visible.sync="isDialogVisible" :title="$t('dialog.world_export.header')" width="650px">
<safe-dialog :visible.sync="isDialogVisible" :title="t('dialog.world_export.header')" width="650px">
<el-checkbox-group
v-model="exportSelectedOptions"
style="margin-bottom: 10px"
@@ -26,7 +26,7 @@
<el-dropdown-item style="display: block; margin: 10px 0" @click.native="selectWorldExportGroup(null)">
None
</el-dropdown-item>
<template v-for="groupAPI in API.favoriteWorldGroups">
<template v-for="groupAPI in favoriteWorldGroups">
<el-dropdown-item
:key="groupAPI.name"
style="display: block; margin: 10px 0"
@@ -81,151 +81,157 @@
</safe-dialog>
</template>
<script>
export default {
name: 'WorldExportDialog',
inject: ['API'],
props: {
favoriteWorlds: Array,
worldExportDialogVisible: Boolean,
localWorldFavorites: Object,
localWorldFavoriteGroups: Array,
localWorldFavoritesList: Array
<script setup>
import { ref, computed, watch, getCurrentInstance } from 'vue';
import { useI18n } from 'vue-i18n-bridge';
import { storeToRefs } from 'pinia';
import { useFavoriteStore, useWorldStore } from '../../../stores';
const props = defineProps({
worldExportDialogVisible: {
type: Boolean,
required: true
}
});
const emit = defineEmits(['update:WorldExportDialogVisible']);
const { t } = useI18n();
const { proxy } = getCurrentInstance();
const favoriteStore = useFavoriteStore();
const {
favoriteWorlds,
favoriteWorldGroups,
localWorldFavorites,
localWorldFavoriteGroups,
localWorldFavoritesList
} = storeToRefs(favoriteStore);
const { getLocalWorldFavoriteGroupLength } = favoriteStore;
const { cachedWorlds } = storeToRefs(useWorldStore());
const worldExportContent = ref('');
const worldExportFavoriteGroup = ref(null);
const worldExportLocalFavoriteGroup = ref(null);
// Storage of selected filtering options for model and world export
const exportSelectedOptions = ref(['ID', 'Name']);
const exportSelectOptions = ref([
{ label: 'ID', value: 'id' },
{ label: 'Name', value: 'name' },
{ label: 'Author ID', value: 'authorId' },
{ label: 'Author Name', value: 'authorName' },
{ label: 'Thumbnail', value: 'thumbnailImageUrl' }
]);
const isDialogVisible = computed({
get() {
return props.worldExportDialogVisible;
},
data() {
return {
worldExportContent: '',
worldExportFavoriteGroup: null,
worldExportLocalFavoriteGroup: null,
// Storage of selected filtering options for model and world export
exportSelectedOptions: ['ID', 'Name'],
exportSelectOptions: [
{ label: 'ID', value: 'id' },
{ label: 'Name', value: 'name' },
{ label: 'Author ID', value: 'authorId' },
{ label: 'Author Name', value: 'authorName' },
{ label: 'Thumbnail', value: 'thumbnailImageUrl' }
]
};
},
computed: {
isDialogVisible: {
get() {
return this.worldExportDialogVisible;
},
set(value) {
this.$emit('update:world-export-dialog-visible', value);
}
}
},
watch: {
worldExportDialogVisible(value) {
if (value) {
this.showWorldExportDialog();
}
}
},
methods: {
showWorldExportDialog() {
this.worldExportFavoriteGroup = null;
this.worldExportLocalFavoriteGroup = null;
this.updateWorldExportDialog();
},
set(value) {
emit('update:WorldExportDialogVisible', value);
}
});
handleCopyWorldExportData(event) {
if (event.target.tagName === 'TEXTAREA') {
event.target.select();
}
navigator.clipboard
.writeText(this.worldExportContent)
.then(() => {
this.$message({
message: 'Copied successfully!',
type: 'success',
duration: 2000
});
})
.catch((err) => {
console.error('Copy failed:', err);
this.$message.error('Copy failed!');
});
},
updateWorldExportDialog() {
const formatter = function (str) {
if (/[\x00-\x1f,"]/.test(str) === true) {
return `"${str.replace(/"/g, '""')}"`;
}
return str;
};
const propsForQuery = this.exportSelectOptions
.filter((option) => this.exportSelectedOptions.includes(option.label))
.map((option) => option.value);
function resText(ref) {
let resArr = [];
propsForQuery.forEach((e) => {
resArr.push(formatter(ref?.[e]));
});
return resArr.join(',');
}
const lines = [this.exportSelectedOptions.join(',')];
if (this.worldExportFavoriteGroup) {
this.API.favoriteWorldGroups.forEach((group) => {
if (this.worldExportFavoriteGroup === group) {
this.favoriteWorlds.forEach((ref) => {
if (group.key === ref.groupKey) {
lines.push(resText(ref.ref));
}
});
}
});
} else if (this.worldExportLocalFavoriteGroup) {
const favoriteGroup = this.localWorldFavorites[this.worldExportLocalFavoriteGroup];
if (!favoriteGroup) {
return;
}
for (let i = 0; i < favoriteGroup.length; ++i) {
const ref = favoriteGroup[i];
lines.push(resText(ref));
}
} else {
// export all
this.favoriteWorlds.forEach((ref) => {
lines.push(resText(ref.ref));
});
for (let i = 0; i < this.localWorldFavoritesList.length; ++i) {
const worldId = this.localWorldFavoritesList[i];
const ref = this.API.cachedWorlds.get(worldId);
if (typeof ref !== 'undefined') {
lines.push(resText(ref));
}
}
}
this.worldExportContent = lines.join('\n');
},
selectWorldExportGroup(group) {
this.worldExportFavoriteGroup = group;
this.worldExportLocalFavoriteGroup = null;
this.updateWorldExportDialog();
},
selectWorldExportLocalGroup(group) {
this.worldExportLocalFavoriteGroup = group;
this.worldExportFavoriteGroup = null;
this.updateWorldExportDialog();
},
getLocalWorldFavoriteGroupLength(group) {
const favoriteGroup = this.localWorldFavorites[group];
if (!favoriteGroup) {
return 0;
}
return favoriteGroup.length;
watch(
() => props.worldExportDialogVisible,
(value) => {
if (value) {
showWorldExportDialog();
}
}
};
);
function showWorldExportDialog() {
worldExportFavoriteGroup.value = null;
worldExportLocalFavoriteGroup.value = null;
updateWorldExportDialog();
}
function handleCopyWorldExportData(event) {
if (event.target.tagName === 'TEXTAREA') {
event.target.select();
}
navigator.clipboard
.writeText(worldExportContent.value)
.then(() => {
proxy.$message({
message: 'Copied successfully!',
type: 'success',
duration: 2000
});
})
.catch((err) => {
console.error('Copy failed:', err);
proxy.$message.error('Copy failed!');
});
}
function updateWorldExportDialog() {
const formatter = function (str) {
if (/[\x00-\x1f,"]/.test(str) === true) {
return `"${str.replace(/"/g, '""')}"`;
}
return str;
};
const propsForQuery = exportSelectOptions.value
.filter((option) => exportSelectedOptions.value.includes(option.label))
.map((option) => option.value);
function resText(ref) {
let resArr = [];
propsForQuery.forEach((e) => {
resArr.push(formatter(ref?.[e]));
});
return resArr.join(',');
}
const lines = [exportSelectedOptions.value.join(',')];
if (worldExportFavoriteGroup.value) {
favoriteWorldGroups.value.forEach((group) => {
if (worldExportFavoriteGroup.value === group) {
favoriteWorlds.value.forEach((ref) => {
if (group.key === ref.groupKey) {
lines.push(resText(ref.ref));
}
});
}
});
} else if (worldExportLocalFavoriteGroup.value) {
const favoriteGroup = localWorldFavorites.value[worldExportLocalFavoriteGroup.value];
if (!favoriteGroup) {
return;
}
for (let i = 0; i < favoriteGroup.length; ++i) {
const ref = favoriteGroup[i];
lines.push(resText(ref));
}
} else {
// export all
favoriteWorlds.value.forEach((ref) => {
lines.push(resText(ref.ref));
});
for (let i = 0; i < localWorldFavoritesList.value.length; ++i) {
const worldId = localWorldFavoritesList.value[i];
const ref = cachedWorlds.value.get(worldId);
if (typeof ref !== 'undefined') {
lines.push(resText(ref));
}
}
}
worldExportContent.value = lines.join('\n');
}
function selectWorldExportGroup(group) {
worldExportFavoriteGroup.value = group;
worldExportLocalFavoriteGroup.value = null;
updateWorldExportDialog();
}
function selectWorldExportLocalGroup(group) {
worldExportLocalFavoriteGroup.value = group;
worldExportFavoriteGroup.value = null;
updateWorldExportDialog();
}
</script>
+200 -192
View File
@@ -1,24 +1,24 @@
<template>
<safe-dialog
ref="worldImportDialog"
ref="worldImportDialogRef"
:visible.sync="isVisible"
:title="$t('dialog.world_import.header')"
:title="t('dialog.world_import.header')"
width="650px"
top="10vh"
class="x-dialog">
<div style="display: flex; align-items: center; justify-content: space-between">
<div style="font-size: 12px">{{ $t('dialog.world_import.description') }}</div>
<div style="font-size: 12px">{{ t('dialog.world_import.description') }}</div>
<div style="display: flex; align-items: center">
<div v-if="worldImportDialog.progress">
{{ $t('dialog.world_import.process_progress') }}
{{ t('dialog.world_import.process_progress') }}
{{ worldImportDialog.progress }} / {{ worldImportDialog.progressTotal }}
<i class="el-icon-loading" style="margin: 0 5px"></i>
</div>
<el-button v-if="worldImportDialog.loading" size="small" @click="cancelWorldImport">
{{ $t('dialog.world_import.cancel') }}
{{ t('dialog.world_import.cancel') }}
</el-button>
<el-button v-else size="small" :disabled="!worldImportDialog.input" @click="processWorldImportList">
{{ $t('dialog.world_import.process_list') }}
{{ t('dialog.world_import.process_list') }}
</el-button>
</div>
</div>
@@ -41,12 +41,12 @@
<i class="el-icon-arrow-down el-icon--right"></i>
</span>
<span v-else>
{{ $t('dialog.world_import.select_vrchat_group_placeholder') }}
{{ t('dialog.world_import.select_vrchat_group_placeholder') }}
<i class="el-icon-arrow-down el-icon--right"></i>
</span>
</el-button>
<el-dropdown-menu slot="dropdown">
<template v-for="groupAPI in API.favoriteWorldGroups">
<template v-for="groupAPI in favoriteWorldGroups">
<el-dropdown-item
:key="groupAPI.name"
style="display: block; margin: 10px 0"
@@ -65,7 +65,7 @@
<i class="el-icon-arrow-down el-icon--right"></i>
</span>
<span v-else>
{{ $t('dialog.world_import.select_local_group_placeholder') }}
{{ t('dialog.world_import.select_local_group_placeholder') }}
<i class="el-icon-arrow-down el-icon--right"></i>
</span>
</el-button>
@@ -90,7 +90,7 @@
</div>
<div>
<el-button size="small" :disabled="worldImportTable.data.length === 0" @click="clearWorldImportTable">
{{ $t('dialog.world_import.clear_table') }}
{{ t('dialog.world_import.clear_table') }}
</el-button>
<el-button
size="small"
@@ -102,27 +102,27 @@
!worldImportDialog.worldImportLocalFavoriteGroup)
"
@click="importWorldImportTable">
{{ $t('dialog.world_import.import') }}
{{ t('dialog.world_import.import') }}
</el-button>
</div>
</div>
<span v-if="worldImportDialog.importProgress" style="margin: 10px">
<i class="el-icon-loading" style="margin-right: 5px"></i>
{{ $t('dialog.world_import.import_progress') }}
{{ t('dialog.world_import.import_progress') }}
{{ worldImportDialog.importProgress }}/{{ worldImportDialog.importProgressTotal }}
</span>
<br />
<template v-if="worldImportDialog.errors">
<el-button size="small" @click="worldImportDialog.errors = ''">
{{ $t('dialog.world_import.clear_errors') }}
{{ t('dialog.world_import.clear_errors') }}
</el-button>
<h2 style="font-weight: bold; margin: 5px 0">
{{ $t('dialog.world_import.errors') }}
{{ t('dialog.world_import.errors') }}
</h2>
<pre style="white-space: pre-wrap; font-size: 12px" v-text="worldImportDialog.errors"></pre>
</template>
<data-tables v-loading="worldImportDialog.loading" v-bind="worldImportTable" style="margin-top: 10px">
<el-table-column :label="$t('table.import.image')" width="70" prop="thumbnailImageUrl">
<el-table-column :label="t('table.import.image')" width="70" prop="thumbnailImageUrl">
<template slot-scope="scope">
<el-popover placement="right" height="500px" trigger="hover">
<img slot="reference" v-lazy="scope.row.thumbnailImageUrl" class="friends-list-avatar" />
@@ -134,12 +134,12 @@
</el-popover>
</template>
</el-table-column>
<el-table-column :label="$t('table.import.name')" prop="name">
<el-table-column :label="t('table.import.name')" prop="name">
<template slot-scope="scope">
<span class="x-link" @click="showWorldDialog(scope.row.id)" v-text="scope.row.name"></span>
</template>
</el-table-column>
<el-table-column :label="$t('table.import.author')" width="120" prop="authorName">
<el-table-column :label="t('table.import.author')" width="120" prop="authorName">
<template slot-scope="scope">
<span
class="x-link"
@@ -147,7 +147,7 @@
v-text="scope.row.authorName"></span>
</template>
</el-table-column>
<el-table-column :label="$t('table.import.status')" width="70" prop="releaseStatus">
<el-table-column :label="t('table.import.status')" width="70" prop="releaseStatus">
<template slot-scope="scope">
<span
:style="{
@@ -163,7 +163,7 @@
"></span>
</template>
</el-table-column>
<el-table-column :label="$t('table.import.action')" width="90" align="right">
<el-table-column :label="t('table.import.action')" width="90" align="right">
<template slot-scope="scope">
<el-button
type="text"
@@ -176,185 +176,193 @@
</safe-dialog>
</template>
<script>
<script setup>
import { ref, watch, computed, getCurrentInstance } from 'vue';
import { useI18n } from 'vue-i18n-bridge';
import { storeToRefs } from 'pinia';
import { favoriteRequest, worldRequest } from '../../../api';
import utils from '../../../classes/utils';
import { adjustDialogZ, removeFromArray } from '../../../shared/utils';
import { useFavoriteStore, useGalleryStore, useUserStore, useWorldStore } from '../../../stores';
export default {
name: 'WorldImportDialog',
inject: ['API', 'showFullscreenImageDialog', 'showUserDialog', 'adjustDialogZ', 'showWorldDialog'],
props: {
worldImportDialogVisible: Boolean,
worldImportDialogInput: String,
getLocalWorldFavoriteGroupLength: Function,
localWorldFavoriteGroups: Array
const { showUserDialog } = useUserStore();
const { favoriteWorldGroups, worldImportDialogInput, worldImportDialogVisible, localWorldFavoriteGroups } =
storeToRefs(useFavoriteStore());
const { getLocalWorldFavoriteGroupLength, addLocalWorldFavorite } = useFavoriteStore();
const { showWorldDialog } = useWorldStore();
const { showFullscreenImageDialog } = useGalleryStore();
const emit = defineEmits(['update:worldImportDialogInput']);
const { proxy } = getCurrentInstance();
const { t } = useI18n();
const worldImportDialogRef = ref(null);
const worldImportDialog = ref({
loading: false,
progress: 0,
progressTotal: 0,
input: '',
worldIdList: new Set(),
errors: '',
worldImportFavoriteGroup: null,
worldImportLocalFavoriteGroup: null,
importProgress: 0,
importProgressTotal: 0
});
const worldImportTable = ref({
data: [],
tableProps: {
stripe: true,
size: 'mini'
},
data() {
return {
worldImportDialog: {
loading: false,
progress: 0,
progressTotal: 0,
input: '',
worldIdList: new Set(),
errors: '',
worldImportFavoriteGroup: null,
worldImportLocalFavoriteGroup: null,
importProgress: 0,
importProgressTotal: 0
},
worldImportTable: {
data: [],
tableProps: {
stripe: true,
size: 'mini'
},
layout: 'table'
}
};
layout: 'table'
});
const isVisible = computed({
get() {
return worldImportDialogVisible.value;
},
computed: {
isVisible: {
get() {
return this.worldImportDialogVisible;
},
set(visible) {
this.$emit('update:world-import-dialog-visible', visible);
}
}
},
watch: {
worldImportDialogVisible(visible) {
if (visible) {
this.adjustDialogZ(this.$refs.worldImportDialog.$el);
this.clearWorldImportTable();
this.resetWorldImport();
if (this.worldImportDialogInput) {
this.worldImportDialog.input = this.worldImportDialogInput;
this.processWorldImportList();
this.$emit('update:world-import-dialog-input', '');
}
}
}
},
methods: {
resetWorldImport() {
this.worldImportDialog.input = '';
this.worldImportDialog.errors = '';
},
async processWorldImportList() {
const D = this.worldImportDialog;
D.loading = true;
const regexWorldId = /wrld_[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}/g;
let match = [];
const worldIdList = new Set();
while ((match = regexWorldId.exec(D.input)) !== null) {
worldIdList.add(match[0]);
}
D.input = '';
D.errors = '';
D.progress = 0;
D.progressTotal = worldIdList.size;
const data = Array.from(worldIdList);
for (let i = 0; i < data.length; ++i) {
if (!this.isVisible) {
this.resetWorldImport();
}
if (!D.loading || !this.isVisible) {
break;
}
const worldId = data[i];
if (!D.worldIdList.has(worldId)) {
try {
const args = await worldRequest.getWorld({
worldId
});
this.worldImportTable.data.push(args.ref);
D.worldIdList.add(worldId);
} catch (err) {
D.errors = D.errors.concat(`WorldId: ${worldId}\n${err}\n\n`);
}
}
D.progress++;
if (D.progress === worldIdList.size) {
D.progress = 0;
}
}
D.loading = false;
},
deleteItemWorldImport(ref) {
utils.removeFromArray(this.worldImportTable.data, ref);
this.worldImportDialog.worldIdList.delete(ref.id);
},
set(visible) {
worldImportDialogVisible.value = visible;
}
});
clearWorldImportTable() {
this.worldImportTable.data = [];
this.worldImportDialog.worldIdList = new Set();
},
selectWorldImportGroup(group) {
this.worldImportDialog.worldImportLocalFavoriteGroup = null;
this.worldImportDialog.worldImportFavoriteGroup = group;
},
selectWorldImportLocalGroup(group) {
this.worldImportDialog.worldImportFavoriteGroup = null;
this.worldImportDialog.worldImportLocalFavoriteGroup = group;
},
cancelWorldImport() {
this.worldImportDialog.loading = false;
},
async importWorldImportTable() {
const D = this.worldImportDialog;
if (!D.worldImportFavoriteGroup && !D.worldImportLocalFavoriteGroup) {
return;
watch(
() => worldImportDialogVisible.value,
(visible) => {
if (visible) {
adjustDialogZ(worldImportDialogRef.value.$el);
clearWorldImportTable();
resetWorldImport();
if (worldImportDialogInput.value) {
worldImportDialog.value.input = worldImportDialogInput.value;
processWorldImportList();
emit('update:worldImportDialogInput', '');
}
D.loading = true;
const data = [...this.worldImportTable.data].reverse();
D.importProgressTotal = data.length;
let ref = '';
try {
for (let i = data.length - 1; i >= 0; i--) {
if (!D.loading || !this.isVisible) {
break;
}
ref = data[i];
if (D.worldImportFavoriteGroup) {
await this.addFavoriteWorld(ref, D.worldImportFavoriteGroup, false);
} else if (D.worldImportLocalFavoriteGroup) {
this.$emit('addLocalWorldFavorite', ref.id, D.worldImportLocalFavoriteGroup);
}
utils.removeFromArray(this.worldImportTable.data, ref);
D.worldIdList.delete(ref.id);
D.importProgress++;
}
} catch (err) {
D.errors = `Name: ${ref.name}\nWorldId: ${ref.id}\n${err}\n\n`;
} finally {
D.importProgress = 0;
D.importProgressTotal = 0;
D.loading = false;
}
},
addFavoriteWorld(ref, group, message) {
return favoriteRequest
.addFavorite({
type: 'world',
favoriteId: ref.id,
tags: group.name
})
.then((args) => {
if (message) {
this.$message({
message: 'World added to favorites',
type: 'success'
});
}
return args;
});
}
}
};
);
function resetWorldImport() {
worldImportDialog.value.input = '';
worldImportDialog.value.errors = '';
}
async function processWorldImportList() {
const D = worldImportDialog.value;
D.loading = true;
const regexWorldId = /wrld_[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}/g;
let match = [];
const worldIdList = new Set();
while ((match = regexWorldId.exec(D.input)) !== null) {
worldIdList.add(match[0]);
}
D.input = '';
D.errors = '';
D.progress = 0;
D.progressTotal = worldIdList.size;
const data = Array.from(worldIdList);
for (let i = 0; i < data.length; ++i) {
if (!isVisible.value) {
resetWorldImport();
}
if (!D.loading || !isVisible.value) {
break;
}
const worldId = data[i];
if (!D.worldIdList.has(worldId)) {
try {
const args = await worldRequest.getWorld({
worldId
});
worldImportTable.value.data.push(args.ref);
D.worldIdList.add(worldId);
} catch (err) {
D.errors = D.errors.concat(`WorldId: ${worldId}\n${err}\n\n`);
}
}
D.progress++;
if (D.progress === worldIdList.size) {
D.progress = 0;
}
}
D.loading = false;
}
function deleteItemWorldImport(ref) {
removeFromArray(worldImportTable.value.data, ref);
worldImportDialog.value.worldIdList.delete(ref.id);
}
function clearWorldImportTable() {
worldImportTable.value.data = [];
worldImportDialog.value.worldIdList = new Set();
}
function selectWorldImportGroup(group) {
worldImportDialog.value.worldImportLocalFavoriteGroup = null;
worldImportDialog.value.worldImportFavoriteGroup = group;
}
function selectWorldImportLocalGroup(group) {
worldImportDialog.value.worldImportFavoriteGroup = null;
worldImportDialog.value.worldImportLocalFavoriteGroup = group;
}
function cancelWorldImport() {
worldImportDialog.value.loading = false;
}
async function importWorldImportTable() {
const D = worldImportDialog.value;
if (!D.worldImportFavoriteGroup && !D.worldImportLocalFavoriteGroup) {
return;
}
D.loading = true;
const data = [...worldImportTable.value.data].reverse();
D.importProgressTotal = data.length;
let ref = '';
try {
for (let i = data.length - 1; i >= 0; i--) {
if (!D.loading || !isVisible.value) {
break;
}
ref = data[i];
if (D.worldImportFavoriteGroup) {
await addFavoriteWorld(ref, D.worldImportFavoriteGroup, false);
} else if (D.worldImportLocalFavoriteGroup) {
addLocalWorldFavorite(ref, D.worldImportLocalFavoriteGroup);
}
removeFromArray(worldImportTable.value.data, ref);
D.worldIdList.delete(ref.id);
D.importProgress++;
}
} catch (err) {
D.errors = `Name: ${ref.name}\nWorldId: ${ref.id}\n${err}\n\n`;
} finally {
D.importProgress = 0;
D.importProgressTotal = 0;
D.loading = false;
}
}
function addFavoriteWorld(ref, group, message) {
return favoriteRequest
.addFavorite({
type: 'world',
favoriteId: ref.id,
tags: group.name
})
.then((args) => {
if (message) {
proxy.$message({
message: 'World added to favorites',
type: 'success'
});
}
return args;
});
}
</script>