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

@@ -327,6 +327,7 @@ import {
commonMessages,
CopyCode,
DropdownSelect,
injectModrinthClient,
injectNotificationManager,
NewModal,
ProjectStatusBadge,
@@ -341,6 +342,7 @@ import OrganizationProjectTransferModal from '~/components/ui/OrganizationProjec
import { getProjectTypeForUrl } from '~/helpers/projects.js'
import { injectOrganizationContext } from '~/providers/organization-context.ts'
const client = injectModrinthClient()
const { addNotification } = injectNotificationManager()
const { formatMessage } = useVIntl()
@@ -350,7 +352,7 @@ const auth = await useAuth()
const { data: userProjects, refetch: refreshUserProjects } = useQuery({
queryKey: computed(() => ['user', auth.value?.user?.id, 'projects']),
queryFn: () => useBaseFetch(`user/${auth.value.user.id}/projects`),
queryFn: () => client.labrinth.users_v2.getProjects(auth.value.user.id),
enabled: computed(() => !!auth.value?.user?.id),
placeholderData: [],
})
@@ -366,11 +368,7 @@ watch(
const projects = userProjects.value.filter((project) => project.organization === null)
const teamIds = projects.map((project) => project?.team).filter((x) => x)
// Shape of teams is member[][]
const teams = await useBaseFetch(`teams?ids=${JSON.stringify(teamIds)}`, {
apiVersion: 3,
})
// for each team id, figure out if the user is a member, and is_owner. Then filter the projects to only include those that are owned by the user
const teams = await client.labrinth.teams_v3.getMultiple(teamIds)
const ownedTeamIds = teamIds.filter((_tid, i) => {
const team = teams?.[i]
if (!team) return false
@@ -379,19 +377,15 @@ watch(
})
const ownedProjects = projects.filter((project) => ownedTeamIds.includes(project.team))
usersOwnedProjects.value = ownedProjects
}, // watch options
},
{ immediate: true, deep: true },
)
const onProjectTransferSubmit = async (projects) => {
try {
for (const project of projects) {
await useBaseFetch(`organization/${organization.value.id}/projects`, {
method: 'POST',
body: JSON.stringify({
project_id: project.id,
}),
apiVersion: 3,
await client.labrinth.organizations_v3.addProject(organization.value.id, {
project_id: project.id,
})
}
@@ -488,17 +482,17 @@ const updateDescending = () => {
const onBulkEditLinks = async () => {
try {
const baseData = {
issues_url: editLinks.value.issues.clear ? null : editLinks.value.issues.val.trim(),
source_url: editLinks.value.source.clear ? null : editLinks.value.source.val.trim(),
wiki_url: editLinks.value.wiki.clear ? null : editLinks.value.wiki.val.trim(),
discord_url: editLinks.value.discord.clear ? null : editLinks.value.discord.val.trim(),
issues_url: editLinks.issues.clear ? null : editLinks.issues.val.trim(),
source_url: editLinks.source.clear ? null : editLinks.source.val.trim(),
wiki_url: editLinks.wiki.clear ? null : editLinks.wiki.val.trim(),
discord_url: editLinks.discord.clear ? null : editLinks.discord.val.trim(),
}
const filteredData = Object.fromEntries(Object.entries(baseData).filter(([, v]) => v !== ''))
await useBaseFetch(`projects?ids=${JSON.stringify(selectedProjects.value.map((x) => x.id))}`, {
method: 'PATCH',
body: JSON.stringify(filteredData),
})
await client.labrinth.projects_v2.bulkEdit(
selectedProjects.value.map((x) => x.id),
filteredData,
)
editLinksModal.value?.hide()
addNotification({
@@ -508,14 +502,14 @@ const onBulkEditLinks = async () => {
})
selectedProjects.value = []
editLinks.value.issues.val = ''
editLinks.value.source.val = ''
editLinks.value.wiki.val = ''
editLinks.value.discord.val = ''
editLinks.value.issues.clear = false
editLinks.value.source.clear = false
editLinks.value.wiki.clear = false
editLinks.value.discord.clear = false
editLinks.issues.val = ''
editLinks.source.val = ''
editLinks.wiki.val = ''
editLinks.discord.val = ''
editLinks.issues.clear = false
editLinks.source.clear = false
editLinks.wiki.clear = false
editLinks.discord.clear = false
} catch (e) {
addNotification({
title: 'An error occurred',