mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-06 22:46:06 +02:00
Clean up setAvatarTagsDialog
This commit is contained in:
@@ -646,8 +646,7 @@
|
|||||||
visible: false,
|
visible: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
ownAvatars: [],
|
ownAvatars: [],
|
||||||
selectedCount: 0,
|
selectedAvatarIds: [],
|
||||||
forceUpdate: 0,
|
|
||||||
selectedTags: [],
|
selectedTags: [],
|
||||||
selectedTagsCsv: '',
|
selectedTagsCsv: '',
|
||||||
contentHorror: false,
|
contentHorror: false,
|
||||||
@@ -732,6 +731,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleDialogOpen() {
|
function handleDialogOpen() {
|
||||||
|
setAvatarTagsDialog.value.visible = false;
|
||||||
memo.value = '';
|
memo.value = '';
|
||||||
treeData.value = [];
|
treeData.value = [];
|
||||||
getAvatarTimeSpent();
|
getAvatarTimeSpent();
|
||||||
@@ -1057,10 +1057,10 @@
|
|||||||
|
|
||||||
function showSetAvatarTagsDialog(avatarId) {
|
function showSetAvatarTagsDialog(avatarId) {
|
||||||
const D = setAvatarTagsDialog.value;
|
const D = setAvatarTagsDialog.value;
|
||||||
|
D.selectedAvatarIds = [avatarId];
|
||||||
D.visible = true;
|
D.visible = true;
|
||||||
D.loading = true;
|
D.loading = true;
|
||||||
D.ownAvatars = [];
|
D.ownAvatars = [];
|
||||||
D.forceUpdate = 0;
|
|
||||||
D.selectedTags = [];
|
D.selectedTags = [];
|
||||||
D.selectedTagsCsv = '';
|
D.selectedTagsCsv = '';
|
||||||
D.contentHorror = false;
|
D.contentHorror = false;
|
||||||
@@ -1095,25 +1095,6 @@
|
|||||||
});
|
});
|
||||||
for (const ref of cachedAvatars.values()) {
|
for (const ref of cachedAvatars.values()) {
|
||||||
if (ref.authorId === currentUser.value.id) {
|
if (ref.authorId === currentUser.value.id) {
|
||||||
ref.$selected = false;
|
|
||||||
ref.$tagString = '';
|
|
||||||
if (avatarId === ref.id) {
|
|
||||||
ref.$selected = true;
|
|
||||||
const conentTags = [];
|
|
||||||
ref.tags.forEach((tag) => {
|
|
||||||
if (tag.startsWith('content_')) {
|
|
||||||
conentTags.push(tag.substring(8));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
for (let i = 0; i < conentTags.length; ++i) {
|
|
||||||
const tag = conentTags[i];
|
|
||||||
if (i < conentTags.length - 1) {
|
|
||||||
ref.$tagString += `${tag}, `;
|
|
||||||
} else {
|
|
||||||
ref.$tagString += tag;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
D.ownAvatars.push(ref);
|
D.ownAvatars.push(ref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,8 @@
|
|||||||
:placeholder="t('dialog.set_avatar_tags.custom_tags_placeholder')"
|
:placeholder="t('dialog.set_avatar_tags.custom_tags_placeholder')"
|
||||||
style="margin-top: 10px"
|
style="margin-top: 10px"
|
||||||
@input="updateInputAvatarTags"></el-input>
|
@input="updateInputAvatarTags"></el-input>
|
||||||
<template v-if="setAvatarTagsDialog.ownAvatars.length === setAvatarTagsDialog.selectedCount">
|
<template
|
||||||
|
v-if="setAvatarTagsDialog.ownAvatars.length === props.setAvatarTagsDialog.selectedAvatarIds.length">
|
||||||
<el-button size="small" @click="setAvatarTagsSelectToggle">{{
|
<el-button size="small" @click="setAvatarTagsSelectToggle">{{
|
||||||
t('dialog.set_avatar_tags.select_none')
|
t('dialog.set_avatar_tags.select_none')
|
||||||
}}</el-button>
|
}}</el-button>
|
||||||
@@ -46,7 +47,8 @@
|
|||||||
}}</el-button>
|
}}</el-button>
|
||||||
</template>
|
</template>
|
||||||
<span style="margin-left: 5px"
|
<span style="margin-left: 5px"
|
||||||
>{{ setAvatarTagsDialog.selectedCount }} / {{ setAvatarTagsDialog.ownAvatars.length }}</span
|
>{{ props.setAvatarTagsDialog.selectedAvatarIds.length }} /
|
||||||
|
{{ setAvatarTagsDialog.ownAvatars.length }}</span
|
||||||
>
|
>
|
||||||
<el-icon v-if="setAvatarTagsDialog.loading" class="is-loading" style="margin-left: 5px"
|
<el-icon v-if="setAvatarTagsDialog.loading" class="is-loading" style="margin-left: 5px"
|
||||||
><Loading
|
><Loading
|
||||||
@@ -74,10 +76,12 @@
|
|||||||
style="color: #f56c6c"
|
style="color: #f56c6c"
|
||||||
v-text="avatar.releaseStatus"></span>
|
v-text="avatar.releaseStatus"></span>
|
||||||
<span v-else class="extra" v-text="avatar.releaseStatus"></span>
|
<span v-else class="extra" v-text="avatar.releaseStatus"></span>
|
||||||
<span class="extra" v-text="avatar.$tagString"></span>
|
<span class="extra" v-text="avatarTagStrings.get(avatar.id)"></span>
|
||||||
</div>
|
</div>
|
||||||
<el-button type="text" size="small" style="margin-left: 5px" @click.stop>
|
<el-button type="text" size="small" style="margin-left: 5px" @click.stop>
|
||||||
<el-checkbox v-model="avatar.$selected" @change="updateAvatarTagsSelection"></el-checkbox>
|
<el-checkbox
|
||||||
|
:model-value="props.setAvatarTagsDialog.selectedAvatarIds.includes(avatar.id)"
|
||||||
|
@click="toggleAvatarSelection(avatar.id)"></el-checkbox>
|
||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -98,9 +102,11 @@
|
|||||||
import { watch } from 'vue';
|
import { watch } from 'vue';
|
||||||
|
|
||||||
import { avatarRequest } from '../../../api';
|
import { avatarRequest } from '../../../api';
|
||||||
|
import { removeFromArray } from '../../../shared/utils';
|
||||||
import { useAvatarStore } from '../../../stores';
|
import { useAvatarStore } from '../../../stores';
|
||||||
|
|
||||||
const { showAvatarDialog, applyAvatar } = useAvatarStore();
|
const { showAvatarDialog, applyAvatar } = useAvatarStore();
|
||||||
|
const { cachedAvatars } = useAvatarStore();
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@@ -109,6 +115,7 @@
|
|||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
const avatarTagStrings = new Map();
|
||||||
|
|
||||||
const emit = defineEmits(['update:setAvatarTagsDialog']);
|
const emit = defineEmits(['update:setAvatarTagsDialog']);
|
||||||
|
|
||||||
@@ -116,7 +123,7 @@
|
|||||||
() => props.setAvatarTagsDialog.visible,
|
() => props.setAvatarTagsDialog.visible,
|
||||||
(newVal) => {
|
(newVal) => {
|
||||||
if (newVal) {
|
if (newVal) {
|
||||||
updateAvatarTagsSelection();
|
updateAvatarTagsString();
|
||||||
updateSelectedAvatarTags();
|
updateSelectedAvatarTags();
|
||||||
updateInputAvatarTags();
|
updateInputAvatarTags();
|
||||||
}
|
}
|
||||||
@@ -171,14 +178,22 @@
|
|||||||
D.selectedTagsCsv = D.selectedTags.join(',').replace(/content_/g, '');
|
D.selectedTagsCsv = D.selectedTags.join(',').replace(/content_/g, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateAvatarTagsSelection() {
|
function toggleAvatarSelection(avatarId) {
|
||||||
|
const D = props.setAvatarTagsDialog;
|
||||||
|
if (D.selectedAvatarIds.includes(avatarId)) {
|
||||||
|
removeFromArray(D.selectedAvatarIds, avatarId);
|
||||||
|
} else {
|
||||||
|
D.selectedAvatarIds.push(avatarId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateAvatarTagsString() {
|
||||||
const D = props.setAvatarTagsDialog;
|
const D = props.setAvatarTagsDialog;
|
||||||
D.selectedCount = 0;
|
|
||||||
for (const ref of D.ownAvatars) {
|
for (const ref of D.ownAvatars) {
|
||||||
if (ref.$selected) {
|
if (!ref) {
|
||||||
D.selectedCount++;
|
continue;
|
||||||
}
|
}
|
||||||
ref.$tagString = '';
|
let tagString = '';
|
||||||
const contentTags = [];
|
const contentTags = [];
|
||||||
ref.tags.forEach((tag) => {
|
ref.tags.forEach((tag) => {
|
||||||
if (tag.startsWith('content_')) {
|
if (tag.startsWith('content_')) {
|
||||||
@@ -188,21 +203,27 @@
|
|||||||
for (let i = 0; i < contentTags.length; ++i) {
|
for (let i = 0; i < contentTags.length; ++i) {
|
||||||
const tag = contentTags[i];
|
const tag = contentTags[i];
|
||||||
if (i < contentTags.length - 1) {
|
if (i < contentTags.length - 1) {
|
||||||
ref.$tagString += `${tag}, `;
|
tagString += `${tag}, `;
|
||||||
} else {
|
} else {
|
||||||
ref.$tagString += tag;
|
tagString += tag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
avatarTagStrings.set(ref.id, tagString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setAvatarTagsSelectToggle() {
|
function setAvatarTagsSelectToggle() {
|
||||||
const D = props.setAvatarTagsDialog;
|
const D = props.setAvatarTagsDialog;
|
||||||
const allSelected = D.ownAvatars.length === D.selectedCount;
|
const allSelected = D.ownAvatars.length === D.selectedAvatarIds.length;
|
||||||
for (const ref of D.ownAvatars) {
|
for (const ref of D.ownAvatars) {
|
||||||
ref.$selected = !allSelected;
|
if (!allSelected) {
|
||||||
|
if (!D.selectedAvatarIds.includes(ref.id)) {
|
||||||
|
D.selectedAvatarIds.push(ref.id);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
removeFromArray(D.selectedAvatarIds, ref.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
updateAvatarTagsSelection();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveSetAvatarTagsDialog() {
|
async function saveSetAvatarTagsDialog() {
|
||||||
@@ -212,14 +233,13 @@
|
|||||||
}
|
}
|
||||||
D.loading = true;
|
D.loading = true;
|
||||||
try {
|
try {
|
||||||
for (let i = D.ownAvatars.length - 1; i >= 0; --i) {
|
for (const avatarId of D.selectedAvatarIds) {
|
||||||
const ref = D.ownAvatars[i];
|
console.log('Saving tags for avatar', avatarId);
|
||||||
if (!D.visible) {
|
const ref = cachedAvatars.get(avatarId);
|
||||||
|
if (!D.visible || !ref) {
|
||||||
|
console.error('Aborting avatar tag save, dialog closed or avatar not found', avatarId);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!ref.$selected) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const tags = [...D.selectedTags];
|
const tags = [...D.selectedTags];
|
||||||
for (const tag of ref.tags) {
|
for (const tag of ref.tags) {
|
||||||
if (!tag.startsWith('content_')) {
|
if (!tag.startsWith('content_')) {
|
||||||
@@ -231,7 +251,6 @@
|
|||||||
tags
|
tags
|
||||||
});
|
});
|
||||||
applyAvatar(args.json);
|
applyAvatar(args.json);
|
||||||
D.selectedCount--;
|
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|||||||
Reference in New Issue
Block a user