Skip to content

Commit

Permalink
feat: init page store
Browse files Browse the repository at this point in the history
  • Loading branch information
batleforc committed Aug 25, 2024
1 parent 0463b01 commit d41659b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 6 deletions.
41 changes: 41 additions & 0 deletions apps/front/src/stores/page.ts
Original file line number Diff line number Diff line change
@@ -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;
});
},
},
});
29 changes: 24 additions & 5 deletions apps/front/src/views/DocView.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<script setup lang="ts">
import { useRoute } from 'vue-router';
import { useDocStore } from '../stores/doc';
const route = useRoute();
let path = Array.isArray(route.params.page) ? route.params.page.join("/") : route.params.page;
const docStore = useDocStore();
if (!docStore.inited && !docStore.docLoading) {
docStore.init();
Expand All @@ -9,13 +15,26 @@ if (!docStore.inited && !docStore.docLoading) {
</script>

<template>
<div id="title" class="container" v-if="docStore.inited">
<h1>Doc sub page</h1>
<p>{{ $route.params.page.join("/") }}</p>
<div>
<div id="title" class="docContainer" v-if="docStore.inited">
<div class="docSidebar">
<p>Doc Sidebar</p>
<p v-for="sidebar in docStore.docContent.sub_categories" :key="sidebar.name">
{{ sidebar.name }}
</p>
</div>
<div class="docContent">
<p>{{ path }}</p>
<p>Doc content</p>
</div>
</div>
</template>
</template>

<style lang="scss">
.docContainer {
@apply flex;
}
.docContent {
@apply grow;
}
</style>
3 changes: 2 additions & 1 deletion apps/front/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"path": "./tsconfig.spec.json"
}
],
"extends": "../../tsconfig.base.json"
"extends": "../../tsconfig.base.json",
"composite": true
}

0 comments on commit d41659b

Please sign in to comment.