refactor: remove useBaseFetch for @modrinth/api-client (#5596)

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

This reverts commit f4f33db7019ea861addb2c66c204d736800b7b6c.

* fix: bugs

* fix: analytics

* fix: lint
This commit is contained in:
Calum H.
2026-03-17 20:06:19 +00:00
committed by GitHub
parent 58c1e225c8
commit 87c86c7d0d
64 changed files with 2073 additions and 691 deletions

View File

@@ -82,6 +82,7 @@
</div>
</template>
<script setup lang="ts">
import type { Labrinth } from '@modrinth/api-client'
import { PlusIcon, SearchIcon, XCircleIcon } from '@modrinth/assets'
import {
Accordion,
@@ -91,20 +92,20 @@ import {
Avatar,
ButtonStyled,
ConfirmModal,
injectModrinthClient,
injectNotificationManager,
StyledInput,
} from '@modrinth/ui'
import type { AffiliateLink, User } from '@modrinth/utils'
import type { User } from '@modrinth/utils'
import { useQuery } from '@tanstack/vue-query'
import { computed, ref } from 'vue'
import { useBaseFetch } from '~/composables/fetch.js'
const client = injectModrinthClient()
const { handleError } = injectNotificationManager()
type UserGroup = {
user: User
affiliates: AffiliateLink[]
affiliates: Labrinth.Affiliate.Internal.AffiliateCode[]
}
const createModal = useTemplateRef<typeof AffiliateLinkCreateModal>('createModal')
@@ -116,8 +117,7 @@ const {
refetch,
} = useQuery({
queryKey: ['affiliate'],
queryFn: () =>
useBaseFetch('affiliate', { method: 'GET', internal: true }) as Promise<AffiliateLink[]>,
queryFn: () => client.labrinth.affiliate_internal.getAll(),
})
const filterQuery = ref('')
@@ -130,7 +130,9 @@ const userIds = computed(() => {
const ids = new Set<string>()
affiliateCodes.value.forEach((code) => {
ids.add(code.affiliate)
ids.add(code.created_by)
if (code.created_by) {
ids.add(code.created_by)
}
})
return Array.from(ids)
})
@@ -139,7 +141,7 @@ const { data: users } = useQuery({
queryKey: computed(() => ['users-bulk', userIds.value]),
queryFn: () => {
if (userIds.value.length === 0) return Promise.resolve([])
return useBaseFetch(`users?ids=${JSON.stringify(userIds.value)}`) as Promise<User[]>
return client.labrinth.users_v2.getMultiple(userIds.value)
},
})
@@ -189,7 +191,8 @@ const filteredGroupedAffiliates = computed(() => {
)
})
function getCreatedByUsername(createdBy: string): string {
function getCreatedByUsername(createdBy: string | null): string {
if (!createdBy) return 'Unknown'
const user = userMap.value.get(createdBy)
return user?.username || 'Unknown'
}
@@ -207,7 +210,7 @@ async function createAffiliateCode(data: { sourceName: string; username?: string
if (!user) {
try {
user = (await useBaseFetch(`user/${data.username}`)) as User
user = await client.labrinth.users_v2.get(data.username)
if (users.value) {
users.value.push(user)
@@ -218,19 +221,15 @@ async function createAffiliateCode(data: { sourceName: string; username?: string
}
}
await useBaseFetch('affiliate', {
method: 'PUT',
body: {
affiliate: user.id,
source_name: data.sourceName,
},
internal: true,
await client.labrinth.affiliate_internal.create({
affiliate: user.id,
source_name: data.sourceName,
})
await refetch()
createModal.value?.close()
} catch (err) {
handleError(err)
handleError(err as Error)
} finally {
creatingLink.value = false
}
@@ -239,7 +238,7 @@ async function createAffiliateCode(data: { sourceName: string; username?: string
const revokingAffiliateUsername = ref<string | null>(null)
const revokingAffiliateId = ref<string | null>(null)
function revokeAffiliateCode(affiliate: AffiliateLink) {
function revokeAffiliateCode(affiliate: Labrinth.Affiliate.Internal.AffiliateCode) {
const user = userMap.value.get(affiliate.affiliate)
revokingAffiliateUsername.value = user?.username || 'Unknown'
revokingAffiliateId.value = affiliate.id
@@ -252,10 +251,7 @@ async function confirmRevokeAffiliateCode() {
}
try {
await useBaseFetch(`affiliate/${revokingAffiliateId.value}`, {
method: 'DELETE',
internal: true,
})
await client.labrinth.affiliate_internal.delete(revokingAffiliateId.value)
await refetch()
revokeModal.value?.hide()

View File

@@ -328,6 +328,7 @@ import {
CopyCode,
defineMessages,
DropdownSelect,
injectModrinthClient,
injectNotificationManager,
NewModal,
StyledInput,
@@ -343,9 +344,9 @@ import { useQuery } from '@tanstack/vue-query'
import dayjs from 'dayjs'
import ModrinthServersIcon from '~/components/ui/servers/ModrinthServersIcon.vue'
import { useBaseFetch } from '~/composables/fetch.js'
const { addNotification } = injectNotificationManager()
const client = injectModrinthClient()
const formatPrice = useFormatPrice()
const formatDateTime = useFormatDateTime({
timeStyle: 'short',
@@ -374,7 +375,7 @@ const messages = defineMessages({
const { data: user, error: userError } = useQuery({
queryKey: ['user', route.params.id],
queryFn: () => useBaseFetch(`user/${route.params.id}`),
queryFn: () => client.labrinth.users_v2.get(route.params.id),
})
watch(userError, (error) => {
@@ -389,20 +390,14 @@ watch(userError, (error) => {
const { data: subscriptions } = useQuery({
queryKey: computed(() => ['billing', 'subscriptions', user.value?.id]),
queryFn: () =>
useBaseFetch(`billing/subscriptions?user_id=${user.value.id}`, {
internal: true,
}),
queryFn: () => client.labrinth.billing_internal.getSubscriptions(user.value.id),
enabled: computed(() => !!user.value?.id),
placeholderData: [],
})
const { data: charges, refetch: refreshCharges } = useQuery({
queryKey: computed(() => ['billing', 'payments', user.value?.id]),
queryFn: () =>
useBaseFetch(`billing/payments?user_id=${user.value.id}`, {
internal: true,
}),
queryFn: () => client.labrinth.billing_internal.getPayments(user.value.id),
enabled: computed(() => !!user.value?.id),
placeholderData: [],
})
@@ -463,15 +458,11 @@ async function applyCredit() {
crediting.value = true
try {
const daysParsed = Math.max(1, Math.floor(Number(creditDays.value) || 1))
await useBaseFetch('billing/credit', {
method: 'POST',
body: JSON.stringify({
subscription_ids: [selectedSubscription.value.id],
days: daysParsed,
send_email: creditSendEmail.value,
message: DEFAULT_CREDIT_EMAIL_MESSAGE,
}),
internal: true,
await client.labrinth.billing_internal.credit({
subscription_ids: [selectedSubscription.value.id],
days: daysParsed,
send_email: creditSendEmail.value,
message: DEFAULT_CREDIT_EMAIL_MESSAGE,
})
addNotification({
title: 'Credit applied',
@@ -501,11 +492,7 @@ async function refundCharge() {
? { type: 'none', unprovision: unprovision.value }
: { type: 'full', unprovision: unprovision.value }
await useBaseFetch(`billing/charge/${selectedCharge.value.id}/refund`, {
method: 'POST',
body: JSON.stringify(payload),
internal: true,
})
await client.labrinth.billing_internal.refundCharge(selectedCharge.value.id, payload)
await refreshCharges()
refundModal.value.hide()
} catch (err) {
@@ -521,12 +508,8 @@ async function refundCharge() {
async function modifyCharge() {
modifying.value = true
try {
await useBaseFetch(`billing/subscription/${selectedSubscription.value.id}`, {
method: 'PATCH',
body: JSON.stringify({
cancelled: cancel.value,
}),
internal: true,
await client.labrinth.billing_internal.editSubscription(selectedSubscription.value.id, {
cancelled: cancel.value,
})
addNotification({
title: 'Modifications made',