Skip to content

Commit

Permalink
feat: Make DocView reactive on page change load the new page
Browse files Browse the repository at this point in the history
  • Loading branch information
batleforc committed Sep 1, 2024
1 parent 7112625 commit 5a25de3
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 13 deletions.
14 changes: 14 additions & 0 deletions apps/front/src/component/Page/PageRender.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script setup lang="ts">
import { Page } from '@portfolio/api-client';
const props = defineProps<{
page: Page;
}>();
</script>

<template>
<div>
<h1>{{ page.name }}</h1>
<p>{{ page.content }}</p>
</div>
</template>
15 changes: 14 additions & 1 deletion apps/front/src/styles/DocView.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
@import "../var.scss";

.docContainer {
@apply flex grow h-full absolute top-0 w-full pt-16;
flex: 1 0 auto;
}

.docContent {
@apply grow overflow-y-scroll p-2 h-full;
@apply grow overflow-y-scroll h-full;
}

.docFooter {
@apply flex justify-center items-center h-16 w-full hidden;
background-color: $color-bgCover;
color: $color-textCover;
}

.docRealContent{
@apply p-2 ;

}
9 changes: 4 additions & 5 deletions apps/front/src/views/DocHomeView.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import DocSidebar from '../component/Doc/DocSidebar.vue';
import PageRender from '../component/Page/PageRender.vue';
import { useDocStore } from '../stores/doc';
import { usePageStore } from '../stores/page';
Expand All @@ -21,16 +22,14 @@ if (docStore.inited && docStore.docContent.has_index && pageStore.pageLoading ==
<div id="title" class="docContainer" v-if="docStore.inited">
<DocSidebar />
<div class="docContent">
<div v-if="docStore.docContent.has_index && pageStore.page !== undefined">
<h1>Doc home page</h1>
<p>{{ pageStore.page.metadata }}</p>
<div v-html="pageStore.page.content"></div>
<div class="docRealContent" v-if="docStore.docContent.has_index && pageStore.page !== undefined">
<PageRender :page="pageStore.page" />
</div>
<div v-if="!docStore.docContent.has_index">
<h1>Doc home page</h1>
<p>There is no index page for this documentation</p>
</div>
<footer>
<footer class="docFooter">
<p>Made with love and too much coffee @Batleforc - {{ new Date().getFullYear() }}</p>
</footer>
</div>
Expand Down
29 changes: 22 additions & 7 deletions apps/front/src/views/DocView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,45 @@
import { useRoute } from 'vue-router';
import { useDocStore } from '../stores/doc';
import DocSidebar from '../component/Doc/DocSidebar.vue';
import { computed } from 'vue';
import { computed, watch } from 'vue';
import { usePageStore } from '../stores/page';
import PageRender from '../component/Page/PageRender.vue';
const route = useRoute();
let pathReactive = computed(() => {
return Array.isArray(route.params.page) ? route.params.page : [route.params.page];
return (Array.isArray(route.params.page) ? route.params.page : [route.params.page]).join('/');
});
const docStore = useDocStore();
const pageStore = usePageStore();
if (!docStore.inited && !docStore.docLoading) {
docStore.init();
docStore.init()
}
if (pageStore.pageLoading === false && pageStore.pagePath !== pathReactive.value) {
pageStore.fetchPage(pathReactive.value);
}
watch(pathReactive, (newVal) => {
if (pageStore.pageLoading === false && pageStore.pagePath !== newVal) {
pageStore.fetchPage(newVal);
}
});
</script>

<template>
<div id="title" class="docContainer" v-if="docStore.inited">
<DocSidebar />
<div class="docContent">
<p>{{ pathReactive }}</p>
<p>Doc content</p>
<p v-for="truc in [...Array(100).keys()]" :key="truc">{{ truc }}</p>
<footer>
<div class="docRealContent" v-if="pageStore.page !== undefined">
<PageRender :page="pageStore.page" />
</div>
<div v-if="!pageStore.pageLoading && pageStore.page === undefined">
<h1>Doc home page</h1>
<p>There is no index page for this documentation</p>
</div>
<footer class="docFooter">
<p>Made with love and too much coffee @Batleforc - {{ new Date().getFullYear() }}</p>
</footer>
</div>
Expand Down

0 comments on commit 5a25de3

Please sign in to comment.