Skip to content

Commit 085323e

Browse files
committed
WIP: Real API calls
1 parent 5fdbfa7 commit 085323e

File tree

3 files changed

+46
-8
lines changed

3 files changed

+46
-8
lines changed

src/components/dialog/confirm/ConfirmBody.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
<div
33
class="flex flex-col px-4 py-2 text-sm text-muted-foreground border-t border-border-default"
44
>
5-
<p v-if="confirmationText">
6-
{{ confirmationText }}
5+
<p v-if="promptText">
6+
{{ promptText }}
77
</p>
88
</div>
99
</template>
1010
<script setup lang="ts">
11+
import type { MaybeRefOrGetter } from 'vue'
12+
1113
defineProps<{
12-
confirmationText?: string
14+
promptText?: MaybeRefOrGetter<string>
1315
}>()
1416
</script>

src/platform/assets/components/AssetCard.vue

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ import EditableText from '@/components/common/EditableText.vue'
128128
import { showConfirmDialog } from '@/components/dialog/confirm/confirmDialog'
129129
import AssetBadgeGroup from '@/platform/assets/components/AssetBadgeGroup.vue'
130130
import type { AssetDisplayItem } from '@/platform/assets/composables/useAssetBrowser'
131+
import { assetService } from '@/platform/assets/services/assetService'
131132
import { useSettingStore } from '@/platform/settings/settingStore'
132133
import { useDialogStore } from '@/stores/dialogStore'
133134
import { cn } from '@/utils/tailwindUtil'
@@ -163,15 +164,14 @@ const { isLoading, error } = useImage({
163164
alt: asset.name
164165
})
165166
166-
async function confirmDeletion() {
167+
function confirmDeletion() {
167168
dropdownMenuButton.value?.hide()
168169
const confirmDialog = showConfirmDialog({
169170
headerProps: {
170171
title: 'Delete this model?'
171172
},
172173
props: {
173-
confirmationText:
174-
'This model will be permanently removed from your library.'
174+
promptText: 'This model will be permanently removed from your library.'
175175
},
176176
footerProps: {
177177
confirmText: 'Delete',
@@ -182,7 +182,13 @@ async function confirmDeletion() {
182182
onCancel: () => {
183183
closeDialog(confirmDialog)
184184
},
185-
onConfirm: () => {
185+
onConfirm: async () => {
186+
try {
187+
await assetService.deleteAsset(asset.id)
188+
// TODO: Remove this from the list on success.
189+
} catch (err: unknown) {
190+
console.error(err)
191+
}
186192
closeDialog(confirmDialog)
187193
}
188194
}
@@ -194,9 +200,12 @@ function startAssetRename() {
194200
isEditing.value = true
195201
}
196202
197-
function assetRename(newName?: string) {
203+
async function assetRename(newName?: string) {
198204
isEditing.value = false
199205
if (newName) {
206+
await assetService.updateAsset(asset.id, {
207+
name: newName
208+
})
200209
newNameRef.value = newName
201210
}
202211
}

src/platform/assets/services/assetService.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,32 @@ function createAssetService() {
281281
}
282282
}
283283

284+
/**
285+
* Updae metadata of an asset by ID
286+
* Only available in cloud environment
287+
*
288+
* @param id - The asset ID (UUID)
289+
* @param newData - The data to update
290+
* @returns Promise<void>
291+
* @throws Error if update fails
292+
*/
293+
async function updateAsset(
294+
id: string,
295+
newData: Partial<AssetMetadata>
296+
): Promise<string> {
297+
const res = await api.fetchApi(`${ASSETS_ENDPOINT}/${id}`, {
298+
method: 'PUT',
299+
body: JSON.stringify(newData)
300+
})
301+
302+
if (!res.ok) {
303+
throw new Error(
304+
`Unable to update asset ${id}: Server returned ${res.status}`
305+
)
306+
}
307+
return res.json()
308+
}
309+
284310
/**
285311
* Retrieves metadata from a download URL without downloading the file
286312
*
@@ -360,6 +386,7 @@ function createAssetService() {
360386
getAssetDetails,
361387
getAssetsByTag,
362388
deleteAsset,
389+
updateAsset,
363390
getAssetMetadata,
364391
uploadAssetFromUrl
365392
}

0 commit comments

Comments
 (0)