diff --git a/dev-dist/sw.js b/dev-dist/sw.js index 1d769f7..acaa371 100644 --- a/dev-dist/sw.js +++ b/dev-dist/sw.js @@ -82,7 +82,7 @@ define(['./workbox-b5f7729d'], (function (workbox) { 'use strict'; "revision": "3ca0b8505b4bec776b69afdba2768812" }, { "url": "index.html", - "revision": "0.4srjfhmcce8" + "revision": "0.iuiv74udim" }], {}); workbox.cleanupOutdatedCaches(); workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), { diff --git a/src/composables/graph/setGraph.ts b/src/composables/graph/setGraph.ts index fb2f741..a4fafb1 100644 --- a/src/composables/graph/setGraph.ts +++ b/src/composables/graph/setGraph.ts @@ -1,15 +1,24 @@ import { onMounted, reactive } from 'vue'; -import { useGraphStore } from '@/stores/graph/graph'; +import { useGraphStore, usePublicationStore } from '@/stores'; import { generateGraphFromArticles } from '@/utils' -import { articles } from '../../../mock'; +import { publications } from '../../../mock'; export function useSetGraph() { const { setGraphData } = useGraphStore(); - const { edges, nodes } = generateGraphFromArticles(articles) + const { edges, nodes } = generateGraphFromArticles(publications) + + const { populatePublications } = usePublicationStore() const currentConnections = reactive({ nodes, edges }); - onMounted(() => setGraphData(nodes, edges)); + + onMounted(() => { + populatePublications() + setGraphData(nodes, edges) + } + + ) + return { currentConnections }; } \ No newline at end of file diff --git a/src/stores/index.ts b/src/stores/index.ts index c3157ab..90b9884 100644 --- a/src/stores/index.ts +++ b/src/stores/index.ts @@ -4,5 +4,6 @@ import { useEdgeStore } from "./graph/edge"; import { useAuthStore } from "./auth/auth"; import { useEventStore } from "./event/event"; import { useTemplateStore } from "./template/template"; +import { usePublicationStore } from "./publication/publication"; -export { useGraphStore, useAuthStore, useTemplateStore, useEdgeStore, useNodeStore, useEventStore }; +export { useGraphStore, useAuthStore, useTemplateStore, useEdgeStore, useNodeStore, useEventStore, usePublicationStore }; diff --git a/src/stores/publication/publication.ts b/src/stores/publication/publication.ts index 167f2a2..dddc8e5 100644 --- a/src/stores/publication/publication.ts +++ b/src/stores/publication/publication.ts @@ -2,11 +2,9 @@ import { ref } from 'vue' import { defineStore } from 'pinia' import { PublicationService, AuthorService, CategoryService, KeywordService } from '@/services'; +import type { IPublication, IAuthor, ICategory, IKeyword } from '@/interfaces' -import type { IPublication, IAuthor } from '@/interfaces' - -export const usePublicationStore = defineStore('template', () => { - +export const usePublicationStore = defineStore('publication', () => { const entirePublications = ref([]) const publications = ref([]) const publication = ref(null) @@ -23,22 +21,54 @@ export const usePublicationStore = defineStore('template', () => { for (let i = 0; i < publications.value.length; i++) { const currentPublication = publications.value[i]; - for (let j = 0; j < currentPublication.authors.length; j++) { - const currentAuthor = currentPublication.authors[j] - const author = await authorService.getAuthorById(currentAuthor.id) + const authors: IAuthor[] = await Promise.all( + currentPublication.authors.map(async (authorId) => { + const author = await authorService.getAuthorById(Number(authorId)); + if (author) { + return author; + } + throw new Error(`Author not found: ${authorId}`); + }) + ) - } + const categories: ICategory[] = await Promise.all( + currentPublication.categories.map(async (categoryId) => { + const category = await categoryService.getCategoryById(Number(categoryId)); + if (category) { + return category; + } + throw new Error(`Category not found: ${categoryId}`); + }) + ) - } + const keywords: IKeyword[] = await Promise.all( + currentPublication.keywords.map(async (keywordId) => { + const keyword = await keywordService.getKeywordById(Number(keywordId)); + if (keyword) { + return keyword; + } + throw new Error(`Keyword not found: ${keywordId}`); + }) + ) + const fullPublication: IPublication = { + ...currentPublication, + authors: authors, + categories: categories, + keywords: keywords + } + entirePublications.value.push(fullPublication) + } } catch (error) { - console.log(error); - + console.log(error) } } - return { - + return { + entirePublications, + publications, + publication, + populatePublications } })