Files
AstralRinth/packages/ui/src/layouts/shared/content-tab/components/modals/ContentInstallModal.vue
T
Calum H. 7d92e4ec7f feat: content tab rewrite for worlds (#5136)
* feat: base content card component

* fix: tooltips + colors

* feat: fix orgs

* feat: base content tab internals rewrite

* feat: fix invalidmodal

* feat: add ContentModpackCard

* fix: extract types

* draft: layout

* feat: unlink modal

* feat: impl content tab

* fix: lint

* fix: toggling

* temp: disable updating stuff

* feat: selection v-model

* feat: bulk selection

* feat: mods tab rough draft

* feat: use fuse.js

* feat: add project combobox

* clean up project combobox

* feat: start install to play modal

* fix: events

* feat: use v-on

* feat: bulk actions + fix floating action bar width

* feat: figma alignments

* feat: migrate toggle to tailwind

* fix: row borders

* feat: disabled state

* feat: virtual list impl for card table based on window scroll

* fix: lint

* feat: virtualization + smaller contentcard items

* feat: use ContentCardTable + ContentCardItems

* feat: fix gap + border issues on last elm

* feat: cleanup + use proper searching

* fix: use TeleportOverflowMenu

* fix: fallback to svg if src is invalid on avatar component

* fix: storybook

* feat: start on updater modal

* feat: finish content updater modal

* feat: i18n pass

* feat: impl modal

* feat(app): backend changes for content tab refactor (#5237)

* feat: include_changelog=false for updater modal

* fix: hash overrides

* feat: update checking for modpack

* feat: qa

* feat: modpack content modal

* fix: padding in table to match modals + tightness

* fix: lint

* feat: delete modal

* feat: fix toggle bugs

* fix: prepr

* fix: duplicate messages

* qa: full width search

* qa: use bg-surface-1.5

* qa: animation for filter pills

* qa: standardize hover colors

* fix: border-[1px] is border

* qa: mass de-select actually mass selecting

* qa: match figma designs for floating action bar

* qa: modal fixes

* q: modal fixes x2

* fix: table border

* qa: confirm modals

* qa: modal alignment

* qa: re-add stuck heading + dedupe logic

* qa: dedupe virtual scrolling + remove dead components

* qa: responsiveness for content table + link fixes

* qa: version column link, tooltips + lint fixes

* qa: instance busy protections

* fix: installation freeze bug

* chore: remove old mods page

* refactor: deduplicate layout

* chore: delete old content page(s)

* qa

* qa

* qa

* feat: sort btn - to iterate

* fix: ml

* feat: date added

* fix: lint

* fix: formatting.ts removal

* feat: get_dependencies_as_content_items

* qa: final QA changes

* refactor: deduplicate + polish content.rs

* feat: hook up content.vue with v1

* feat: hide v1 content api behind frontend feature flag

* fix: query keys + copy on empty state

* chore: i18n pass

* feat: reimpl unlink + upload endpoint

* feat: use bulk endpoints v1

* fix: lint

* fix: flags

* fix: responsiveness via container queries

* fix: lint

* qa: 1

* qa: fixes

* qa: fix ssr issues with browse content

* qa: header page divider

* qa: modals

* fix: prepr

* fix: issues

* fix: lint

* fix: toggle v1 ff

* qa: 5

* qa: delete modal copy

* feat: creation flow modals (#5383)

* refactor: delete content v0 usages + impl

* feat: qa + fixes

* feat: installing banner using state event

* feat: fix modpack card bugs + filtering issues

* refactor: delete backups v0 api module

* feat: v1 servers GET endpoint

* fix: backups

* feat: swap to kyros upload v1 addon

* fix: use tanstack for loader.vue

* feat: finish install from discovery modal

* qa: bug fixes

* feat: set up installation settings

* fix: lint

* fix: typos

* fix: bugs

* fix: disable inline content

* feat: content tab improvements — upload UX, installation settings, and client-only indicators

   Upload cancellation and navigation guard:
   - Add ConfirmLeaveModal that prompts when navigating away during upload
   - Cancel in-flight XHR uploads when user confirms leaving the page
   - Add beforeunload handler to warn on browser/tab close during upload
   - Track uploadedBytes/totalBytes in UploadState for progress display
   - Replace Collapsible with Transition for upload progress admonition
   - Show byte progress and percentage in upload banner
   - Clamp upload progress to prevent exceeding 100%

   Installation settings (server.properties):
   - Add KnownPropertiesFields and PropertiesFields types to Archon types
   - Add buildProperties() to creation flow context to collect gamemode,
     difficulty, seed, world type, structures, and generator settings
   - Pass properties through installContent on onboarding, discovery, and
     ServerSetupModal flows

   Server setup and discovery flow improvements:
   - Migrate ServerSetupModal from servers_v0.reinstall to content_v1.installContent
   - Replace loaderApiNames lookup with toApiLoader() helper
   - Remove eraseDataOnInstall toggle — always use soft_override: false
   - Simplify modpack install on discovery page to use first available version
     and route through creation flow modal for both onboarding and non-onboarding
   - Differentiate post-install navigation: content page for onboarding,
     loader options for existing servers

   Modpack update flow:
   - Replace updateModpack() call with installContent() using soft_override: true
     to support version selection in the content updater modal

   Client-only mod indicators:
   - Add environment field to AddonVersion (reuses Labrinth.Projects.v3.Environment)
   - Add environment to ContentItem and isClientOnly to ContentCardTableItem
   - Show orange TriangleAlertIcon with tooltip on client-only mods in content table
   - Add "Client-only" filter pill to content filtering (controlled via
     showClientOnlyFilter on ContentManagerContext)
   - Apply client-only indicators in both ContentPageLayout and ModpackContentModal

   Misc:
   - Add CLAUDE.md note about using prepr commands for lint checks
   - Export ConfirmLeaveModal from instances barrel

* fix: piping

* fix: switch content disable for linked server instances

* feat: client only filter

* fix: prepr

* feat: hasUpdate shape update

* feat: bulk update endpoint impl for content in panel

* feat: websocket state impl again with new phases

* fix: ws

* fix: use timeout fn for sync admon + fix content card layout scroll for browsers with overflow anchor bug

* fix: qa bugs

* fix: lint, a11y and i18n

* refactor: set up layouts folder properly

* fix: linked data cache stuff + lint

* feat: move installationsettings to shared layout

* fix: lint

* fix: issues

* feat: temp fuck staging up

* fix: lockfile

* fix: data sync issues on loader.vue

* fix: lint

* Hide shader configuration files from content list (#5499)

* feat: workaround search problem + split out reset

* fix: qa

* fix: changelog not showing on first open

* fix: qa + optimistic updating improvements

* fix: prepr+lint

* fix: qa

* feat: qa

* fix: lint

* fix: lint

* fix: build

* fix: build

* fix: type errors

* fix: fade and JAVA_HOME passthrough

* feat: qa

* feat: impl diff shit

* fix: qa

* fix: app qa

* feat: update diff modal

* fix: endpoint

* fix: qa

* fix: qa

* fix: use bulk in modpack modal

* feat: abort signal impl + fix issues

* fix: diff modal trunc

* feat: qa

* fix: qa

* feat: tooltip content tab

* fix: prepr

* fix: dismiss on settings btn

* feat: qa

* feat: dont clear handlers on disconnect

* fix: lint

* fix: wrangler + introduce staging-archon env file

---------

Signed-off-by: Calum H. <calum@modrinth.com>
Co-authored-by: tdgao <mr.trumgao@gmail.com>
Co-authored-by: Artyom Ezri <61311568+Artezon@users.noreply.github.com>
2026-03-12 13:24:32 -07:00

461 lines
13 KiB
Vue

<template>
<NewModal ref="modal" no-padding scrollable max-width="560px" width="560px" :on-hide="handleHide">
<template #title>
<span class="text-2xl font-semibold text-contrast">
{{ formatMessage(messages.header) }}
</span>
</template>
<div class="flex flex-col gap-2.5 p-6">
<span class="font-semibold text-contrast">
{{ formatMessage(messages.instanceType) }}
</span>
<Chips v-model="tab" :items="tabs" :format-label="formatTabLabel" :never-empty="true" />
</div>
<div class="h-px bg-divider" />
<!-- Existing instance tab -->
<div
v-if="tab === 'existing'"
class="flex flex-col gap-3 bg-surface-2 py-4"
style="height: 400px; overflow-y: auto"
>
<div class="flex items-start gap-3 px-6">
<StyledInput
v-model="searchFilter"
:icon="SearchIcon"
:placeholder="formatMessage(messages.searchPlaceholder)"
class="flex-1"
/>
<ButtonStyled type="outlined" circular>
<button
v-tooltip="`${hideUninstallable ? 'Show' : 'Hide'} unavailable`"
class="!border-surface-4 !border"
@click="hideUninstallable = !hideUninstallable"
>
<EyeIcon v-if="hideUninstallable" />
<EyeOffIcon v-else />
</button>
</ButtonStyled>
</div>
<div v-if="loading" class="flex items-center justify-center py-12">
<LoadingIndicator />
</div>
<div
v-else-if="filteredInstances.length === 0"
class="flex items-center justify-center py-12 text-secondary"
>
{{ formatMessage(messages.noInstances) }}
</div>
<div v-else class="flex flex-col gap-1">
<div
v-for="inst in filteredInstances"
:key="inst.id"
class="flex items-center justify-between px-6 py-1.5"
:class="
!inst.compatible ? 'opacity-40' : inst.installed ? 'opacity-60' : 'hover:bg-surface-3'
"
>
<button
v-tooltip="
!inst.compatible ? 'This instance is not compatible with this project' : undefined
"
class="flex min-w-0 cursor-pointer items-center gap-2.5 overflow-hidden border-0 bg-transparent p-0 text-left"
@click="emit('navigate', inst)"
>
<Avatar :src="inst.iconUrl ?? undefined" size="2rem" rounded="md" />
<span class="truncate font-semibold text-contrast hover:underline">{{
inst.name
}}</span>
</button>
<ButtonStyled v-if="inst.installed" :disabled="true">
<button>
<CheckIcon />
{{ formatMessage(messages.installedBadge) }}
</button>
</ButtonStyled>
<ButtonStyled v-else-if="inst.compatible" :disabled="inst.installing">
<button @click="emit('install', inst)">
{{
inst.installing
? formatMessage(messages.installingLabel)
: formatMessage(messages.installButton)
}}
</button>
</ButtonStyled>
</div>
</div>
</div>
<!-- New instance tab -->
<div v-else class="flex flex-col gap-6 p-6">
<div class="flex items-center gap-4">
<Avatar :src="iconPreviewUrl ?? undefined" size="5rem" rounded="2xl" />
<div class="flex flex-col gap-2">
<ButtonStyled type="outlined">
<button class="!border-surface-4 !border" @click="selectIcon">
<UploadIcon />
{{ formatMessage(messages.selectIcon) }}
</button>
</ButtonStyled>
<ButtonStyled type="outlined">
<button
class="!border-surface-4 !border"
:disabled="!iconPreviewUrl"
@click="removeIcon"
>
<XIcon />
{{ formatMessage(messages.removeIcon) }}
</button>
</ButtonStyled>
</div>
</div>
<div class="flex flex-col gap-2.5">
<span class="font-semibold text-contrast">
{{ formatMessage(messages.nameLabel) }}
</span>
<StyledInput
v-model="instanceName"
:placeholder="formatMessage(messages.namePlaceholder)"
/>
</div>
<div class="flex flex-col gap-2.5">
<span class="font-semibold text-contrast">
{{ formatMessage(messages.loaderLabel) }}
</span>
<Chips
v-model="selectedLoader"
:items="compatibleLoaders"
:format-label="formatLoaderLabel"
:never-empty="true"
/>
</div>
<div class="flex flex-col gap-2.5">
<span class="font-semibold text-contrast">
{{ formatMessage(messages.gameVersionLabel) }}
</span>
<Combobox
v-model="selectedGameVersion"
:options="gameVersionOptions"
searchable
sync-with-selection
:placeholder="formatMessage(messages.gameVersionPlaceholder)"
>
<template v-if="hasReleaseData" #dropdown-footer>
<button
class="flex w-full cursor-pointer items-center justify-center gap-1.5 border-0 border-t border-solid border-surface-5 bg-transparent py-3 text-center text-sm font-semibold text-secondary transition-colors hover:text-contrast"
@mousedown.prevent
@click="showSnapshots = !showSnapshots"
>
<EyeOffIcon v-if="showSnapshots" class="size-4" />
<EyeIcon v-else class="size-4" />
{{
showSnapshots
? formatMessage(messages.hideSnapshots)
: formatMessage(messages.showAllVersions)
}}
</button>
</template>
</Combobox>
</div>
</div>
<template #actions>
<div v-if="tab === 'existing'" class="flex items-center justify-between pt-5 pb-1 px-4">
<div class="flex items-center gap-1.5">
<BoxIcon class="size-5" />
<span>
{{ formatMessage(messages.compatibleCount, { count: compatibleCount }) }}
</span>
</div>
<ButtonStyled type="outlined">
<button class="!border-surface-4 !border" @click="modal?.hide()">
<XIcon />
{{ formatMessage(commonMessages.cancelButton) }}
</button>
</ButtonStyled>
</div>
<div v-else class="flex items-center justify-end gap-2">
<ButtonStyled type="outlined">
<button class="!border-surface-4 !border" @click="modal?.hide()">
<XIcon />
{{ formatMessage(commonMessages.cancelButton) }}
</button>
</ButtonStyled>
<ButtonStyled color="brand">
<button :disabled="!instanceName" @click="handleCreateAndInstall">
<DownloadIcon />
{{ formatMessage(messages.installButton) }}
</button>
</ButtonStyled>
</div>
</template>
</NewModal>
</template>
<script setup lang="ts">
import {
BoxIcon,
CheckIcon,
DownloadIcon,
EyeIcon,
EyeOffIcon,
SearchIcon,
UploadIcon,
XIcon,
} from '@modrinth/assets'
import { computed, ref } from 'vue'
import Avatar from '#ui/components/base/Avatar.vue'
import ButtonStyled from '#ui/components/base/ButtonStyled.vue'
import Chips from '#ui/components/base/Chips.vue'
import Combobox, { type ComboboxOption } from '#ui/components/base/Combobox.vue'
import LoadingIndicator from '#ui/components/base/LoadingIndicator.vue'
import StyledInput from '#ui/components/base/StyledInput.vue'
import NewModal from '#ui/components/modal/NewModal.vue'
import { defineMessages, useVIntl } from '#ui/composables/i18n'
import { injectFilePicker } from '#ui/providers'
import { commonMessages } from '#ui/utils/common-messages'
import { formatLoaderLabel } from '#ui/utils/loaders'
const { formatMessage } = useVIntl()
const messages = defineMessages({
header: {
id: 'instances.content-install.header',
defaultMessage: 'Install project',
},
instanceType: {
id: 'instances.content-install.instance-type',
defaultMessage: 'Instance type',
},
existingTab: {
id: 'instances.content-install.existing-tab',
defaultMessage: 'Existing instance',
},
newTab: {
id: 'instances.content-install.new-tab',
defaultMessage: 'New instance',
},
searchPlaceholder: {
id: 'instances.content-install.search-placeholder',
defaultMessage: 'Search instance',
},
installedBadge: {
id: 'instances.content-install.installed-badge',
defaultMessage: 'Installed',
},
installingLabel: {
id: 'instances.content-install.installing-label',
defaultMessage: 'Installing...',
},
installButton: {
id: 'instances.content-install.install-button',
defaultMessage: 'Install',
},
selectIcon: {
id: 'instances.content-install.select-icon',
defaultMessage: 'Select icon',
},
removeIcon: {
id: 'instances.content-install.remove-icon',
defaultMessage: 'Remove icon',
},
nameLabel: {
id: 'instances.content-install.name-label',
defaultMessage: 'Name',
},
namePlaceholder: {
id: 'instances.content-install.name-placeholder',
defaultMessage: 'Enter instance name',
},
loaderLabel: {
id: 'instances.content-install.loader-label',
defaultMessage: 'Loader',
},
gameVersionLabel: {
id: 'instances.content-install.game-version-label',
defaultMessage: 'Game version',
},
gameVersionPlaceholder: {
id: 'instances.content-install.game-version-placeholder',
defaultMessage: 'Select game version',
},
compatibleCount: {
id: 'instances.content-install.compatible-count',
defaultMessage: '{count} compatible {count, plural, one {instance} other {instances}}',
},
noInstances: {
id: 'instances.content-install.no-instances',
defaultMessage: 'No compatible instances found',
},
showAllVersions: {
id: 'instances.content-install.show-all-versions',
defaultMessage: 'Show all versions',
},
hideSnapshots: {
id: 'instances.content-install.hide-snapshots',
defaultMessage: 'Hide snapshots',
},
})
export interface ContentInstallInstance {
id: string
name: string
iconUrl?: string | null
installed: boolean
compatible: boolean
installing?: boolean
}
const props = defineProps<{
instances: ContentInstallInstance[]
compatibleLoaders: string[]
gameVersions: string[]
releaseGameVersions?: Set<string>
loading?: boolean
defaultTab?: 'existing' | 'new'
preferredLoader?: string | null
preferredGameVersion?: string | null
}>()
const emit = defineEmits<{
install: [instance: ContentInstallInstance]
'create-and-install': [
data: {
name: string
iconPath: string | null
iconPreviewUrl: string | null
loader: string
gameVersion: string
},
]
navigate: [instance: ContentInstallInstance]
cancel: []
}>()
const modal = ref<InstanceType<typeof NewModal>>()
type Tab = 'existing' | 'new'
const tabs = computed<Tab[]>(() =>
props.compatibleLoaders.length > 0 ? ['existing', 'new'] : ['existing'],
)
const tab = ref<Tab>('existing')
const tabLabels: Record<Tab, () => string> = {
existing: () => formatMessage(messages.existingTab),
new: () => formatMessage(messages.newTab),
}
const formatTabLabel = (item: Tab) => tabLabels[item]()
const searchFilter = ref('')
const hideUninstallable = ref(true)
const filteredInstances = computed(() => {
let list = props.instances
if (hideUninstallable.value) list = list.filter((i) => i.compatible && !i.installed)
if (searchFilter.value) {
const query = searchFilter.value.toLowerCase()
list = list.filter((i) => i.name.toLowerCase().includes(query))
}
const score = (i: ContentInstallInstance) => (!i.compatible ? 2 : i.installed ? 1 : 0)
return list.slice().sort((a, b) => {
const diff = score(a) - score(b)
if (diff !== 0) return diff
return a.name.localeCompare(b.name)
})
})
const compatibleCount = computed(() => props.instances.filter((i) => i.compatible).length)
const instanceName = ref('')
const selectedLoader = ref<string | null>(null)
const selectedGameVersion = ref<string | null>(null)
const iconPath = ref<string | null>(null)
const iconPreviewUrl = ref<string | null>(null)
const showSnapshots = ref(false)
const hasReleaseData = computed(
() => props.releaseGameVersions && props.releaseGameVersions.size > 0,
)
const gameVersionOptions = computed<ComboboxOption<string>[]>(() => {
const versions =
showSnapshots.value || !hasReleaseData.value
? props.gameVersions
: props.gameVersions.filter((v) => props.releaseGameVersions!.has(v))
return versions.map((v) => ({ value: v, label: v }))
})
const filePicker = injectFilePicker(null)
async function selectIcon() {
if (!filePicker) return
const picked = await filePicker.pickImage()
if (picked) {
iconPath.value = picked.path ?? null
iconPreviewUrl.value = picked.previewUrl
}
}
function removeIcon() {
iconPath.value = null
iconPreviewUrl.value = null
}
function resetState() {
tab.value = props.defaultTab ?? 'existing'
searchFilter.value = ''
hideUninstallable.value = true
instanceName.value = `New instance (${props.instances.length + 1})`
iconPath.value = null
iconPreviewUrl.value = null
selectedLoader.value = props.preferredLoader ?? props.compatibleLoaders[0] ?? null
const preferred = props.preferredGameVersion
const isSnapshot = preferred && hasReleaseData.value && !props.releaseGameVersions!.has(preferred)
showSnapshots.value = !!isSnapshot
const defaultVersion = hasReleaseData.value
? (props.gameVersions.find((v) => props.releaseGameVersions!.has(v)) ??
props.gameVersions[0] ??
null)
: (props.gameVersions[0] ?? null)
selectedGameVersion.value = preferred ?? defaultVersion
}
function handleHide() {
resetState()
emit('cancel')
}
function show() {
resetState()
modal.value?.show()
}
function hide() {
modal.value?.hide()
}
function handleCreateAndInstall() {
if (!instanceName.value || !selectedLoader.value || !selectedGameVersion.value) return
emit('create-and-install', {
name: instanceName.value,
iconPath: iconPath.value,
iconPreviewUrl: iconPreviewUrl.value,
loader: selectedLoader.value,
gameVersion: selectedGameVersion.value,
})
hide()
}
defineExpose({ show, hide })
</script>