Clean up avatarHistory

This commit is contained in:
Natsumi
2025-10-30 14:42:27 +11:00
parent de1a5a91d7
commit 9ece7c0ddf
5 changed files with 19 additions and 22 deletions
+7 -15
View File
@@ -1,4 +1,4 @@
import { nextTick, reactive, ref, watch } from 'vue'; import { nextTick, ref, watch } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus'; import { ElMessage, ElMessageBox } from 'element-plus';
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
@@ -59,8 +59,7 @@ export const useAvatarStore = defineStore('Avatar', () => {
cachePath: '', cachePath: '',
fileAnalysis: [] fileAnalysis: []
}); });
const avatarHistory = reactive(new Set()); const avatarHistory = ref([]);
const avatarHistoryArray = ref([]);
watch( watch(
() => watchState.isLoggedIn, () => watchState.isLoggedIn,
@@ -69,8 +68,7 @@ export const useAvatarStore = defineStore('Avatar', () => {
cachedAvatars.clear(); cachedAvatars.clear();
cachedAvatarNames.clear(); cachedAvatarNames.clear();
cachedAvatarModerations.clear(); cachedAvatarModerations.clear();
avatarHistory.clear(); avatarHistory.value = [];
avatarHistoryArray.value = [];
if (isLoggedIn) { if (isLoggedIn) {
getAvatarHistory(); getAvatarHistory();
} }
@@ -339,7 +337,6 @@ export const useAvatarStore = defineStore('Avatar', () => {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async function getAvatarHistory() { async function getAvatarHistory() {
avatarHistory.clear();
const historyArray = await database.getAvatarHistory( const historyArray = await database.getAvatarHistory(
userStore.currentUser.id userStore.currentUser.id
); );
@@ -349,9 +346,8 @@ export const useAvatarStore = defineStore('Avatar', () => {
continue; continue;
} }
applyAvatar(avatar); applyAvatar(avatar);
avatarHistory.add(avatar.id);
} }
avatarHistoryArray.value = historyArray; avatarHistory.value = historyArray;
} }
/** /**
@@ -370,16 +366,14 @@ export const useAvatarStore = defineStore('Avatar', () => {
return; return;
} }
const historyArray = avatarHistoryArray.value; const historyArray = avatarHistory.value;
for (let i = 0; i < historyArray.length; ++i) { for (let i = 0; i < historyArray.length; ++i) {
if (historyArray[i].id === ref.id) { if (historyArray[i].id === ref.id) {
historyArray.splice(i, 1); historyArray.splice(i, 1);
} }
} }
avatarHistoryArray.value.unshift(ref); avatarHistory.value.unshift(ref);
avatarHistory.delete(ref.id);
avatarHistory.add(ref.id);
}) })
.catch((err) => { .catch((err) => {
console.error('Failed to add avatar to history:', err); console.error('Failed to add avatar to history:', err);
@@ -387,8 +381,7 @@ export const useAvatarStore = defineStore('Avatar', () => {
} }
function clearAvatarHistory() { function clearAvatarHistory() {
avatarHistory.clear(); avatarHistory.value = [];
avatarHistoryArray.value = [];
database.clearAvatarHistory(); database.clearAvatarHistory();
} }
@@ -675,7 +668,6 @@ export const useAvatarStore = defineStore('Avatar', () => {
return { return {
avatarDialog, avatarDialog,
avatarHistory, avatarHistory,
avatarHistoryArray,
cachedAvatarModerations, cachedAvatarModerations,
cachedAvatars, cachedAvatars,
cachedAvatarNames, cachedAvatarNames,
+2 -2
View File
@@ -1151,7 +1151,7 @@ export const useFavoriteStore = defineStore('Favorite', () => {
} }
} }
if (!avatarInFavorites) { if (!avatarInFavorites) {
if (!avatarStore.avatarHistory.has(id)) { if (!avatarStore.avatarHistory.includes(id)) {
database.removeAvatarFromCache(id); database.removeAvatarFromCache(id);
} }
} }
@@ -1292,7 +1292,7 @@ export const useFavoriteStore = defineStore('Favorite', () => {
} }
} }
if (!avatarInFavorites) { if (!avatarInFavorites) {
if (!avatarStore.avatarHistory.has(avatarId)) { if (!avatarStore.avatarHistory.includes(avatarId)) {
database.removeAvatarFromCache(avatarId); database.removeAvatarFromCache(avatarId);
} }
} }
+5
View File
@@ -82,6 +82,11 @@ pinia.use(
...state.Group, ...state.Group,
groupInstances: null, groupInstances: null,
inGameGroupOrder: null inGameGroupOrder: null
},
Avatar: {
// @ts-ignore
...state.Avatar,
avatarHistory: null
} }
}) })
}) })
+1 -1
View File
@@ -274,7 +274,7 @@ export const useVrcxStore = defineStore('Vrcx', () => {
!favoriteStore.cachedFavoritesByObjectId(id) && !favoriteStore.cachedFavoritesByObjectId(id) &&
ref.authorId !== userStore.currentUser.id && ref.authorId !== userStore.currentUser.id &&
!favoriteStore.localAvatarFavoritesList.includes(id) && !favoriteStore.localAvatarFavoritesList.includes(id) &&
!avatarStore.avatarHistory.has(id) !avatarStore.avatarHistory.includes(id)
) { ) {
avatarStore.cachedAvatars.delete(id); avatarStore.cachedAvatars.delete(id);
} }
@@ -109,7 +109,7 @@
<template #title> <template #title>
<span style="font-weight: bold; font-size: 14px; margin-left: 10px">Local History</span> <span style="font-weight: bold; font-size: 14px; margin-left: 10px">Local History</span>
<span style="color: #909399; font-size: 12px; margin-left: 10px" <span style="color: #909399; font-size: 12px; margin-left: 10px"
>{{ avatarHistoryArray.length }}/100</span >{{ avatarHistory.length }}/100</span
> >
<el-tooltip placement="right" content="Clear" :teleported="false"> <el-tooltip placement="right" content="Clear" :teleported="false">
<el-button <el-button
@@ -120,9 +120,9 @@
@click.stop="promptClearAvatarHistory"></el-button> @click.stop="promptClearAvatarHistory"></el-button>
</el-tooltip> </el-tooltip>
</template> </template>
<div v-if="avatarHistoryArray.length" class="x-friend-list" style="margin-top: 10px"> <div v-if="avatarHistory.length" class="x-friend-list" style="margin-top: 10px">
<FavoritesAvatarLocalHistoryItem <FavoritesAvatarLocalHistoryItem
v-for="favorite in avatarHistoryArray" v-for="favorite in avatarHistory"
:key="favorite.id" :key="favorite.id"
style="display: inline-block; width: 300px; margin-right: 15px" style="display: inline-block; width: 300px; margin-right: 15px"
:favorite="favorite" :favorite="favorite"
@@ -239,7 +239,7 @@
localAvatarFavoritesList, localAvatarFavoritesList,
localAvatarFavoriteGroups localAvatarFavoriteGroups
} = useFavoriteStore(); } = useFavoriteStore();
const { avatarHistoryArray } = storeToRefs(useAvatarStore()); const { avatarHistory } = storeToRefs(useAvatarStore());
const { promptClearAvatarHistory, showAvatarDialog, applyAvatar } = useAvatarStore(); const { promptClearAvatarHistory, showAvatarDialog, applyAvatar } = useAvatarStore();
const { isLocalUserVrcPlusSupporter } = storeToRefs(useUserStore()); const { isLocalUserVrcPlusSupporter } = storeToRefs(useUserStore());
const { t } = useI18n(); const { t } = useI18n();