mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-05 06:16:05 +02:00
add @tanstack/query
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
||||
storeAvatarImage
|
||||
} from '../shared/utils';
|
||||
import { avatarRequest, miscRequest } from '../api';
|
||||
import { patchAvatarFromEvent } from '../query';
|
||||
import { AppDebug } from '../service/appConfig';
|
||||
import { database } from '../service/database';
|
||||
import { processBulk } from '../service/request';
|
||||
@@ -170,6 +171,7 @@ export const useAvatarStore = defineStore('Avatar', () => {
|
||||
// update db cache
|
||||
database.addAvatarToCache(avatarRef);
|
||||
}
|
||||
patchAvatarFromEvent(ref);
|
||||
return ref;
|
||||
}
|
||||
|
||||
@@ -178,14 +180,15 @@ export const useAvatarStore = defineStore('Avatar', () => {
|
||||
* @param {string} avatarId
|
||||
* @returns
|
||||
*/
|
||||
function showAvatarDialog(avatarId) {
|
||||
function showAvatarDialog(avatarId, options = {}) {
|
||||
const D = avatarDialog.value;
|
||||
const forceRefresh = Boolean(options?.forceRefresh);
|
||||
const isMainDialogOpen = uiStore.openDialog({
|
||||
type: 'avatar',
|
||||
id: avatarId
|
||||
});
|
||||
D.visible = true;
|
||||
if (isMainDialogOpen && D.id === avatarId) {
|
||||
if (isMainDialogOpen && D.id === avatarId && !forceRefresh) {
|
||||
uiStore.setDialogCrumbLabel('avatar', D.id, D.ref?.name || D.id);
|
||||
nextTick(() => (D.loading = false));
|
||||
return;
|
||||
@@ -217,8 +220,10 @@ export const useAvatarStore = defineStore('Avatar', () => {
|
||||
uiStore.setDialogCrumbLabel('avatar', D.id, D.ref?.name || D.id);
|
||||
nextTick(() => (D.loading = false));
|
||||
}
|
||||
avatarRequest
|
||||
.getAvatar({ avatarId })
|
||||
const loadAvatarRequest = forceRefresh
|
||||
? avatarRequest.getAvatar({ avatarId })
|
||||
: avatarRequest.getCachedAvatar({ avatarId });
|
||||
loadAvatarRequest
|
||||
.then((args) => {
|
||||
const ref = applyAvatar(args.json);
|
||||
D.ref = ref;
|
||||
|
||||
@@ -542,7 +542,7 @@ export const useFavoriteStore = defineStore('Favorite', () => {
|
||||
}
|
||||
isFavoriteGroupLoading.value = true;
|
||||
processBulk({
|
||||
fn: favoriteRequest.getFavoriteGroups,
|
||||
fn: favoriteRequest.getCachedFavoriteGroups,
|
||||
N: -1,
|
||||
params: {
|
||||
n: 50,
|
||||
@@ -707,7 +707,7 @@ export const useFavoriteStore = defineStore('Favorite', () => {
|
||||
}
|
||||
isFavoriteLoading.value = true;
|
||||
try {
|
||||
const args = await favoriteRequest.getFavoriteLimits();
|
||||
const args = await favoriteRequest.getCachedFavoriteLimits();
|
||||
favoriteLimits.value = {
|
||||
...favoriteLimits.value,
|
||||
...args.json
|
||||
@@ -717,7 +717,7 @@ export const useFavoriteStore = defineStore('Favorite', () => {
|
||||
}
|
||||
let newFavoriteSortOrder = [];
|
||||
processBulk({
|
||||
fn: favoriteRequest.getFavorites,
|
||||
fn: favoriteRequest.getCachedFavorites,
|
||||
N: -1,
|
||||
params: {
|
||||
n: 300,
|
||||
@@ -839,7 +839,7 @@ export const useFavoriteStore = defineStore('Favorite', () => {
|
||||
offset: 0,
|
||||
tag
|
||||
};
|
||||
const args = await favoriteRequest.getFavoriteAvatars(params);
|
||||
const args = await favoriteRequest.getCachedFavoriteAvatars(params);
|
||||
handleFavoriteAvatarList(args);
|
||||
}
|
||||
|
||||
@@ -848,8 +848,8 @@ export const useFavoriteStore = defineStore('Favorite', () => {
|
||||
*/
|
||||
function refreshFavoriteItems() {
|
||||
const types = {
|
||||
world: [0, favoriteRequest.getFavoriteWorlds],
|
||||
avatar: [0, favoriteRequest.getFavoriteAvatars]
|
||||
world: [0, favoriteRequest.getCachedFavoriteWorlds],
|
||||
avatar: [0, favoriteRequest.getCachedFavoriteAvatars]
|
||||
};
|
||||
const tags = [];
|
||||
for (const ref of cachedFavorites.values()) {
|
||||
|
||||
@@ -777,7 +777,7 @@ export const useFriendStore = defineStore('Friend', () => {
|
||||
async function fetchPage(offset) {
|
||||
const result = await executeWithBackoff(
|
||||
async () => {
|
||||
const { json } = await friendRequest.getFriends({
|
||||
const { json } = await friendRequest.getCachedFriends({
|
||||
...args,
|
||||
n: PAGE_SIZE,
|
||||
offset
|
||||
|
||||
+12
-10
@@ -149,7 +149,7 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
tag: 'gallery'
|
||||
};
|
||||
vrcPlusIconRequest
|
||||
.getFileList(params)
|
||||
.getCachedFileList(params)
|
||||
.then((args) => handleFilesList(args))
|
||||
.catch((error) => {
|
||||
console.error('Error fetching gallery files:', error);
|
||||
@@ -166,7 +166,7 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
tag: 'icon'
|
||||
};
|
||||
vrcPlusIconRequest
|
||||
.getFileList(params)
|
||||
.getCachedFileList(params)
|
||||
.then((args) => handleFilesList(args))
|
||||
.catch((error) => {
|
||||
console.error('Error fetching VRC Plus icons:', error);
|
||||
@@ -208,7 +208,7 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
tag: 'sticker'
|
||||
};
|
||||
vrcPlusIconRequest
|
||||
.getFileList(params)
|
||||
.getCachedFileList(params)
|
||||
.then((args) => handleFilesList(args))
|
||||
.catch((error) => {
|
||||
console.error('Error fetching stickers:', error);
|
||||
@@ -232,7 +232,7 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
if (instanceStickersCache.value.length > 100) {
|
||||
instanceStickersCache.value.shift();
|
||||
}
|
||||
const args = await inventoryRequest.getUserInventoryItem({
|
||||
const args = await inventoryRequest.getCachedUserInventoryItem({
|
||||
inventoryId,
|
||||
userId
|
||||
});
|
||||
@@ -269,7 +269,7 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
n: 100
|
||||
};
|
||||
try {
|
||||
const args = await vrcPlusImageRequest.getPrints(params);
|
||||
const args = await vrcPlusImageRequest.getCachedPrints(params);
|
||||
args.json.sort((a, b) => {
|
||||
return (
|
||||
new Date(b.timestamp).getTime() -
|
||||
@@ -306,7 +306,7 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
}
|
||||
|
||||
async function trySavePrintToFile(printId) {
|
||||
const args = await vrcPlusImageRequest.getPrint({ printId });
|
||||
const args = await vrcPlusImageRequest.getCachedPrint({ printId });
|
||||
const imageUrl = args.json?.files?.image;
|
||||
if (!imageUrl) {
|
||||
console.error('Print image URL is missing', args);
|
||||
@@ -357,7 +357,7 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
tag: 'emoji'
|
||||
};
|
||||
vrcPlusIconRequest
|
||||
.getFileList(params)
|
||||
.getCachedFileList(params)
|
||||
.then((args) => handleFilesList(args))
|
||||
.catch((error) => {
|
||||
console.error('Error fetching emojis:', error);
|
||||
@@ -379,7 +379,9 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
try {
|
||||
for (let i = 0; i < 100; i++) {
|
||||
params.offset = i * params.n;
|
||||
const args = await inventoryRequest.getInventoryItems(params);
|
||||
const args = await inventoryRequest.getCachedInventoryItems(
|
||||
params
|
||||
);
|
||||
for (const item of args.json.data) {
|
||||
advancedSettingsStore.currentUserInventory.set(
|
||||
item.id,
|
||||
@@ -476,7 +478,7 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
}
|
||||
|
||||
async function trySaveEmojiToFile(inventoryId, userId) {
|
||||
const args = await inventoryRequest.getUserInventoryItem({
|
||||
const args = await inventoryRequest.getCachedUserInventoryItem({
|
||||
inventoryId,
|
||||
userId
|
||||
});
|
||||
@@ -548,7 +550,7 @@ export const useGalleryStore = defineStore('Gallery', () => {
|
||||
return;
|
||||
}
|
||||
miscReq
|
||||
.getFile({ fileId })
|
||||
.getCachedFile({ fileId })
|
||||
.then((args) => {
|
||||
cachedEmoji.set(fileId, args.json);
|
||||
resolve(args.json);
|
||||
|
||||
+45
-34
@@ -9,6 +9,7 @@ import {
|
||||
userRequest,
|
||||
worldRequest
|
||||
} from '../api';
|
||||
import { patchGroupFromEvent } from '../query';
|
||||
import {
|
||||
convertFileUrlToImageUrl,
|
||||
hasGroupPermission,
|
||||
@@ -127,17 +128,18 @@ export const useGroupStore = defineStore('Group', () => {
|
||||
{ flush: 'sync' }
|
||||
);
|
||||
|
||||
function showGroupDialog(groupId) {
|
||||
function showGroupDialog(groupId, options = {}) {
|
||||
if (!groupId) {
|
||||
return;
|
||||
}
|
||||
const forceRefresh = Boolean(options?.forceRefresh);
|
||||
const isMainDialogOpen = uiStore.openDialog({
|
||||
type: 'group',
|
||||
id: groupId
|
||||
});
|
||||
const D = groupDialog.value;
|
||||
D.visible = true;
|
||||
if (isMainDialogOpen && D.id === groupId) {
|
||||
if (isMainDialogOpen && D.id === groupId && !forceRefresh) {
|
||||
uiStore.setDialogCrumbLabel('group', D.id, D.ref?.name || D.id);
|
||||
instanceStore.applyGroupDialogInstances();
|
||||
D.loading = false;
|
||||
@@ -159,10 +161,15 @@ export const useGroupStore = defineStore('Group', () => {
|
||||
D.members = [];
|
||||
D.memberFilter = groupDialogFilterOptions.everyone;
|
||||
D.calendar = [];
|
||||
groupRequest
|
||||
.getCachedGroup({
|
||||
groupId
|
||||
})
|
||||
const loadGroupRequest = forceRefresh
|
||||
? groupRequest.getGroup({
|
||||
groupId,
|
||||
includeRoles: false
|
||||
})
|
||||
: groupRequest.getCachedGroup({
|
||||
groupId
|
||||
});
|
||||
loadGroupRequest
|
||||
.catch((err) => {
|
||||
D.loading = false;
|
||||
D.id = null;
|
||||
@@ -172,29 +179,27 @@ export const useGroupStore = defineStore('Group', () => {
|
||||
throw err;
|
||||
})
|
||||
.then((args) => {
|
||||
if (groupId === args.ref.id) {
|
||||
D.ref = args.ref;
|
||||
const ref = args.ref || applyGroup(args.json);
|
||||
if (groupId === ref.id) {
|
||||
D.ref = ref;
|
||||
uiStore.setDialogCrumbLabel(
|
||||
'group',
|
||||
D.id,
|
||||
D.ref?.name || D.id
|
||||
);
|
||||
D.inGroup = args.ref.membershipStatus === 'member';
|
||||
D.ownerDisplayName = args.ref.ownerId;
|
||||
D.inGroup = ref.membershipStatus === 'member';
|
||||
D.ownerDisplayName = ref.ownerId;
|
||||
D.visible = true;
|
||||
D.loading = false;
|
||||
if (args.cache) {
|
||||
groupRequest.getGroup(args.params);
|
||||
}
|
||||
userRequest
|
||||
.getCachedUser({
|
||||
userId: args.ref.ownerId
|
||||
userId: ref.ownerId
|
||||
})
|
||||
.then((args1) => {
|
||||
D.ownerDisplayName = args1.ref.displayName;
|
||||
});
|
||||
database.getLastGroupVisit(D.ref.name).then((r) => {
|
||||
if (D.id === args.ref.id) {
|
||||
if (D.id === ref.id) {
|
||||
D.lastVisit = r.created_at;
|
||||
}
|
||||
});
|
||||
@@ -400,33 +405,37 @@ export const useGroupStore = defineStore('Group', () => {
|
||||
*/
|
||||
async function getAllGroupPosts(params) {
|
||||
const n = 100;
|
||||
let posts = [];
|
||||
const posts = [];
|
||||
let offset = 0;
|
||||
let total = 0;
|
||||
const args = await groupRequest.getGroupPosts({
|
||||
groupId: params.groupId,
|
||||
n,
|
||||
offset
|
||||
});
|
||||
let total = Infinity;
|
||||
let pages = 0;
|
||||
do {
|
||||
posts = posts.concat(args.json.posts);
|
||||
total = args.json.total;
|
||||
const args = await groupRequest.getCachedGroupPosts({
|
||||
groupId: params.groupId,
|
||||
n,
|
||||
offset
|
||||
});
|
||||
const pagePosts = args.json?.posts ?? [];
|
||||
total = Number(args.json?.total ?? pagePosts.length);
|
||||
posts.push(...pagePosts);
|
||||
offset += n;
|
||||
} while (offset < total);
|
||||
pages += 1;
|
||||
if (pagePosts.length === 0) {
|
||||
break;
|
||||
}
|
||||
} while (offset < total && pages < 50);
|
||||
const returnArgs = {
|
||||
posts,
|
||||
params
|
||||
};
|
||||
const D = groupDialog.value;
|
||||
if (D.id === args.params.groupId) {
|
||||
for (const post of args.json.posts) {
|
||||
if (D.id === params.groupId) {
|
||||
for (const post of posts) {
|
||||
post.title = replaceBioSymbols(post.title);
|
||||
post.text = replaceBioSymbols(post.text);
|
||||
}
|
||||
if (args.json.posts.length > 0) {
|
||||
D.announcement = args.json.posts[0];
|
||||
}
|
||||
D.posts = args.json.posts;
|
||||
D.announcement = posts[0] ?? {};
|
||||
D.posts = posts;
|
||||
updateGroupPostSearch();
|
||||
}
|
||||
|
||||
@@ -437,7 +446,7 @@ export const useGroupStore = defineStore('Group', () => {
|
||||
const D = groupDialog.value;
|
||||
D.isGetGroupDialogGroupLoading = false;
|
||||
return groupRequest
|
||||
.getGroup({ groupId, includeRoles: true })
|
||||
.getCachedGroup({ groupId, includeRoles: true })
|
||||
.catch((err) => {
|
||||
throw err;
|
||||
})
|
||||
@@ -447,6 +456,7 @@ export const useGroupStore = defineStore('Group', () => {
|
||||
D.loading = false;
|
||||
D.ref = ref;
|
||||
D.inGroup = ref.membershipStatus === 'member';
|
||||
D.memberRoles = [];
|
||||
for (const role of ref.roles) {
|
||||
if (
|
||||
D.ref &&
|
||||
@@ -487,14 +497,14 @@ export const useGroupStore = defineStore('Group', () => {
|
||||
});
|
||||
}
|
||||
});
|
||||
groupRequest.getGroupCalendar(groupId).then((args) => {
|
||||
groupRequest.getCachedGroupCalendar(groupId).then((args) => {
|
||||
if (groupDialog.value.id === args.params.groupId) {
|
||||
D.calendar = args.json.results;
|
||||
for (const event of D.calendar) {
|
||||
applyGroupEvent(event);
|
||||
// fetch again for isFollowing
|
||||
groupRequest
|
||||
.getGroupCalendarEvent({
|
||||
.getCachedGroupCalendarEvent({
|
||||
groupId,
|
||||
eventId: event.id
|
||||
})
|
||||
@@ -782,6 +792,7 @@ export const useGroupStore = defineStore('Group', () => {
|
||||
D.inGroup = ref.membershipStatus === 'member';
|
||||
D.ref = ref;
|
||||
}
|
||||
patchGroupFromEvent(ref);
|
||||
return ref;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
userRequest,
|
||||
worldRequest
|
||||
} from '../api';
|
||||
import { patchInstanceFromEvent } from '../query';
|
||||
import {
|
||||
accessTypeLocaleKeyMap,
|
||||
instanceContentSettings
|
||||
@@ -573,6 +574,7 @@ export const useInstanceStore = defineStore('Instance', () => {
|
||||
}
|
||||
}
|
||||
lastInstanceApplied.value = ref.id;
|
||||
patchInstanceFromEvent(ref);
|
||||
return ref;
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -29,6 +29,7 @@ import {
|
||||
instanceRequest,
|
||||
userRequest
|
||||
} from '../api';
|
||||
import { patchUserFromEvent } from '../query';
|
||||
import { processBulk, request } from '../service/request';
|
||||
import { AppDebug } from '../service/appConfig';
|
||||
import { database } from '../service/database';
|
||||
@@ -764,6 +765,7 @@ export const useUserStore = defineStore('User', () => {
|
||||
}
|
||||
}
|
||||
}
|
||||
patchUserFromEvent(ref);
|
||||
return ref;
|
||||
}
|
||||
|
||||
@@ -920,9 +922,6 @@ export const useUserStore = defineStore('User', () => {
|
||||
if (locationStore.lastLocation.playerList.has(D.ref.id)) {
|
||||
inCurrentWorld = true;
|
||||
}
|
||||
if (args.cache) {
|
||||
userRequest.getUser(args.params);
|
||||
}
|
||||
if (userId !== currentUser.value.id) {
|
||||
database
|
||||
.getUserStats(D.ref, inCurrentWorld)
|
||||
|
||||
+13
-13
@@ -13,6 +13,7 @@ import {
|
||||
replaceBioSymbols
|
||||
} from '../shared/utils';
|
||||
import { instanceRequest, miscRequest, worldRequest } from '../api';
|
||||
import { patchWorldFromEvent } from '../query';
|
||||
import { database } from '../service/database';
|
||||
import { processBulk } from '../service/request';
|
||||
import { useFavoriteStore } from './favorite';
|
||||
@@ -76,8 +77,9 @@ export const useWorldStore = defineStore('World', () => {
|
||||
* @param {string} tag
|
||||
* @param {string} shortName
|
||||
*/
|
||||
function showWorldDialog(tag, shortName = null) {
|
||||
function showWorldDialog(tag, shortName = null, options = {}) {
|
||||
const D = worldDialog;
|
||||
const forceRefresh = Boolean(options?.forceRefresh);
|
||||
const L = parseLocation(tag);
|
||||
if (L.worldId === '') {
|
||||
return;
|
||||
@@ -89,7 +91,7 @@ export const useWorldStore = defineStore('World', () => {
|
||||
shortName
|
||||
});
|
||||
D.visible = true;
|
||||
if (isMainDialogOpen && D.id === L.worldId) {
|
||||
if (isMainDialogOpen && D.id === L.worldId && !forceRefresh) {
|
||||
uiStore.setDialogCrumbLabel('world', D.id, D.ref?.name || D.id);
|
||||
instanceStore.applyWorldDialogInstances();
|
||||
nextTick(() => (D.loading = false));
|
||||
@@ -141,10 +143,14 @@ export const useWorldStore = defineStore('World', () => {
|
||||
D.timeSpent = ref.timeSpent;
|
||||
}
|
||||
});
|
||||
worldRequest
|
||||
.getCachedWorld({
|
||||
worldId: L.worldId
|
||||
})
|
||||
const loadWorldRequest = forceRefresh
|
||||
? worldRequest.getWorld({
|
||||
worldId: L.worldId
|
||||
})
|
||||
: worldRequest.getCachedWorld({
|
||||
worldId: L.worldId
|
||||
});
|
||||
loadWorldRequest
|
||||
.catch((err) => {
|
||||
nextTick(() => (D.loading = false));
|
||||
D.id = null;
|
||||
@@ -199,13 +205,6 @@ export const useWorldStore = defineStore('World', () => {
|
||||
}
|
||||
});
|
||||
|
||||
if (args.cache) {
|
||||
worldRequest.getWorld(args.params).then((args1) => {
|
||||
if (D.id === args1.ref.id) {
|
||||
updateVRChatWorldCache();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -343,6 +342,7 @@ export const useWorldStore = defineStore('World', () => {
|
||||
// update db cache
|
||||
database.addWorldToCache(ref);
|
||||
}
|
||||
patchWorldFromEvent(ref);
|
||||
return ref;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user