Skip to content

Commit 92eddbe

Browse files
authored
feat: move switch version inline like update btn for content tab (#5631)
* fix: switch version inline same as update btn * fix: lint
1 parent 9e6a6cd commit 92eddbe

File tree

8 files changed

+43
-36
lines changed

8 files changed

+43
-36
lines changed

apps/app-frontend/src/locales/en-US/index.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@
8686
"app.instance.mods.successfully-uploaded": {
8787
"message": "Successfully uploaded"
8888
},
89-
"app.instance.mods.switch-version": {
90-
"message": "Switch version"
91-
},
9289
"app.instance.mods.unknown-version": {
9390
"message": "Unknown"
9491
},

apps/app-frontend/src/pages/instance/Mods.vue

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363

6464
<script setup lang="ts">
6565
import type { Labrinth } from '@modrinth/api-client'
66-
import { ArrowLeftRightIcon, ClipboardCopyIcon, FolderOpenIcon } from '@modrinth/assets'
66+
import { ClipboardCopyIcon, FolderOpenIcon } from '@modrinth/assets'
6767
import {
6868
ConfirmModpackUpdateModal,
6969
type ContentItem,
@@ -165,10 +165,6 @@ const messages = defineMessages({
165165
id: 'app.instance.mods.copy-link',
166166
defaultMessage: 'Copy link',
167167
},
168-
switchVersion: {
169-
id: 'app.instance.mods.switch-version',
170-
defaultMessage: 'Switch version',
171-
},
172168
})
173169
174170
let savedModalState: ModpackContentModalState | null = null
@@ -386,7 +382,7 @@ async function switchProjectVersion(mod: ContentItem, version: Labrinth.Versions
386382
}
387383
388384
async function handleUpdate(id: string) {
389-
const item = projects.value.find((p) => p.file_name === id)
385+
const item = projects.value.find((p) => p.id === id)
390386
if (!item?.has_update || !item.project?.id || !item.version?.id) return
391387
392388
debug('handleUpdate triggered', {
@@ -663,14 +659,6 @@ async function handleShareItems(
663659
function getOverflowOptions(item: ContentItem): OverflowMenuOption[] {
664660
const options: OverflowMenuOption[] = []
665661
666-
if (item.project?.id && item.version?.id && !item.has_update) {
667-
options.push({
668-
id: formatMessage(messages.switchVersion),
669-
icon: ArrowLeftRightIcon,
670-
action: () => handleSwitchVersion(item),
671-
})
672-
}
673-
674662
options.push({
675663
id: formatMessage(messages.showFile),
676664
icon: FolderOpenIcon,
@@ -837,6 +825,7 @@ provideContentManager({
837825
viewModpackContent: handleModpackContent,
838826
unlinkModpack: unpairProfile,
839827
openSettings: props.openSettings,
828+
switchVersion: handleSwitchVersion,
840829
getOverflowOptions,
841830
showContentHint,
842831
dismissContentHint,

packages/ui/src/layouts/shared/content-tab/components/ContentCardItem.vue

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script setup lang="ts">
22
import {
3+
ArrowLeftRightIcon,
34
DownloadIcon,
45
MoreVerticalIcon,
56
SpinnerIcon,
@@ -67,11 +68,15 @@ const emit = defineEmits<{
6768
'update:enabled': [value: boolean]
6869
delete: [event: MouseEvent]
6970
update: []
71+
switchVersion: []
7072
}>()
7173
7274
const instance = getCurrentInstance()
7375
const hasDeleteListener = computed(() => typeof instance?.vnode.props?.onDelete === 'function')
7476
const hasUpdateListener = computed(() => typeof instance?.vnode.props?.onUpdate === 'function')
77+
const hasSwitchVersionListener = computed(
78+
() => typeof instance?.vnode.props?.onSwitchVersion === 'function',
79+
)
7580
7681
const versionNumberRef = ref<HTMLElement | null>(null)
7782
const fileNameRef = ref<HTMLElement | null>(null)
@@ -232,8 +237,11 @@ const deleteHovered = ref(false)
232237
>
233238
<slot name="additionalButtonsLeft" />
234239

235-
<!-- Fixed width container to reserve space for update button -->
236-
<div v-if="hasUpdateListener" class="flex w-8 items-center justify-center">
240+
<!-- Fixed width container to reserve space for update/switch version button -->
241+
<div
242+
v-if="hasUpdateListener || hasSwitchVersionListener"
243+
class="flex w-8 items-center justify-center"
244+
>
237245
<ButtonStyled
238246
v-if="hasUpdate"
239247
circular
@@ -250,6 +258,15 @@ const deleteHovered = ref(false)
250258
<DownloadIcon class="size-5" />
251259
</button>
252260
</ButtonStyled>
261+
<ButtonStyled v-else-if="hasSwitchVersionListener && version" circular type="transparent">
262+
<button
263+
v-tooltip="formatMessage(commonMessages.switchVersionButton)"
264+
:disabled="disabled"
265+
@click="emit('switchVersion')"
266+
>
267+
<ArrowLeftRightIcon class="size-5" />
268+
</button>
269+
</ButtonStyled>
253270
</div>
254271

255272
<Toggle

packages/ui/src/layouts/shared/content-tab/components/ContentCardTable.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,17 @@ const emit = defineEmits<{
4949
'update:enabled': [id: string, value: boolean]
5050
delete: [id: string, event: MouseEvent]
5151
update: [id: string]
52+
switchVersion: [id: string]
5253
sort: [column: ContentCardTableSortColumn, direction: ContentCardTableSortDirection]
5354
}>()
5455
5556
// Check if any actions are available
5657
const instance = getCurrentInstance()
5758
const hasDeleteListener = computed(() => typeof instance?.vnode.props?.onDelete === 'function')
5859
const hasUpdateListener = computed(() => typeof instance?.vnode.props?.onUpdate === 'function')
60+
const hasSwitchVersionListener = computed(
61+
() => typeof instance?.vnode.props?.onSwitchVersion === 'function',
62+
)
5963
const hasEnabledListener = computed(
6064
() => typeof instance?.vnode.props?.['onUpdate:enabled'] === 'function',
6165
)
@@ -65,6 +69,7 @@ const hasAnyActions = computed(() => {
6569
const hasListeners =
6670
(hasDeleteListener.value && !props.hideDelete) ||
6771
hasUpdateListener.value ||
72+
hasSwitchVersionListener.value ||
6873
hasEnabledListener.value
6974
7075
// Check if any items have overflow options or updates
@@ -294,6 +299,7 @@ function handleSort(column: ContentCardTableSortColumn) {
294299
@update:enabled="(val) => emit('update:enabled', item.id, val)"
295300
@delete="(e: MouseEvent) => emit('delete', item.id, e)"
296301
@update="emit('update', item.id)"
302+
@switch-version="emit('switchVersion', item.id)"
297303
>
298304
<template #additionalButtonsLeft>
299305
<slot name="itemButtonsLeft" :item="item" :index="visibleRange.start + idx" />
@@ -342,6 +348,7 @@ function handleSort(column: ContentCardTableSortColumn) {
342348
@update:enabled="(val) => emit('update:enabled', item.id, val)"
343349
@delete="(e: MouseEvent) => emit('delete', item.id, e)"
344350
@update="emit('update', item.id)"
351+
@switch-version="emit('switchVersion', item.id)"
345352
>
346353
<template #additionalButtonsLeft>
347354
<slot name="itemButtonsLeft" :item="item" :index="index" />

packages/ui/src/layouts/shared/content-tab/layout.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,13 @@ function handleUpdateById(id: string) {
407407
ctx.updateItem?.(id)
408408
}
409409
410+
function handleSwitchVersionById(id: string) {
411+
const item = ctx.items.value.find((i) => i.id === id)
412+
if (item) {
413+
ctx.switchVersion?.(item)
414+
}
415+
}
416+
410417
// Bulk updating
411418
const confirmBulkUpdateModal = ref<InstanceType<typeof ConfirmBulkUpdateModal>>()
412419
const pendingBulkUpdateItems = ref<ContentItem[]>([])
@@ -705,6 +712,7 @@ const confirmUnlinkModal = ref<InstanceType<typeof ConfirmUnlinkModal>>()
705712
@update:enabled="handleToggleEnabledById"
706713
@delete="handleDeleteById"
707714
@update="handleUpdateById"
715+
@switch-version="handleSwitchVersionById"
708716
>
709717
<template #empty>
710718
<span>{{ formatMessage(messages.noContentFound) }}</span>

packages/ui/src/layouts/shared/content-tab/providers/content-manager.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ export interface ContentManagerContext {
7878
unlinkModpack?: () => void
7979
openSettings?: () => void
8080

81+
// Switch version (optional)
82+
switchVersion?: (item: ContentItem) => void
83+
8184
// Per-item overflow menu (optional)
8285
getOverflowOptions?: (item: ContentItem) => OverflowMenuOption[]
8386

packages/ui/src/layouts/wrapped/hosting/manage/content.vue

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
import type { Archon, Labrinth } from '@modrinth/api-client'
3-
import { ArrowLeftRightIcon, ClipboardCopyIcon } from '@modrinth/assets'
3+
import { ClipboardCopyIcon } from '@modrinth/assets'
44
import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
55
import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue'
66
import { onBeforeRouteLeave, useRoute, useRouter } from 'vue-router'
@@ -78,10 +78,6 @@ const messages = defineMessages({
7878
id: 'hosting.content.failed-to-bulk-update',
7979
defaultMessage: 'Failed to update content',
8080
},
81-
switchVersion: {
82-
id: 'hosting.content.switch-version',
83-
defaultMessage: 'Switch version',
84-
},
8581
copyLink: {
8682
id: 'hosting.content.copy-link',
8783
defaultMessage: 'Copy link',
@@ -823,15 +819,7 @@ function handleModpackUpdateCancel() {
823819
}
824820
825821
function getOverflowOptions(item: ContentItem) {
826-
const options: { id: string; icon?: typeof ArrowLeftRightIcon; action: () => void }[] = []
827-
828-
if (item.project?.id && item.version?.id && !item.has_update) {
829-
options.push({
830-
id: formatMessage(messages.switchVersion),
831-
icon: ArrowLeftRightIcon,
832-
action: () => handleSwitchVersion(item),
833-
})
834-
}
822+
const options: { id: string; icon?: typeof ClipboardCopyIcon; action: () => void }[] = []
835823
836824
if (item.project?.slug) {
837825
options.push({
@@ -894,6 +882,7 @@ provideContentManager({
894882
viewModpackContent: handleViewModpackContent,
895883
unlinkModpack: handleModpackUnlink,
896884
openSettings: () => router.push(`/hosting/manage/${serverId}/options/loader`),
885+
switchVersion: handleSwitchVersion,
897886
getOverflowOptions,
898887
mapToTableItem: (item) => {
899888
const projectType = item.project_type ?? type.value

packages/ui/src/locales/en-US/index.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,6 @@
554554
"hosting.content.failed-to-upload": {
555555
"defaultMessage": "Failed to upload file"
556556
},
557-
"hosting.content.switch-version": {
558-
"defaultMessage": "Switch version"
559-
},
560557
"hosting.specs.burst": {
561558
"defaultMessage": "Bursts up to {cpus} CPUs"
562559
},

0 commit comments

Comments
 (0)