feat: connect admin image workflow
Quality / test (push) Canceled after 0s

This commit is contained in:
2026-09-08 22:16:59 -04:00
parent c382852924
commit a21d1ae854
9 changed files with 120 additions and 0 deletions
@@ -0,0 +1,50 @@
import { ref } from 'vue';
import {
deleteImage,
listAdminImages,
reorderImage,
retryImageProcessing,
setPrimaryImage,
updateImageAltText,
} from '@/services/admin-image-service.js';
function csrfToken() {
return document.cookie.split('; ').find((value) => value.startsWith('pokemon_inventory_csrf='))?.split('=')[1] ?? '';
}
export function useAdminImages(inventoryItemId) {
const images = ref([]);
const isLoading = ref(false);
const isSaving = ref(false);
const error = ref(null);
async function load() {
isLoading.value = true;
error.value = null;
try { images.value = await listAdminImages(inventoryItemId); }
catch (requestError) { error.value = requestError; }
finally { isLoading.value = false; }
}
async function apply(action) {
isSaving.value = true;
error.value = null;
try { await action(csrfToken()); await load(); }
catch (requestError) { error.value = requestError; }
finally { isSaving.value = false; }
}
return {
images,
isLoading,
isSaving,
error,
load,
reorder: (imageId, sortOrder) => apply((token) => reorderImage(imageId, sortOrder, token)),
setPrimary: (imageId) => apply((token) => setPrimaryImage(imageId, token)),
updateAltText: (imageId, altText) => apply((token) => updateImageAltText(imageId, altText, token)),
retry: (imageId) => apply((token) => retryImageProcessing(imageId, token)),
remove: (imageId) => apply((token) => deleteImage(imageId, token)),
};
}