mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-03 05:26:05 +02:00
refactor: store state
This commit is contained in:
+34
-45
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user