refactor: removing useAsyncData for tanstack query (#5262)

* refactor: most places with useAsyncData replaced with tanstack query

* refactor report list and report view

* refactor organization page to use tanstack query

* fix types

* refactor collection page and include proper loading state

* fix followed projects proper loading state

* fix 404 handling

* fix organization loading and 404 states

* pnpm prepr

* refactor: remove useAsyncData on newsletter button

* refactor: remove useAsyncData on auth globals fetch

* refactor: settings/billing/index.vue to useQuery instead of useAsyncData

* refactor: user page to remove useAsyncData

* pnpm prepr

* fix reports pages

* fix notifications page

* fix billing page cannot read properties of null and prop warnings

* fix refresh causing 404 by removing useBaseFetch and use api-client

* fix stale data after removing organization from project

* pnpm prepr

* fix news erroring in build

* fix: project page loads header only after content

* fix: user page tanstack problems (start on migrating away from useBaseFetch)

* fix: start swapping useBaseFetch usages to api-client

* Revert "fix: start swapping useBaseFetch usages to api-client"

This reverts commit 3df3fab11d535159132b1288dd7cacc38282b553.

* fix: remove debug logging

* fix: lint

---------

Co-authored-by: Calum H. <calum@modrinth.com>
Co-authored-by: Calum H. (IMB11) <contact@cal.engineer>
This commit is contained in:
Truman Gao
2026-03-16 12:10:29 -07:00
committed by GitHub
parent d0c7575a23
commit 681ae5d1d8
53 changed files with 1686 additions and 1079 deletions

View File

@@ -648,6 +648,7 @@ import {
useVIntl,
} from '@modrinth/ui'
import { monthsInInterval } from '@modrinth/ui/src/utils/billing.ts'
import { useQuery } from '@tanstack/vue-query'
import { computed } from 'vue'
import { useBaseFetch } from '@/composables/fetch.js'
@@ -1011,14 +1012,18 @@ const selectedCurrency = ref('USD')
const loggedOut = computed(() => !auth.value.user)
const outOfStockUrl = 'https://discord.modrinth.com'
const { data: hasServers } = await useAsyncData('ServerListCountCheck', async () => {
try {
if (!auth.value.user) return false
const response = await useServersFetch('servers')
return response.servers && response.servers.length > 0
} catch {
return false
}
const { data: hasServers } = useQuery({
queryKey: computed(() => ['servers', 'list-count', auth.value?.user?.id]),
queryFn: async () => {
try {
if (!auth.value.user) return false
const response = await useServersFetch('servers')
return response.servers && response.servers.length > 0
} catch {
return false
}
},
enabled: computed(() => !!auth.value?.user),
})
function fetchStock(region, request) {
@@ -1080,15 +1085,12 @@ async function fetchCapacityStatuses(customProduct = null) {
}
}
const { data: capacityStatuses, refresh: refreshCapacity } = await useAsyncData(
'ServerCapacityAll',
fetchCapacityStatuses,
{
getCachedData() {
return null // Dont cache stock data.
},
},
)
const { data: capacityStatuses, refetch: refreshCapacity } = useQuery({
queryKey: ['server', 'capacity', 'all'],
queryFn: fetchCapacityStatuses,
staleTime: 0, // Dont cache stock data
gcTime: 0,
})
const isSmallAtCapacity = computed(() => capacityStatuses.value?.small?.available === 0)
const isMediumAtCapacity = computed(() => capacityStatuses.value?.medium?.available === 0)

View File

@@ -118,7 +118,7 @@ import {
StyledInput,
Toggle,
} from '@modrinth/ui'
import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
import { useMutation, useQueryClient } from '@tanstack/vue-query'
import Fuse from 'fuse.js'
import { computed, ref, watch } from 'vue'