mirror of
https://github.com/modrinth/code.git
synced 2026-08-27 18:14:49 +00:00
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 3df3fab11d.
* 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:
co-authored by
Calum H.
Calum H.
parent
d0c7575a23
commit
681ae5d1d8
@@ -1,14 +1,15 @@
|
||||
<script setup lang="ts">
|
||||
import { GitGraphIcon, RssIcon } from '@modrinth/assets'
|
||||
import { articles as rawArticles } from '@modrinth/blog'
|
||||
import { Avatar, ButtonStyled, useFormatDateTime } from '@modrinth/ui'
|
||||
import type { User } from '@modrinth/utils'
|
||||
import { Avatar, ButtonStyled, injectModrinthClient, useFormatDateTime } from '@modrinth/ui'
|
||||
import { useQuery } from '@tanstack/vue-query'
|
||||
import dayjs from 'dayjs'
|
||||
import { computed, onMounted } from 'vue'
|
||||
|
||||
import NewsletterButton from '~/components/ui/NewsletterButton.vue'
|
||||
import ShareArticleButtons from '~/components/ui/ShareArticleButtons.vue'
|
||||
|
||||
const client = injectModrinthClient()
|
||||
const config = useRuntimeConfig()
|
||||
const route = useRoute()
|
||||
|
||||
@@ -24,21 +25,19 @@ if (!rawArticle) {
|
||||
})
|
||||
}
|
||||
|
||||
const authorsUrl = `users?ids=${JSON.stringify(rawArticle.authors)}`
|
||||
const { data: authors } = useQuery({
|
||||
queryKey: computed(() => ['users', rawArticle.authors]),
|
||||
queryFn: async () => {
|
||||
const users = await client.labrinth.users_v2.getMultiple(rawArticle.authors)
|
||||
users.sort((a, b) => {
|
||||
return rawArticle.authors.indexOf(a.id) - rawArticle.authors.indexOf(b.id)
|
||||
})
|
||||
return users
|
||||
},
|
||||
enabled: computed(() => rawArticle.authors.length > 0),
|
||||
})
|
||||
|
||||
const [authors, html] = await Promise.all([
|
||||
rawArticle.authors
|
||||
? useAsyncData(authorsUrl, () => useBaseFetch(authorsUrl)).then((data) => {
|
||||
const users = data.data as Ref<User[]>
|
||||
users.value.sort((a, b) => {
|
||||
return rawArticle.authors.indexOf(a.id) - rawArticle.authors.indexOf(b.id)
|
||||
})
|
||||
|
||||
return users
|
||||
})
|
||||
: Promise.resolve(),
|
||||
rawArticle.html(),
|
||||
])
|
||||
const html = await rawArticle.html()
|
||||
|
||||
const article = computed(() => ({
|
||||
...rawArticle,
|
||||
|
||||
Reference in New Issue
Block a user