-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from IT4Change/boilerplate-function-layout
feat(frontend): boilerplate function & layout
- Loading branch information
Showing
32 changed files
with
352 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# META | ||
PUBLIC_ENV__META__DEFAULT_TITLE="IT4C" | ||
PUBLIC_ENV__META__DEFAULT_DESCRIPTION="IT4C Frontend Boilerplate" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ coverage/ | |
!.vuepress/ | ||
.vuepress/.temp/ | ||
.vuepress/.cache/ | ||
build-storybook.log | ||
build-storybook.log | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,30 @@ | ||
import { createApp } from './app' | ||
|
||
import type { PageContextClient } from '#types/PageContext' | ||
import type { PageContext, VikePageContext } from '#types/PageContext' | ||
|
||
// This render() hook only supports SSR, see https://vike.dev/render-modes for how to modify render() to support SPA | ||
async function render(pageContext: PageContextClient) { | ||
const { Page, pageProps } = pageContext | ||
if (!Page) throw new Error('Client-side render() hook expects pageContext.Page to be defined') | ||
const app = createApp(Page, pageProps, pageContext) | ||
app.mount('#app') | ||
let app: ReturnType<typeof createApp> | ||
async function render(pageContext: VikePageContext & PageContext) { | ||
if (!app) { | ||
app = createApp(pageContext) | ||
app.mount('#app') | ||
} else { | ||
app.changePage(pageContext) | ||
} | ||
} | ||
|
||
/* To enable Client-side Routing: | ||
export const clientRouting = true | ||
// !! WARNING !! Before doing so, read https://vike.dev/clientRouting */ | ||
function onHydrationEnd() { | ||
// console.log('Hydration finished; page is now interactive.') | ||
} | ||
function onPageTransitionStart() { | ||
// console.log('Page transition start') | ||
} | ||
function onPageTransitionEnd() { | ||
// console.log('Page transition end') | ||
} | ||
|
||
export const clientRouting = true | ||
export const prefetchStaticAssets = 'viewport' | ||
export { render } | ||
export { onHydrationEnd } | ||
export { onPageTransitionStart } | ||
export { onPageTransitionEnd } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,75 @@ | ||
import { createSSRApp, defineComponent, h } from 'vue' | ||
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate' | ||
import { createSSRApp, defineComponent, h, markRaw, reactive } from 'vue' | ||
|
||
import PageShell from '#components/PageShell.vue' | ||
import { setPageContext } from '#context/usePageContext' | ||
import i18n from '#plugins/i18n' | ||
import pinia from '#plugins/pinia' | ||
import CreateVuetify from '#plugins/vuetify' | ||
import { Page } from '#types/Page' | ||
import { PageProps } from '#types/PageProps' | ||
|
||
import type { PageContext } from '#types/PageContext' | ||
import type { Component } from '#types/Component' | ||
import type { PageContext, VikePageContext } from '#types/PageContext' | ||
|
||
function createApp(Page: Page, pageProps: PageProps | undefined, pageContext: PageContext) { | ||
const PageWithLayout = defineComponent({ | ||
const vuetify = CreateVuetify(i18n) | ||
|
||
function createApp(pageContext: VikePageContext & PageContext, isClient = true) { | ||
let rootComponent: Component | ||
const PageWithWrapper = defineComponent({ | ||
data: () => ({ | ||
Page: markRaw(pageContext.Page), | ||
pageProps: markRaw(pageContext.pageProps || {}), | ||
isClient, | ||
}), | ||
created() { | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
rootComponent = this | ||
}, | ||
render() { | ||
return h( | ||
PageShell, | ||
{}, | ||
{ | ||
default() { | ||
return h(Page, pageProps || {}) | ||
default: () => { | ||
return h(this.Page, this.pageProps) | ||
}, | ||
}, | ||
) | ||
}, | ||
}) | ||
|
||
const app = createSSRApp(PageWithLayout) | ||
if (isClient) { | ||
pinia.use(piniaPluginPersistedstate) | ||
} | ||
|
||
const app = createSSRApp(PageWithWrapper) | ||
app.use(pinia) | ||
app.use(i18n) | ||
app.use(CreateVuetify(i18n)) | ||
app.use(vuetify) | ||
|
||
objectAssign(app, { | ||
changePage: (pageContext: VikePageContext & PageContext) => { | ||
Object.assign(pageContextReactive, pageContext) | ||
rootComponent.Page = markRaw(pageContext.Page) | ||
rootComponent.pageProps = markRaw(pageContext.pageProps || {}) | ||
}, | ||
}) | ||
|
||
// When doing Client Routing, we mutate pageContext (see usage of `app.changePage()` in `_default.page.client.js`). | ||
// We therefore use a reactive pageContext. | ||
const pageContextReactive = reactive(pageContext) | ||
|
||
// Make pageContext available from any Vue component | ||
setPageContext(app, pageContext) | ||
setPageContext(app, pageContextReactive) | ||
|
||
return app | ||
} | ||
|
||
// Same as `Object.assign()` but with type inference | ||
function objectAssign<Obj extends object, ObjAddendum>( | ||
obj: Obj, | ||
objAddendum: ObjAddendum, | ||
): asserts obj is Obj & ObjAddendum { | ||
Object.assign(obj, objAddendum) | ||
} | ||
|
||
export { createApp } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { createPinia } from 'pinia' | ||
|
||
export default createPinia() | ||
const pinia = createPinia() | ||
export default pinia |
2 changes: 1 addition & 1 deletion
2
src/components/ClickCounter.test.ts → src/components/ClickCounter.delete.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<template> | ||
<template v-if="isMounted"><slot /></template> | ||
<template v-else><slot name="placeholder" /></template> | ||
</template> | ||
|
||
<script setup> | ||
import { ref, onMounted } from 'vue' | ||
const isMounted = ref(false) | ||
onMounted(() => { | ||
isMounted.value = true | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,5 @@ | ||
<template> | ||
<v-app> | ||
<v-container> | ||
<div class="layout"> | ||
<div class="navigation"> | ||
<a href="/" class="logo"> | ||
<img :src="Logo" height="64" width="64" alt="logo" /> | ||
</a> | ||
<VikeLink href="/">Home</VikeLink> | ||
<VikeLink href="/about">About</VikeLink> | ||
</div> | ||
<div class="content"><slot /></div> | ||
</div> | ||
</v-container> | ||
<slot /> | ||
</v-app> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import Logo from '#assets/it4c-logo2-clean-bg_alpha-128x128.png' | ||
import VikeLink from './VikeLink.vue' | ||
</script> | ||
|
||
<style> | ||
body { | ||
margin: 0; | ||
font-family: sans-serif; | ||
} | ||
* { | ||
box-sizing: border-box; | ||
} | ||
a { | ||
text-decoration: none; | ||
} | ||
</style> | ||
|
||
<style scoped> | ||
.layout { | ||
display: flex; | ||
max-width: 900px; | ||
margin: auto; | ||
} | ||
.content { | ||
min-height: 100vh; | ||
padding: 20px; | ||
padding-bottom: 50px; | ||
border-left: 2px solid #eee; | ||
} | ||
.navigation { | ||
display: flex; | ||
flex-direction: column; | ||
flex-shrink: 0; | ||
align-items: center; | ||
padding: 20px; | ||
line-height: 1.8em; | ||
} | ||
.logo { | ||
margin-top: 20px; | ||
margin-bottom: 10px; | ||
} | ||
</style> |
Oops, something went wrong.