Skip to content

Commit

Permalink
build(webapp): migrate to Vike v1 API
Browse files Browse the repository at this point in the history
  • Loading branch information
JoosepAlviste committed Feb 17, 2024
1 parent 9c2e8e3 commit e0188ec
Show file tree
Hide file tree
Showing 30 changed files with 80 additions and 61 deletions.
5 changes: 5 additions & 0 deletions apps/webapp/src/features/+config.h.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { Config } from 'vike/types'

export default {
filesystemRoutingRoot: '/',
} satisfies Config
1 change: 0 additions & 1 deletion apps/webapp/src/features/_default.page.route.ts

This file was deleted.

5 changes: 5 additions & 0 deletions apps/webapp/src/features/auth/pages/+config.h.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { Config } from 'vike/types'

export default {
filesystemRoutingRoot: '/',
} satisfies Config
1 change: 0 additions & 1 deletion apps/webapp/src/features/auth/pages/_default.page.route.ts

This file was deleted.

8 changes: 0 additions & 8 deletions apps/webapp/src/features/auth/pages/login.page.route.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Link } from '@serieslist/core-ui'
import React from 'react'

import { AuthLayout } from '../components'
import { LoginForm } from '../components/LoginForm'
import { AuthLayout } from '../../components'
import { LoginForm } from '../../components/LoginForm'

export const Page = () => (
<AuthLayout
Expand Down
5 changes: 5 additions & 0 deletions apps/webapp/src/features/auth/pages/login/+guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { GuardSync } from 'vike/types'

import { requireNoAuthentication } from '#/utils/redirect'

export const guard: GuardSync = requireNoAuthentication()
8 changes: 0 additions & 8 deletions apps/webapp/src/features/auth/pages/register.page.route.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Link } from '@serieslist/core-ui'
import React from 'react'

import { AuthLayout } from '../components'
import { RegisterForm } from '../components/RegisterForm'
import { AuthLayout } from '../../components'
import { RegisterForm } from '../../components/RegisterForm'

export const Page = () => (
<AuthLayout
Expand Down
5 changes: 5 additions & 0 deletions apps/webapp/src/features/auth/pages/register/+guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { GuardSync } from 'vike/types'

import { requireNoAuthentication } from '#/utils/redirect'

export const guard: GuardSync = requireNoAuthentication()
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'

import { usePageContext } from '#/hooks'

import { SeriesDetailsPage } from '../components/SeriesDetailsPage'
import { SeriesDetailsPage } from '../../components/SeriesDetailsPage'

export const Page = () => {
const ctx = usePageContext()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { redirect } from 'vike/abort'
import type { GuardSync } from 'vike/types'

import { requireAuthentication } from '#/utils/redirect'

export const guard: GuardSync = (pageContext) => {
if (!pageContext.currentUser) {
throw redirect('/')
}
requireAuthentication()(pageContext)

throw redirect('/series/list/in-progress')
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react'
import { UserSeriesStatusStatus } from '#/generated/gql/graphql'
import { usePageContext } from '#/hooks'

import { UserSeriesListPage } from '../../components/UserSeriesListPage'
import { UserSeriesListPage } from '../../../components/UserSeriesListPage'

const statuses: Record<string, UserSeriesStatusStatus> = {
['in-progress']: UserSeriesStatusStatus.InProgress,
Expand Down
5 changes: 5 additions & 0 deletions apps/webapp/src/features/series/pages/list/@status/+guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { GuardSync } from 'vike/types'

import { requireAuthentication } from '#/utils/redirect'

export const guard: GuardSync = requireAuthentication()
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react'
import { usePageContext } from '#/hooks'

import Illustration404 from './404.svg?react'
import * as s from './_error.page.css'
import * as s from './ErrorPage.css'
import ServerDown from './ServerDown.svg?react'

export const Page = () => {
Expand Down
File renamed without changes
File renamed without changes.
File renamed without changes
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Title } from '@serieslist/core-ui'
import React from 'react'

import * as s from './index.page.css'
import * as s from './AboutPage.css'
import TMDBLogo from './TMDBLogo.svg?react'

export const Page = () => (
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions apps/webapp/src/pages/index/+guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { GuardSync } from 'vike/types'

import { requireNoAuthentication } from '#/utils/redirect'

export const guard: GuardSync = requireNoAuthentication()
8 changes: 0 additions & 8 deletions apps/webapp/src/pages/index/index.page.route.ts

This file was deleted.

16 changes: 16 additions & 0 deletions apps/webapp/src/renderer/+config.h.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { Config } from 'vike/types'

export default {
passToClient: [
'pageProps',
'routeParams',
'documentProps',
'apolloInitialState',
'currentUser',
'theme',
],
// Enable client-side routing
// https://vike.dev/clientRouting
clientRouting: true,
hydrationCanBeAborted: true,
} satisfies Config
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let root: Root | undefined
*/
let apollo: ApolloClient<NormalizedCacheObject> | undefined

export function render(pageContext: PageContextClient) {
export function onRenderClient(pageContext: PageContextClient) {
const { Page, pageProps } = pageContext

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
Expand Down Expand Up @@ -60,8 +60,3 @@ export function render(pageContext: PageContextClient) {
}
document.title = getPageTitle(pageContext)
}

// Enable client-side routing
// https://vike.dev/clientRouting
export const clientRouting = true
export const hydrationCanBeAborted = true
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,9 @@ import { THEME } from '#/utils/theme'

import { PageShell } from './PageShell'

export const passToClient = [
'pageProps',
'routeParams',
'documentProps',
'apolloInitialState',
'currentUser',
'theme',
]

const isProduction = process.env.NODE_ENV === 'production'

export async function render(pageContext: PageContextServer) {
export async function onRenderHtml(pageContext: PageContextServer) {
const { Page, pageProps, theme } = pageContext
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!Page) {
Expand Down
21 changes: 21 additions & 0 deletions apps/webapp/src/utils/redirect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { redirect } from 'vike/abort'
import type { GuardSync } from 'vike/types'

const UNAUTHENTICATED_DEFAULT_URL = '/'
const AUTHENTICATED_DEFAULT_URL = '/series/list/in-progress'

export const requireAuthentication =
(redirectTo = UNAUTHENTICATED_DEFAULT_URL): GuardSync =>
(pageContext) => {
if (!pageContext.currentUser) {
throw redirect(redirectTo)
}
}

export const requireNoAuthentication =
(redirectTo = AUTHENTICATED_DEFAULT_URL): GuardSync =>
(pageContext) => {
if (pageContext.currentUser) {
throw redirect(redirectTo)
}
}

0 comments on commit e0188ec

Please sign in to comment.