refactor: store state

This commit is contained in:
pa
2025-10-11 15:30:44 +09:00
committed by Natsumi
parent 1e18d89b61
commit 86f7847c46
31 changed files with 2719 additions and 4029 deletions
+34 -45
View File
@@ -1,5 +1,5 @@
import { defineStore } from 'pinia';
import { computed, reactive, watch } from 'vue';
import { reactive, watch } from 'vue';
import { ElMessage } from 'element-plus';
import { instanceRequest, miscRequest, worldRequest } from '../api';
import { database } from '../service/database';
@@ -23,49 +23,41 @@ export const useWorldStore = defineStore('World', () => {
const favoriteStore = useFavoriteStore();
const instanceStore = useInstanceStore();
const userStore = useUserStore();
const state = reactive({
worldDialog: {
visible: false,
loading: false,
id: '',
memo: '',
$location: {},
ref: {},
isFavorite: false,
avatarScalingDisabled: false,
focusViewDisabled: false,
rooms: [],
treeData: [],
bundleSizes: [],
lastUpdated: '',
inCache: false,
cacheSize: '',
cacheLocked: false,
cachePath: '',
fileAnalysis: [],
lastVisit: '',
visitCount: 0,
timeSpent: 0,
isPC: false,
isQuest: false,
isIos: false,
hasPersistData: false
}
const worldDialog = reactive({
visible: false,
loading: false,
id: '',
memo: '',
$location: {},
ref: {},
isFavorite: false,
avatarScalingDisabled: false,
focusViewDisabled: false,
rooms: [],
treeData: [],
bundleSizes: [],
lastUpdated: '',
inCache: false,
cacheSize: '',
cacheLocked: false,
cachePath: '',
fileAnalysis: [],
lastVisit: '',
visitCount: 0,
timeSpent: 0,
isPC: false,
isQuest: false,
isIos: false,
hasPersistData: false
});
let cachedWorlds = new Map();
const worldDialog = computed({
get: () => state.worldDialog,
set: (value) => {
state.worldDialog = value;
}
});
watch(
() => watchState.isLoggedIn,
() => {
state.worldDialog.visible = false;
worldDialog.visible = false;
cachedWorlds.clear();
},
{ flush: 'sync' }
@@ -77,7 +69,7 @@ export const useWorldStore = defineStore('World', () => {
* @param {string} shortName
*/
function showWorldDialog(tag, shortName = null) {
const D = state.worldDialog;
const D = worldDialog;
const L = parseLocation(tag);
if (L.worldId === '') {
return;
@@ -177,10 +169,10 @@ export const useWorldStore = defineStore('World', () => {
})
.then((args) => {
if (
args.params.worldId === state.worldDialog.id &&
state.worldDialog.visible
args.params.worldId === worldDialog.id &&
worldDialog.visible
) {
state.worldDialog.hasPersistData =
worldDialog.hasPersistData =
args.json !== false;
}
});
@@ -205,7 +197,7 @@ export const useWorldStore = defineStore('World', () => {
}
function updateVRChatWorldCache() {
const D = state.worldDialog;
const D = worldDialog;
if (D.visible) {
D.inCache = false;
D.cacheSize = '';
@@ -287,7 +279,6 @@ export const useWorldStore = defineStore('World', () => {
if (userDialog.visible && userDialog.$location.worldId === ref.id) {
userStore.applyUserDialogLocation();
}
const worldDialog = state.worldDialog;
if (worldDialog.visible && worldDialog.id === ref.id) {
worldDialog.ref = ref;
worldDialog.avatarScalingDisabled = ref.tags?.includes(
@@ -319,8 +310,6 @@ export const useWorldStore = defineStore('World', () => {
}
return {
state,
worldDialog,
cachedWorlds,
showWorldDialog,