mirror of
https://github.com/modrinth/code.git
synced 2026-09-03 05:25:58 +00:00
feat: header migration pt 2
This commit is contained in:
@@ -10,7 +10,9 @@ import {
|
||||
} from '@modrinth/assets'
|
||||
import type { BrowseInstallContentType, CardAction, ProjectType, Tags } from '@modrinth/ui'
|
||||
import {
|
||||
BrowseInstallHeader,
|
||||
BrowsePageLayout,
|
||||
BrowseSidebar,
|
||||
commonMessages,
|
||||
CreationFlowModal,
|
||||
defineMessages,
|
||||
@@ -21,8 +23,10 @@ import {
|
||||
preferencesDiffer,
|
||||
provideBrowseManager,
|
||||
requestInstall,
|
||||
SelectedProjectsFloatingBar,
|
||||
useBrowseSearch,
|
||||
useDebugLogger,
|
||||
useStickyObserver,
|
||||
useVIntl,
|
||||
} from '@modrinth/ui'
|
||||
import { useQueryClient } from '@tanstack/vue-query'
|
||||
@@ -79,6 +83,7 @@ const {
|
||||
isSetupServerContext,
|
||||
effectiveServerWorldId,
|
||||
serverContextServerData,
|
||||
serverContextWorldName,
|
||||
serverContentProjectIds,
|
||||
queuedServerInstallProjectIds,
|
||||
queuedServerInstallCount,
|
||||
@@ -412,6 +417,10 @@ const messages = defineMessages({
|
||||
id: 'app.browse.back-to-instance',
|
||||
defaultMessage: 'Back to instance',
|
||||
},
|
||||
worldFallbackName: {
|
||||
id: 'app.browse.server.world-fallback-name',
|
||||
defaultMessage: 'Instance',
|
||||
},
|
||||
serverInstanceContentWarning: {
|
||||
id: 'app.browse.server-instance-content-warning',
|
||||
defaultMessage:
|
||||
@@ -565,8 +574,9 @@ const selectableProjectTypes = computed(() => {
|
||||
const installContext = computed(() => {
|
||||
if (isServerContext.value && serverContextServerData.value) {
|
||||
return {
|
||||
name: serverContextServerData.value.name,
|
||||
name: serverContextWorldName.value ?? formatMessage(messages.worldFallbackName),
|
||||
loader: serverContextServerData.value.loader ?? '',
|
||||
loaderVersion: serverContextServerData.value.loader_version ?? '',
|
||||
gameVersion: serverContextServerData.value.mc_version ?? '',
|
||||
serverId: serverIdQuery.value,
|
||||
upstream: serverContextServerData.value.upstream,
|
||||
@@ -606,6 +616,11 @@ const installContext = computed(() => {
|
||||
}
|
||||
return null
|
||||
})
|
||||
const stickyInstallHeaderRef = ref<HTMLElement | null>(null)
|
||||
const { isStuck: isInstallHeaderStuck } = useStickyObserver(
|
||||
stickyInstallHeaderRef,
|
||||
'BrowseInstallHeader',
|
||||
)
|
||||
|
||||
const installingProjectIds = ref<Set<string>>(new Set())
|
||||
|
||||
@@ -1092,6 +1107,17 @@ provideBrowseManager({
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-3 p-6">
|
||||
<div
|
||||
v-if="installContext"
|
||||
ref="stickyInstallHeaderRef"
|
||||
class="sticky top-0 z-20 -mx-6 -mt-6 rounded-tl-[--radius-xl] border-0 border-b border-solid bg-surface-1 p-3 border-surface-5"
|
||||
:class="[isInstallHeaderStuck ? 'border-t' : '']"
|
||||
>
|
||||
<BrowseInstallHeader />
|
||||
</div>
|
||||
|
||||
<SelectedProjectsFloatingBar v-if="installContext" />
|
||||
|
||||
<BrowsePageLayout>
|
||||
<template #after>
|
||||
<ContextMenu ref="contextMenuRef" @option-clicked="handleOptionsClick">
|
||||
@@ -1118,5 +1144,9 @@ provideBrowseManager({
|
||||
@browse-modpacks="() => {}"
|
||||
@create="handleServerModpackFlowCreate"
|
||||
/>
|
||||
|
||||
<Teleport to="#sidebar-teleport-target">
|
||||
<BrowseSidebar />
|
||||
</Teleport>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -53,6 +53,7 @@ export interface ServerInstallContentContext {
|
||||
isSetupServerContext: ComputedRef<boolean>
|
||||
effectiveServerWorldId: ComputedRef<string | null>
|
||||
serverContextServerData: Ref<Archon.Servers.v0.Server | null>
|
||||
serverContextWorldName: ComputedRef<string | null>
|
||||
serverContentProjectIds: Ref<Set<string>>
|
||||
queuedServerInstallProjectIds: ComputedRef<Set<string>>
|
||||
queuedServerInstallCount: ComputedRef<number>
|
||||
@@ -226,6 +227,7 @@ export function createServerInstallContent(opts: {
|
||||
|
||||
const serverContextWorldId = ref<string | null>(worldIdQuery.value)
|
||||
const serverContextServerData = ref<Archon.Servers.v0.Server | null>(null)
|
||||
const serverContextServerFull = ref<Archon.Servers.v1.ServerFull | null>(null)
|
||||
const serverContentProjectIds = ref<Set<string>>(new Set())
|
||||
const serverContentInstallKeys = ref<Set<string>>(new Set())
|
||||
const queuedServerInstalls = ref<Map<string, BrowseInstallPlan<InstallableSearchResult>>>(
|
||||
@@ -243,6 +245,18 @@ export function createServerInstallContent(opts: {
|
||||
const isInstallingQueuedServerInstalls = ref(false)
|
||||
const queuedInstallProgress = ref({ completed: 0, total: 0 })
|
||||
const effectiveServerWorldId = computed(() => worldIdQuery.value ?? serverContextWorldId.value)
|
||||
const serverContextWorld = computed(() => {
|
||||
const serverFull = serverContextServerFull.value
|
||||
if (!serverFull) return null
|
||||
|
||||
const worldId = effectiveServerWorldId.value
|
||||
if (worldId) {
|
||||
return serverFull.worlds.find((world) => world.id === worldId) ?? null
|
||||
}
|
||||
|
||||
return serverFull.worlds.find((world) => world.is_active) ?? serverFull.worlds[0] ?? null
|
||||
})
|
||||
const serverContextWorldName = computed(() => serverContextWorld.value?.name ?? null)
|
||||
const serverBackUrl = computed(() => {
|
||||
const sid = serverIdQuery.value
|
||||
if (!sid) return '/hosting/manage'
|
||||
@@ -266,9 +280,19 @@ export function createServerInstallContent(opts: {
|
||||
return 'Installing content'
|
||||
})
|
||||
|
||||
async function getServerContextServerFull(serverId: string) {
|
||||
if (serverContextServerFull.value?.id === serverId) {
|
||||
return serverContextServerFull.value
|
||||
}
|
||||
|
||||
const server = await client.archon.servers_v1.get(serverId)
|
||||
serverContextServerFull.value = server
|
||||
return server
|
||||
}
|
||||
|
||||
async function resolveServerContextWorldId(serverId: string) {
|
||||
try {
|
||||
const server = await client.archon.servers_v1.get(serverId)
|
||||
const server = await getServerContextServerFull(serverId)
|
||||
const activeWorld = server.worlds.find((world) => world.is_active)
|
||||
return activeWorld?.id ?? server.worlds[0]?.id ?? null
|
||||
} catch (err) {
|
||||
@@ -304,6 +328,11 @@ export function createServerInstallContent(opts: {
|
||||
} catch (err) {
|
||||
handleError(err as Error)
|
||||
}
|
||||
try {
|
||||
await getServerContextServerFull(sid)
|
||||
} catch (err) {
|
||||
handleError(err as Error)
|
||||
}
|
||||
|
||||
let resolvedWorldId = effectiveServerWorldId.value
|
||||
if (!resolvedWorldId) {
|
||||
@@ -323,6 +352,7 @@ export function createServerInstallContent(opts: {
|
||||
watch([serverIdQuery, effectiveServerWorldId], async ([sid, wid], [prevSid, prevWid]) => {
|
||||
if (!sid) {
|
||||
serverContextServerData.value = null
|
||||
serverContextServerFull.value = null
|
||||
serverContentProjectIds.value = new Set()
|
||||
serverContentInstallKeys.value = new Set()
|
||||
setQueuedServerInstallPlans(new Map())
|
||||
@@ -330,6 +360,8 @@ export function createServerInstallContent(opts: {
|
||||
}
|
||||
|
||||
if (sid !== prevSid) {
|
||||
serverContextWorldId.value = worldIdQuery.value
|
||||
serverContextServerFull.value = null
|
||||
serverContentProjectIds.value = new Set()
|
||||
serverContentInstallKeys.value = new Set()
|
||||
queuedServerInstalls.value = readStoredServerInstallQueue(sid, wid)
|
||||
@@ -338,6 +370,15 @@ export function createServerInstallContent(opts: {
|
||||
} catch (err) {
|
||||
handleError(err as Error)
|
||||
}
|
||||
try {
|
||||
const serverFull = await getServerContextServerFull(sid)
|
||||
if (!worldIdQuery.value) {
|
||||
const activeWorld = serverFull.worlds.find((world) => world.is_active)
|
||||
serverContextWorldId.value = activeWorld?.id ?? serverFull.worlds[0]?.id ?? null
|
||||
}
|
||||
} catch (err) {
|
||||
handleError(err as Error)
|
||||
}
|
||||
}
|
||||
|
||||
if (wid !== prevWid) {
|
||||
@@ -586,6 +627,7 @@ export function createServerInstallContent(opts: {
|
||||
isSetupServerContext,
|
||||
effectiveServerWorldId,
|
||||
serverContextServerData,
|
||||
serverContextWorldName,
|
||||
serverContentProjectIds,
|
||||
queuedServerInstallProjectIds,
|
||||
queuedServerInstallCount,
|
||||
|
||||
Reference in New Issue
Block a user