diff --git a/apps/front/src/stores/page.ts b/apps/front/src/stores/page.ts new file mode 100644 index 0000000..7feebd0 --- /dev/null +++ b/apps/front/src/stores/page.ts @@ -0,0 +1,41 @@ +import { getPage, Page } from '@portfolio/api-client'; +import { defineStore } from 'pinia'; + +export interface PageState { + pageLoading: boolean; + loadingError?: string; + page?: Page; + pagePath: string; +} + +export const usePageStore = defineStore({ + id: 'page', + state: (): PageState => ({ + pageLoading: false, + pagePath: '', + }), + actions: { + fetchPage(path: string) { + if (this.pageLoading) return; + this.pageLoading = true; + if (this.pagePath === path) { + this.pageLoading = false; + return; + } + getPage({ query: { info: { path } } }) + .then((body) => { + if (body.status === 200) { + this.page = body.data; + this.pagePath = path; + } + }) + .catch((err) => { + console.error(err); + this.loadingError = 'Failed to load page'; + }) + .finally(() => { + this.pageLoading = false; + }); + }, + }, +}); diff --git a/apps/front/src/views/DocView.vue b/apps/front/src/views/DocView.vue index 9224a45..254b29d 100644 --- a/apps/front/src/views/DocView.vue +++ b/apps/front/src/views/DocView.vue @@ -1,6 +1,12 @@ \ No newline at end of file + + + \ No newline at end of file diff --git a/apps/front/tsconfig.json b/apps/front/tsconfig.json index c7f95da..e7b4430 100644 --- a/apps/front/tsconfig.json +++ b/apps/front/tsconfig.json @@ -18,5 +18,6 @@ "path": "./tsconfig.spec.json" } ], - "extends": "../../tsconfig.base.json" + "extends": "../../tsconfig.base.json", + "composite": true }