You've already forked AstralRinth
forked from didirus/AstralRinth
681ae5d1d8
* 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>
30 lines
901 B
TypeScript
30 lines
901 B
TypeScript
// https://tanstack.com/query/v5/docs/framework/vue/examples/nuxt3
|
|
import type { DehydratedState, VueQueryPluginOptions } from '@tanstack/vue-query'
|
|
import { dehydrate, hydrate, QueryClient, VueQueryPlugin } from '@tanstack/vue-query'
|
|
|
|
import { defineNuxtPlugin, useState } from '#imports'
|
|
|
|
export default defineNuxtPlugin((nuxt) => {
|
|
const vueQueryState = useState<DehydratedState | null>('vue-query')
|
|
|
|
const queryClient = new QueryClient({
|
|
defaultOptions: { queries: { staleTime: 10000 } },
|
|
})
|
|
const options: VueQueryPluginOptions = { queryClient }
|
|
|
|
nuxt.vueApp.use(VueQueryPlugin, options)
|
|
|
|
// Expose queryClient for middleware and composables
|
|
nuxt.provide('queryClient', queryClient)
|
|
|
|
if (import.meta.server) {
|
|
nuxt.hooks.hook('app:rendered', () => {
|
|
vueQueryState.value = dehydrate(queryClient)
|
|
})
|
|
}
|
|
|
|
if (import.meta.client) {
|
|
hydrate(queryClient, vueQueryState.value)
|
|
}
|
|
})
|