Skip to content

Commit

Permalink
CHORE: Mod composable for graph generator #44
Browse files Browse the repository at this point in the history
  • Loading branch information
Caussz committed Jul 19, 2024
1 parent e80275c commit 3c1728c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 19 deletions.
2 changes: 1 addition & 1 deletion dev-dist/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"), {
Expand Down
17 changes: 13 additions & 4 deletions src/composables/graph/setGraph.ts
Original file line number Diff line number Diff line change
@@ -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 };
}
3 changes: 2 additions & 1 deletion src/stores/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
56 changes: 43 additions & 13 deletions src/stores/publication/publication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IPublication[]>([])
const publications = ref<IPublication[]>([])
const publication = ref<IPublication | null>(null)
Expand All @@ -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
}
})

0 comments on commit 3c1728c

Please sign in to comment.