Skip to content

Commit 457254f

Browse files
authored
Revert "Revert "feat: sync individual content installation states on … (#7155)
Revert "Revert "feat: sync individual content installation states on panel" (…" This reverts commit 1dba3bf.
1 parent 283f38c commit 457254f

54 files changed

Lines changed: 2003 additions & 2426 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/app-frontend/src/providers/setup/server-install-content.ts‎

Lines changed: 15 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { Archon, Labrinth } from '@modrinth/api-client'
22
import {
3-
addPendingServerContentInstalls,
43
type BrowseInstallPlan,
54
type BrowseSelectedProject,
65
createContext,
@@ -12,12 +11,11 @@ import {
1211
injectModrinthClient,
1312
injectNotificationManager,
1413
type ModpackSearchResult,
15-
type PendingServerContentInstall,
16-
type PendingServerContentInstallType,
1714
readStoredServerInstallQueue,
18-
removePendingServerContentInstall,
1915
resolveServerAddonInstallPlans,
20-
writePendingServerContentInstallBaseline,
16+
useServerContextRuntime,
17+
useServerPanelSync,
18+
waitForServerContextRuntimeReady,
2119
writeStoredServerInstallQueue,
2220
} from '@modrinth/ui'
2321
import { useQueryClient } from '@tanstack/vue-query'
@@ -30,7 +28,6 @@ type InstallableSearchResult = Labrinth.Search.v3.ResultSearchProject & {
3028
installing?: boolean
3129
installed?: boolean
3230
}
33-
type PendingServerContentInstallInput = Omit<PendingServerContentInstall, 'createdAt'>
3431

3532
export interface ServerModpackSelectionRequest {
3633
projectId: string
@@ -96,61 +93,6 @@ function readQueryString(value: unknown): string | null {
9693
return typeof value === 'string' && value.length > 0 ? value : null
9794
}
9895

99-
function getQueuedInstallOwnerFallback(project: InstallableSearchResult) {
100-
if (project.organization) {
101-
const ownerId = project.organization_id ?? project.organization
102-
return {
103-
id: ownerId,
104-
name: project.organization,
105-
type: 'organization' as const,
106-
link: `https://modrinth.com/organization/${ownerId}`,
107-
}
108-
}
109-
110-
if (!project.author) return null
111-
112-
const ownerId = project.author_id ?? project.author
113-
return {
114-
id: ownerId,
115-
name: project.author,
116-
type: 'user' as const,
117-
link: `/user/${encodeURIComponent(ownerId)}`,
118-
}
119-
}
120-
121-
function getQueuedAddonInstallPlans(
122-
plans: Map<string, BrowseInstallPlan<InstallableSearchResult>>,
123-
) {
124-
return Array.from(plans.values()).filter((plan) => plan.contentType !== 'modpack')
125-
}
126-
127-
function getQueuedInstallPlaceholder(
128-
plan: BrowseInstallPlan<InstallableSearchResult>,
129-
owner: PendingServerContentInstallInput['owner'],
130-
): PendingServerContentInstallInput {
131-
const project = plan.project as InstallableSearchResult & { slug?: string | null }
132-
return {
133-
projectId: plan.projectId,
134-
versionId: plan.versionId,
135-
contentType: plan.contentType as PendingServerContentInstallType,
136-
title: project.name ?? 'Project',
137-
versionName: plan.versionName ?? null,
138-
versionNumber: plan.versionNumber ?? null,
139-
fileName: plan.fileName ?? null,
140-
owner,
141-
slug: project.slug ?? plan.projectId,
142-
iconUrl: project.icon_url ?? null,
143-
}
144-
}
145-
146-
function getQueuedInstallPlaceholderFallbacks(
147-
plans: Map<string, BrowseInstallPlan<InstallableSearchResult>>,
148-
) {
149-
return getQueuedAddonInstallPlans(plans).map((plan) =>
150-
getQueuedInstallPlaceholder(plan, getQueuedInstallOwnerFallback(plan.project)),
151-
)
152-
}
153-
15496
export function createServerInstallContent(opts: {
15597
serverSetupModalRef: Ref<ServerSetupModalHandle | null>
15698
}) {
@@ -173,6 +115,7 @@ export function createServerInstallContent(opts: {
173115
const isFromWorlds = computed(() => browseFrom.value === 'worlds')
174116
const isServerContext = computed(() => !!serverIdQuery.value)
175117
const isSetupServerContext = computed(() => !!serverIdQuery.value && !!serverFlowFrom.value)
118+
useServerContextRuntime(serverIdQuery)
176119

177120
const serverContextWorldId = ref<string | null>(worldIdQuery.value)
178121

@@ -199,7 +142,6 @@ export function createServerInstallContent(opts: {
199142
initialServerId ? getCachedServer(initialServerId) : null,
200143
)
201144
const serverContentProjectIds = ref<Set<string>>(new Set())
202-
const serverContentInstallKeys = ref<Set<string>>(new Set())
203145
const queuedServerInstalls = ref<Map<string, BrowseInstallPlan<InstallableSearchResult>>>(
204146
new Map(),
205147
)
@@ -220,6 +162,10 @@ export function createServerInstallContent(opts: {
220162
const isInstallingQueuedServerInstalls = ref(false)
221163
const queuedInstallProgress = ref({ completed: 0, total: 0 })
222164
const effectiveServerWorldId = computed(() => worldIdQuery.value ?? serverContextWorldId.value)
165+
useServerPanelSync({
166+
serverId: serverIdQuery,
167+
worldId: effectiveServerWorldId,
168+
})
223169
const serverBackUrl = computed(() => {
224170
const sid = serverIdQuery.value
225171
if (!sid) return '/hosting/manage'
@@ -265,11 +211,7 @@ export function createServerInstallContent(opts: {
265211
.map((addon) => addon.project_id)
266212
.filter((projectId): projectId is string => !!projectId),
267213
)
268-
const keys = new Set(
269-
(content.addons ?? []).map((addon) => addon.project_id ?? addon.filename),
270-
)
271214
serverContentProjectIds.value = ids
272-
serverContentInstallKeys.value = keys
273215
} catch (err) {
274216
handleError(err as Error)
275217
}
@@ -311,14 +253,12 @@ export function createServerInstallContent(opts: {
311253
serverContextWorldId.value = null
312254
serverContextServerData.value = null
313255
serverContentProjectIds.value = new Set()
314-
serverContentInstallKeys.value = new Set()
315256
setQueuedServerInstallPlans(new Map())
316257
return
317258
}
318259

319260
if (sid !== prevSid) {
320261
serverContentProjectIds.value = new Set()
321-
serverContentInstallKeys.value = new Set()
322262
queuedServerInstalls.value = readStoredServerInstallQueue(sid, wid)
323263
serverContextServerData.value = getCachedServer(sid)
324264
try {
@@ -487,6 +427,13 @@ export function createServerInstallContent(opts: {
487427
const queuedPlans = getStoredServerAddonInstallQueue<InstallableSearchResult>(serverId, worldId)
488428
if (queuedPlans.size === 0) return true
489429

430+
try {
431+
await waitForServerContextRuntimeReady(client, serverId)
432+
} catch (error) {
433+
handleError(error as Error)
434+
return false
435+
}
436+
490437
isInstallingQueuedServerInstalls.value = true
491438
queuedInstallProgress.value = {
492439
completed: 0,
@@ -507,9 +454,6 @@ export function createServerInstallContent(opts: {
507454
})
508455

509456
if (!result.ok) {
510-
for (const plan of result.attemptedPlans) {
511-
removePendingServerContentInstall(serverId, worldId, plan.projectId)
512-
}
513457
handleError(result.error as Error)
514458
return false
515459
}
@@ -522,10 +466,6 @@ export function createServerInstallContent(opts: {
522466
...serverContentProjectIds.value,
523467
...result.flushedPlans.map((plan) => plan.projectId),
524468
])
525-
serverContentInstallKeys.value = new Set([
526-
...serverContentInstallKeys.value,
527-
...result.flushedPlans.map((plan) => plan.projectId),
528-
])
529469
if (result.flushedPlans.length > 0) {
530470
await queryClient.invalidateQueries({ queryKey: ['content', 'list', 'v1', serverId] })
531471
}
@@ -550,8 +490,6 @@ export function createServerInstallContent(opts: {
550490

551491
if (sid && wid) {
552492
writeStoredServerInstallQueue(sid, wid, plans)
553-
writePendingServerContentInstallBaseline(sid, wid, serverContentInstallKeys.value)
554-
addPendingServerContentInstalls(sid, wid, getQueuedInstallPlaceholderFallbacks(plans))
555493
}
556494
const installed = await flushQueuedServerInstalls(sid, wid)
557495
if (!installed) return false

‎apps/frontend/src/composables/use-server-install-content.ts‎

Lines changed: 16 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ import type {
66
CreationFlowContextValue,
77
EnvironmentSearchOverride,
88
FilterValue,
9-
PendingServerContentInstall,
10-
PendingServerContentInstallType,
119
} from '@modrinth/ui'
1210
import {
13-
addPendingServerContentInstalls,
1411
commonMessages,
1512
defineMessages,
1613
flushStoredServerAddonInstallQueue,
@@ -20,13 +17,14 @@ import {
2017
injectModrinthClient,
2118
injectNotificationManager,
2219
readStoredServerInstallQueue,
23-
removePendingServerContentInstall,
2420
requestInstall,
2521
resolveServerAddonInstallPlans,
2622
stripServerRuntimeInstallFilters,
2723
stripServerRuntimeInstallOverrides,
24+
useServerContextRuntime,
25+
useServerPanelSync,
2826
useVIntl,
29-
writePendingServerContentInstallBaseline,
27+
waitForServerContextRuntimeReady,
3028
writeStoredServerInstallQueue,
3129
} from '@modrinth/ui'
3230
import { useQuery, useQueryClient } from '@tanstack/vue-query'
@@ -36,7 +34,6 @@ import { computed, nextTick, ref, watch } from 'vue'
3634
import { navigateTo, useRoute } from '#app'
3735
import { queryAsString } from '~/utils/router'
3836

39-
type PendingServerContentInstallInput = Omit<PendingServerContentInstall, 'createdAt'>
4037
type ServerInstallBrowseSearchState = Pick<
4138
BrowseSearchState,
4239
'currentFilters' | 'overriddenProvidedFilterTypes'
@@ -89,34 +86,6 @@ const messages = defineMessages({
8986
},
9087
})
9188

92-
function getQueuedInstallOwnerFallback(project: ServerInstallSearchResult) {
93-
if (project.organization) {
94-
const ownerId = project.organization_id ?? project.organization
95-
return {
96-
id: ownerId,
97-
name: project.organization,
98-
type: 'organization' as const,
99-
link: `/organization/${ownerId}`,
100-
}
101-
}
102-
103-
if (!project.author) return null
104-
105-
const ownerId = project.author_id ?? project.author
106-
return {
107-
id: ownerId,
108-
name: project.author,
109-
type: 'user' as const,
110-
link: `/user/${ownerId}`,
111-
}
112-
}
113-
114-
function getQueuedAddonInstallPlans(
115-
plans: Map<string, BrowseInstallPlan<ServerInstallSearchResult>>,
116-
) {
117-
return Array.from(plans.values()).filter((plan) => plan.contentType !== 'modpack')
118-
}
119-
12089
export function useServerInstallContent({
12190
projectType,
12291
onboardingModalRef,
@@ -137,6 +106,11 @@ export function useServerInstallContent({
137106
const currentServerId = computed(() => queryAsString(route.query.sid) || null)
138107
const fromContext = computed(() => queryAsString(route.query.from) || null)
139108
const currentWorldId = computed(() => queryAsString(route.query.wid) || null)
109+
useServerContextRuntime(currentServerId)
110+
useServerPanelSync({
111+
serverId: currentServerId,
112+
worldId: currentWorldId,
113+
})
140114

141115
const {
142116
data: serverData,
@@ -225,32 +199,6 @@ export function useServerInstallContent({
225199
writeStoredServerInstallQueue(serverId, worldId, plans)
226200
}
227201

228-
function getQueuedInstallPlaceholder(
229-
plan: BrowseInstallPlan<ServerInstallSearchResult>,
230-
owner: PendingServerContentInstallInput['owner'],
231-
): PendingServerContentInstallInput {
232-
return {
233-
projectId: plan.projectId,
234-
versionId: plan.versionId,
235-
contentType: plan.contentType as PendingServerContentInstallType,
236-
title: getInstallProjectName(plan.project),
237-
versionName: plan.versionName ?? null,
238-
versionNumber: plan.versionNumber ?? null,
239-
fileName: plan.fileName ?? null,
240-
owner,
241-
slug: plan.project.slug ?? plan.projectId,
242-
iconUrl: plan.project.icon_url ?? null,
243-
}
244-
}
245-
246-
function getQueuedInstallPlaceholderFallbacks(
247-
plans: Map<string, BrowseInstallPlan<ServerInstallSearchResult>>,
248-
) {
249-
return getQueuedAddonInstallPlans(plans).map((plan) =>
250-
getQueuedInstallPlaceholder(plan, getQueuedInstallOwnerFallback(plan.project)),
251-
)
252-
}
253-
254202
function setProjectInstalling(projectId: string, installing: boolean) {
255203
const next = new Set(installingProjectIds.value)
256204
if (installing) {
@@ -276,10 +224,6 @@ export function useServerInstallContent({
276224
)
277225
}
278226

279-
function getServerInstalledContentKeys(data = serverContentData.value) {
280-
return new Set((data?.addons ?? []).map((addon) => addon.project_id ?? addon.filename))
281-
}
282-
283227
function syncHiddenInstalledProjectIds() {
284228
hiddenInstalledProjectIds.value = new Set([
285229
...getServerInstalledProjectIds(),
@@ -466,6 +410,13 @@ export function useServerInstallContent({
466410
)
467411
if (queuedPlans.size === 0) return true
468412

413+
try {
414+
await waitForServerContextRuntimeReady(client, serverId)
415+
} catch (error) {
416+
handleError(error as Error)
417+
return false
418+
}
419+
469420
isInstallingQueuedServerInstalls.value = true
470421
queuedInstallProgress.value = {
471422
completed: 0,
@@ -486,9 +437,6 @@ export function useServerInstallContent({
486437
})
487438

488439
if (!result.ok) {
489-
for (const plan of result.attemptedPlans) {
490-
removePendingServerContentInstall(serverId, worldId, plan.projectId)
491-
}
492440
handleError(result.error as Error)
493441
return false
494442
}
@@ -501,9 +449,7 @@ export function useServerInstallContent({
501449
total: result.flushedPlans.length,
502450
}
503451
if (result.flushedPlans.length > 0) {
504-
await queryClient.invalidateQueries({
505-
queryKey: ['content', 'list', 'v1', serverId],
506-
})
452+
await queryClient.invalidateQueries({ queryKey: ['content', 'list'] })
507453
}
508454

509455
return true
@@ -526,11 +472,6 @@ export function useServerInstallContent({
526472

527473
if (sid && wid) {
528474
writeStoredServerInstallQueue(sid, wid, plans)
529-
writePendingServerContentInstallBaseline(sid, wid, [
530-
...getServerInstalledContentKeys(),
531-
...optimisticallyInstalledProjectIds.value,
532-
])
533-
addPendingServerContentInstalls(sid, wid, getQueuedInstallPlaceholderFallbacks(plans))
534475
}
535476
const installed = await flushQueuedServerInstalls(sid, wid)
536477
if (!installed) return false

0 commit comments

Comments
 (0)