Skip to content

Commit 65bbd01

Browse files
committed
WIP: Deleting assets, UI only, also not wired up
1 parent 860fd36 commit 65bbd01

File tree

8 files changed

+139
-13
lines changed

8 files changed

+139
-13
lines changed

src/components/dialog/GlobalDialog.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<component
1515
:is="item.headerComponent"
1616
v-if="item.headerComponent"
17+
v-bind="item.headerProps"
1718
:id="item.key"
1819
/>
1920
<h3 v-else :id="item.key">
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<template>
2+
<div
3+
class="flex flex-col px-4 py-2 text-sm text-muted-foreground border-t border-border-default"
4+
>
5+
<p v-if="confirmationText">
6+
{{ confirmationText }}
7+
</p>
8+
</div>
9+
</template>
10+
<script setup lang="ts">
11+
defineProps<{
12+
confirmationText?: string
13+
}>()
14+
</script>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<template>
2+
<section class="w-full flex gap-2 justify-end px-2 pb-2">
3+
<TextButton
4+
:label="cancelTextX"
5+
type="transparent"
6+
autofocus
7+
@click="$emit('cancel')"
8+
/>
9+
<TextButton
10+
:label="confirmTextX"
11+
type="transparent"
12+
:class="confirmClass"
13+
@click="$emit('confirm')"
14+
/>
15+
</section>
16+
</template>
17+
<script setup lang="ts">
18+
import { computed } from 'vue'
19+
import { useI18n } from 'vue-i18n'
20+
21+
import TextButton from '@/components/button/TextButton.vue'
22+
23+
const { t } = useI18n()
24+
25+
const { cancelText, confirmText, confirmClass } = defineProps<{
26+
cancelText?: string
27+
confirmText?: string
28+
confirmClass?: string
29+
}>()
30+
31+
defineEmits<{
32+
cancel: []
33+
confirm: []
34+
}>()
35+
36+
const confirmTextX = computed(() => confirmText || t('g.confirm'))
37+
const cancelTextX = computed(() => cancelText || t('g.cancel'))
38+
</script>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<template>
2+
<div
3+
class="flex items-center gap-2 p-4 font-bold text-sm text-base-foreground font-inter"
4+
>
5+
<span v-if="title" class="flex-auto">{{ title }}</span>
6+
</div>
7+
</template>
8+
<script setup lang="ts">
9+
defineProps<{
10+
title?: string
11+
}>()
12+
</script>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import ConfirmBody from '@/components/dialog/confirm/ConfirmBody.vue'
2+
import ConfirmFooter from '@/components/dialog/confirm/ConfirmFooter.vue'
3+
import ConfirmHeader from '@/components/dialog/confirm/ConfirmHeader.vue'
4+
import { useDialogStore } from '@/stores/dialogStore'
5+
import type { ComponentAttrs } from 'vue-component-type-helpers'
6+
7+
interface ConfirmDialogOptions {
8+
headerProps?: ComponentAttrs<typeof ConfirmHeader>
9+
props?: ComponentAttrs<typeof ConfirmBody>
10+
footerProps?: ComponentAttrs<typeof ConfirmFooter>
11+
}
12+
13+
export function showConfirmDialog(options: ConfirmDialogOptions = {}) {
14+
const dialogStore = useDialogStore()
15+
const { headerProps, props, footerProps } = options
16+
return dialogStore.showDialog({
17+
headerComponent: ConfirmHeader,
18+
component: ConfirmBody,
19+
footerComponent: ConfirmFooter,
20+
headerProps,
21+
props,
22+
footerProps,
23+
dialogComponentProps: {
24+
pt: {
25+
header: 'py-0! px-0!',
26+
content: 'p-0!',
27+
footer: 'p-0!'
28+
}
29+
}
30+
})
31+
}

