diff --git a/CHANGELOG.md b/CHANGELOG.md index 75e1f4c..79a0541 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,10 @@ As this project is a user-facing application, the places in the semantic version - Extracted the concept of a Resource as a supertype of Corpus, in preparation for adding the Metadata resource type [#145](https://github.com/spraakbanken/mink-frontend/issues/145) - Source text file content now look the same as log output +### Fixed + +- Missing `type` in store caused new corpus form to crash + ## [1.3.0] (2024-02-12) ### Added diff --git a/src/corpus/createCorpus.composable.ts b/src/corpus/createCorpus.composable.ts index 9a486b5..bbe24ad 100644 --- a/src/corpus/createCorpus.composable.ts +++ b/src/corpus/createCorpus.composable.ts @@ -25,7 +25,8 @@ export default function useCreateCorpus() { const corpusId = await mink.createCorpus().catch(alertError); if (!corpusId) return undefined; - return await addNewResource(corpusId); + await addNewResource("corpus", corpusId); + return corpusId; } async function createFromUpload(files: FileList) { diff --git a/src/metadata/CreateMetadata.vue b/src/metadata/CreateMetadata.vue index 8994707..dbb48b1 100644 --- a/src/metadata/CreateMetadata.vue +++ b/src/metadata/CreateMetadata.vue @@ -26,7 +26,7 @@ async function submit(fields: Form) { .catch(alertError); if (!resourceId) return; - await addNewResource(resourceId); + await addNewResource("metadata", resourceId); router.push(`/library/metadata/${resourceId}`); } diff --git a/src/resource/createResource.composable.ts b/src/resource/createResource.composable.ts index 8f91274..9c539f7 100644 --- a/src/resource/createResource.composable.ts +++ b/src/resource/createResource.composable.ts @@ -1,3 +1,4 @@ +import type { ResourceType } from "@/api/api.types"; import { useAuth } from "@/auth/auth.composable"; import { useResourceStore } from "@/store/resource.store"; @@ -5,15 +6,19 @@ export default function useCreateResource() { const { refreshJwt } = useAuth(); const resourceStore = useResourceStore(); - async function addNewResource(resourceId: string) { + /** + * Register a newly created resource. + * @param type The type is necessary for the store's filter getters to include the new object. + * @param resourceId The resource id. + */ + async function addNewResource(type: ResourceType, resourceId: string) { // Have the new corpus included in further API calls. await refreshJwt(); // Adding the new id to store may trigger API calls, so do it after updating the JWT. - resourceStore.resources[resourceId] = - resourceStore.resources[resourceId] || {}; - - return resourceId; + if (!(resourceId in resourceStore.resources)) { + resourceStore.resources[resourceId] = { type }; + } } return {