feat: card alignment + fix modals

This commit is contained in:
Calum H. (IMB11)
2026-04-18 15:47:28 +01:00
parent dd51c08a18
commit 36a09c495f
6 changed files with 270 additions and 77 deletions
@@ -45,9 +45,9 @@
</Transition> </Transition>
</div> </div>
<template #actions> <template #actions>
<div class="w-full flex flex-row gap-2 justify-end"> <div class="flex gap-2 justify-end">
<ButtonStyled type="outlined"> <ButtonStyled type="outlined">
<button class="!border-[1px] !border-surface-4" @click="hideModal"> <button class="!border !border-surface-4" @click="hideModal">
<XIcon /> <XIcon />
Cancel Cancel
</button> </button>
@@ -13,8 +13,8 @@
<template #actions> <template #actions>
<div class="flex gap-2 justify-end"> <div class="flex gap-2 justify-end">
<ButtonStyled> <ButtonStyled type="outlined">
<button @click="modal?.hide()"> <button class="!border !border-surface-4" @click="modal?.hide()">
<XIcon /> <XIcon />
Cancel Cancel
</button> </button>
@@ -2,11 +2,12 @@
import type { Archon } from '@modrinth/api-client' import type { Archon } from '@modrinth/api-client'
import { import {
ClipboardCopyIcon, ClipboardCopyIcon,
ClockIcon,
DownloadIcon, DownloadIcon,
EditIcon, EditIcon,
LoaderCircleIcon,
MoreVerticalIcon, MoreVerticalIcon,
RotateCounterClockwiseIcon, RotateCounterClockwiseIcon,
ShieldIcon,
TrashIcon, TrashIcon,
UserRoundIcon, UserRoundIcon,
XIcon, XIcon,
@@ -85,7 +86,7 @@ const activeOperation = computed(() => creating.value || restoring.value)
const backupIcon = computed(() => { const backupIcon = computed(() => {
if (props.backup.automated) { if (props.backup.automated) {
return ClockIcon return ShieldIcon
} }
return UserRoundIcon return UserRoundIcon
}) })
@@ -167,35 +168,54 @@ const messages = defineMessages({
id: 'servers.backups.item.manual-backup', id: 'servers.backups.item.manual-backup',
defaultMessage: 'Manual backup', defaultMessage: 'Manual backup',
}, },
creatingBackup: {
id: 'servers.backups.item.creating-backup',
defaultMessage: 'Creating backup\u2026',
},
restoring: {
id: 'servers.backups.item.restoring',
defaultMessage: 'Restoring',
},
}) })
</script> </script>
<template> <template>
<div <div
class="grid items-center gap-4 rounded-2xl bg-bg-raised p-4 shadow-md" class="flex items-center gap-4 rounded-[20px] bg-surface-3 p-4 shadow-[0px_1px_2px_0px_rgba(0,0,0,0.3),0px_1px_3px_0px_rgba(0,0,0,0.15)]"
:class="
preview
? 'grid-cols-1'
: 'grid-cols-[auto_1fr_auto] md:grid-cols-[minmax(0,1fr)_400px_minmax(0,1fr)]'
"
> >
<div class="flex flex-row gap-4 items-center"> <div class="flex min-w-0 flex-1 items-center gap-4">
<!-- Icon tile -->
<div <div
class="flex size-12 shrink-0 items-center justify-center rounded-2xl border-solid border-[1px] border-surface-5 bg-surface-4 md:size-16" class="flex shrink-0 items-center justify-center rounded-2xl border border-solid border-surface-5 bg-surface-4"
:class="preview ? 'size-10' : 'size-14'"
> >
<component :is="backupIcon" class="size-7 text-secondary md:size-10" /> <LoaderCircleIcon
v-if="activeOperation"
v-tooltip="restoring ? formatMessage(messages.restoring) : undefined"
class="animate-spin text-secondary"
:class="preview ? 'size-6' : 'size-10'"
/>
<component
:is="backupIcon"
v-else
class="text-secondary"
:class="preview ? 'size-6' : 'size-10'"
/>
</div> </div>
<!-- Name + badge + subtitle -->
<div class="flex min-w-0 flex-col gap-1.5"> <div class="flex min-w-0 flex-col gap-1.5">
<div class="flex flex-wrap items-center gap-2"> <div class="flex min-w-0 items-center gap-2">
<span class="truncate font-semibold text-contrast max-w-[400px]">{{ backup.name }}</span> <span class="min-w-0 truncate font-semibold text-contrast">
{{ creating ? formatMessage(messages.creatingBackup) : backup.name }}
</span>
<span <span
v-if="backup.automated" v-if="backup.automated"
class="rounded-full border-solid border-[1px] border-surface-5 bg-surface-4 px-2.5 py-1 text-sm text-secondary" class="shrink-0 rounded-full border border-solid border-surface-5 bg-surface-4 px-2.5 py-1 text-sm font-medium text-secondary"
> >
{{ formatMessage(messages.auto) }} {{ formatMessage(messages.auto) }}
</span> </span>
</div> </div>
<div class="flex items-center gap-1.5 text-sm text-secondary"> <div class="flex items-center gap-1.5 text-sm font-medium text-secondary">
<template v-if="preview"> <template v-if="preview">
<span>{{ formatDateTime(backup.created_at) }}</span> <span>{{ formatDateTime(backup.created_at) }}</span>
</template> </template>
@@ -227,47 +247,51 @@ const messages = defineMessages({
</div> </div>
</div> </div>
<div <!-- Date + size (middle column) -->
v-if="!preview" <div v-if="!preview" class="flex w-[240px] shrink-0 flex-col gap-1.5">
class="col-span-full row-start-2 flex flex-col gap-2 md:col-span-1 md:row-start-auto md:items-center" <span class="whitespace-nowrap font-medium text-contrast">{{ formatDateTime(backup.created_at) }}</span>
>
<span class="w-full font-medium text-contrast md:text-center">
{{ formatDateTime(backup.created_at) }}
</span>
<!-- TODO: Uncomment when API supports size field --> <!-- TODO: Uncomment when API supports size field -->
<!-- <span class="text-secondary">{{ formatBytes(backup.size) }}</span> --> <!-- <span class="font-normal text-secondary">{{ formatBytes(backup.size) }}</span> -->
</div> </div>
<div v-if="!preview" class="flex shrink-0 items-center gap-2 md:justify-self-end"> <!-- Right side actions -->
<ButtonStyled v-if="!activeOperation" color="brand" type="outlined"> <div v-if="!preview" class="flex w-[180px] shrink-0 items-center justify-end gap-2">
<button <ButtonStyled v-if="creating" type="outlined">
v-tooltip="props.restoreDisabled" <button @click="() => emit('delete', true)" class="!border !border-surface-4">
class="!border-[1px]" {{ formatMessage(commonMessages.cancelButton) }}
:disabled="!!props.restoreDisabled"
@click="() => emit('restore')"
>
<RotateCounterClockwiseIcon class="size-5" />
{{ formatMessage(messages.restore) }}
</button> </button>
</ButtonStyled> </ButtonStyled>
<ButtonStyled circular type="transparent"> <template v-else>
<OverflowMenu :options="overflowMenuOptions"> <ButtonStyled v-if="!activeOperation" color="brand" type="outlined">
<MoreVerticalIcon class="size-5" /> <button
<template #copy-id> v-tooltip="props.restoreDisabled"
<ClipboardCopyIcon class="size-5" /> class="!border"
{{ formatMessage(commonMessages.copyIdButton) }} :disabled="!!props.restoreDisabled"
</template> @click="() => emit('restore')"
<template #download> >
<DownloadIcon class="size-5" /> {{ formatMessage(commonMessages.downloadButton) }} <RotateCounterClockwiseIcon class="size-5" />
</template> {{ formatMessage(messages.restore) }}
<template #rename> </button>
<EditIcon class="size-5" /> {{ formatMessage(messages.rename) }} </ButtonStyled>
</template> <ButtonStyled circular type="transparent">
<template #delete> <OverflowMenu :options="overflowMenuOptions">
<TrashIcon class="size-5" /> {{ formatMessage(commonMessages.deleteLabel) }} <MoreVerticalIcon class="size-5" />
</template> <template #copy-id>
</OverflowMenu> <ClipboardCopyIcon class="size-5" />
</ButtonStyled> {{ formatMessage(commonMessages.copyIdButton) }}
</template>
<template #download>
<DownloadIcon class="size-5" /> {{ formatMessage(commonMessages.downloadButton) }}
</template>
<template #rename>
<EditIcon class="size-5" /> {{ formatMessage(messages.rename) }}
</template>
<template #delete>
<TrashIcon class="size-5" /> {{ formatMessage(commonMessages.deleteLabel) }}
</template>
</OverflowMenu>
</ButtonStyled>
</template>
</div> </div>
<pre v-if="!preview && showDebugInfo" class="w-full rounded-xl bg-surface-4 p-2 text-xs">{{ <pre v-if="!preview && showDebugInfo" class="w-full rounded-xl bg-surface-4 p-2 text-xs">{{
@@ -20,26 +20,28 @@
</span> </span>
</div> </div>
</div> </div>
<div class="mt-2 flex justify-start gap-2"> <template #actions>
<ButtonStyled color="brand"> <div class="flex gap-2 justify-end">
<button :disabled="renameMutation.isPending.value || nameExists" @click="renameBackup"> <ButtonStyled type="outlined">
<template v-if="renameMutation.isPending.value"> <button class="!border !border-surface-4" @click="hide">
<SpinnerIcon class="animate-spin" /> <XIcon />
Renaming... Cancel
</template> </button>
<template v-else> </ButtonStyled>
<SaveIcon /> <ButtonStyled color="brand">
Save changes <button :disabled="renameMutation.isPending.value || nameExists" @click="renameBackup">
</template> <template v-if="renameMutation.isPending.value">
</button> <SpinnerIcon class="animate-spin" />
</ButtonStyled> Renaming...
<ButtonStyled> </template>
<button @click="hide"> <template v-else>
<XIcon /> <SaveIcon />
Cancel Save changes
</button> </template>
</ButtonStyled> </button>
</div> </ButtonStyled>
</div>
</template>
</NewModal> </NewModal>
</template> </template>
@@ -17,8 +17,8 @@
<template #actions> <template #actions>
<div class="flex gap-2 justify-end"> <div class="flex gap-2 justify-end">
<ButtonStyled> <ButtonStyled type="outlined">
<button @click="modal?.hide()"> <button class="!border !border-surface-4" @click="modal?.hide()">
<XIcon /> <XIcon />
Cancel Cancel
</button> </button>
@@ -0,0 +1,167 @@
import type { Archon } from '@modrinth/api-client'
import type { Meta, StoryObj } from '@storybook/vue3-vite'
import BackupItem from '../../components/servers/backups/BackupItem.vue'
const meta = {
title: 'Servers/BackupItem',
component: BackupItem,
args: {
preview: false,
showCopyIdAction: false,
showDebugInfo: false,
restoreDisabled: undefined,
},
} satisfies Meta<typeof BackupItem>
export default meta
type Story = StoryObj<typeof meta>
function makeBackup(overrides: Partial<Archon.Backups.v1.Backup> = {}): Archon.Backups.v1.Backup {
return {
id: 'backup-001',
physical_id: 'phys-001',
name: 'Backup #5',
created_at: new Date(Date.now() - 1000 * 60 * 10).toISOString(),
automated: false,
status: 'done',
interrupted: false,
ongoing: false,
locked: false,
...overrides,
}
}
export const Default: Story = {
name: 'Default (manual)',
args: {
backup: makeBackup({ name: 'Base finished!!' }),
},
}
export const Automated: Story = {
name: 'Automated',
args: {
backup: makeBackup({ automated: true, name: 'Backup #2' }),
},
}
export const Creating: Story = {
name: 'Creating (in progress)',
args: {
backup: makeBackup({
automated: true,
name: 'Backup #3',
status: 'in_progress',
ongoing: true,
task: {
create: { progress: 0.4, state: 'ongoing' },
},
}),
},
}
export const Restoring: Story = {
name: 'Restoring (in progress)',
args: {
backup: makeBackup({
name: 'Backup #5',
automated: true,
task: {
restore: { progress: 0.6, state: 'ongoing' },
},
}),
},
}
export const FailedCreate: Story = {
name: 'Failed (create)',
args: {
backup: makeBackup({ status: 'error', name: 'Backup #4' }),
},
}
export const FailedRestore: Story = {
name: 'Failed (restore)',
args: {
backup: makeBackup({
name: 'Backup #5',
task: {
restore: { progress: 0, state: 'failed' },
},
}),
},
}
export const Preview: Story = {
name: 'Preview (compact, used in delete modal)',
args: {
backup: makeBackup({ name: 'Base finished!!' }),
preview: true,
},
}
export const RestoreDisabled: Story = {
name: 'Restore disabled (server running)',
args: {
backup: makeBackup({ name: 'Backup #5', automated: true }),
restoreDisabled: 'Cannot restore backup while server is running',
},
}
export const AllStates: Story = {
render: () => ({
components: { BackupItem },
setup() {
const now = new Date(Date.now() - 1000 * 60 * 10).toISOString()
function makeBackup(
overrides: Partial<Archon.Backups.v1.Backup>,
): Archon.Backups.v1.Backup {
return {
id: 'backup-001',
physical_id: 'phys-001',
name: 'Backup #5',
created_at: now,
automated: false,
status: 'done',
interrupted: false,
ongoing: false,
locked: false,
...overrides,
}
}
return {
manual: makeBackup({ name: 'Base finished!!' }),
automated: makeBackup({ automated: true, name: 'Backup #2' }),
creating: makeBackup({
automated: true,
name: 'Backup #3',
status: 'in_progress',
ongoing: true,
task: { create: { progress: 0.4, state: 'ongoing' } },
}),
restoring: makeBackup({
automated: true,
task: { restore: { progress: 0.6, state: 'ongoing' } },
}),
failedCreate: makeBackup({ status: 'error', name: 'Backup #4' }),
failedRestore: makeBackup({
task: { restore: { progress: 0, state: 'failed' } },
}),
}
},
template: /* html */ `
<div style="display: flex; flex-direction: column; gap: 0.75rem; max-width: 900px;">
<BackupItem :backup="manual" />
<BackupItem :backup="automated" />
<BackupItem :backup="creating" />
<BackupItem :backup="restoring" />
<BackupItem :backup="failedCreate" />
<BackupItem :backup="failedRestore" />
<BackupItem :backup="manual" preview />
</div>
`,
}),
}