src/platform/assets/components/AssetCard.vue

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@
5454
<i class="icon-[lucide--pencil]" />
5555
</template>
5656
</IconTextButton>
57-
<IconTextButton :label="$t('g.delete')" type="secondary" size="md">
57+
<IconTextButton
58+
:label="$t('g.delete')"
59+
type="secondary"
60+
size="md"
61+
@click="confirmDeletion"
62+
>
5863
<template #icon>
5964
<i class="icon-[lucide--trash-2]" />
6065
</template>
@@ -120,9 +125,11 @@ import IconGroup from '@/components/button/IconGroup.vue'
120125
import IconTextButton from '@/components/button/IconTextButton.vue'
121126
import MoreButton from '@/components/button/MoreButton.vue'
122127
import EditableText from '@/components/common/EditableText.vue'
128+
import { showConfirmDialog } from '@/components/dialog/confirm/confirmDialog'
123129
import AssetBadgeGroup from '@/platform/assets/components/AssetBadgeGroup.vue'
124130
import type { AssetDisplayItem } from '@/platform/assets/composables/useAssetBrowser'
125131
import { useSettingStore } from '@/platform/settings/settingStore'
132+
import { useDialogStore } from '@/stores/dialogStore'
126133
import { cn } from '@/utils/tailwindUtil'
127134
128135
const { asset, interactive } = defineProps<{
@@ -135,6 +142,7 @@ defineEmits<{
135142
}>()
136143
137144
const settingStore = useSettingStore()
145+
const { closeDialog } = useDialogStore()
138146
139147
const dropdownMenuButton = useTemplateRef<InstanceType<typeof MoreButton>>(
140148
'dropdown-menu-button'
@@ -155,6 +163,32 @@ const { isLoading, error } = useImage({
155163
alt: asset.name
156164
})
157165
166+
async function confirmDeletion() {
167+
dropdownMenuButton.value?.hide()
168+
const confirmDialog = showConfirmDialog({
169+
headerProps: {
170+
title: 'Delete this model?'
171+
},
172+
props: {
173+
confirmationText:
174+
'This model will be permanently removed from your library.'
175+
},
176+
footerProps: {
177+
confirmText: 'Delete',
178+
// TODO: These need to be put into the new Button Variants once we have them.
179+
confirmClass: cn(
180+
'bg-danger-200 text-base-foreground hover:bg-danger-200/80 focus:bg-danger-200/80 focus:ring ring-base-foreground'
181+
),
182+
onCancel: () => {
183+
closeDialog(confirmDialog)
184+
},
185+
onConfirm: () => {
186+
closeDialog(confirmDialog)
187+
}
188+
}
189+
})
190+
}
191+
158192
function startAssetRename() {
159193
dropdownMenuButton.value?.hide()
160194
isEditing.value = true

src/platform/assets/components/UploadModelDialog.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div
3-
class="upload-model-dialog flex flex-col justify-between gap-6 p-4 pt-6 border-t-[1px] border-border-default"
3+
class="upload-model-dialog flex flex-col justify-between gap-6 p-4 pt-6 border-t border-border-default"
44
>
55
<!-- Step 1: Enter URL -->
66
<UploadModelUrlInput

src/stores/dialogStore.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ interface DialogInstance<
4646
visible: boolean
4747
title?: string
4848
headerComponent?: H
49+
headerProps?: ComponentAttrs<H>
4950
component: B
5051
contentProps: ComponentAttrs<B>
5152
footerComponent?: F
@@ -133,17 +134,11 @@ export const useDialogStore = defineStore('dialog', () => {
133134
updateCloseOnEscapeStates()
134135
}
135136

136-
function createDialog(options: {
137-
key: string
138-
title?: string
139-
headerComponent?: Component
140-
footerComponent?: Component
141-
component: Component
142-
props?: Record<string, any>
143-
footerProps?: Record<string, any>
144-
dialogComponentProps?: DialogComponentProps
145-
priority?: number
146-
}) {
137+
function createDialog<
138+
H extends Component = Component,
139+
B extends Component = Component,
140+
F extends Component = Component
141+
>(options: ShowDialogOptions<H, B, F> & { key: string }) {
147142
if (dialogStack.value.length >= 10) {
148143
dialogStack.value.shift()
149144
}
@@ -159,6 +154,7 @@ export const useDialogStore = defineStore('dialog', () => {
159154
? markRaw(options.footerComponent)
160155
: undefined,
161156
component: markRaw(options.component),
157+
headerProps: { ...options.headerProps },
162158
contentProps: { ...options.props },
163159
footerProps: { ...options.footerProps },
164160
priority: options.priority ?? 1,

0 commit comments

Comments
 (0)