-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
91 additions
and
2 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
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,39 @@ | ||
import { gql, request } from '@solid-primitives/graphql' | ||
import { cache, redirect, RouteLoadFunc } from '@solidjs/router' | ||
import { GRAPHQL_BACKEND_URL } from '~/constants' | ||
import { Page } from '~/models/page' | ||
|
||
const QUERY = gql` | ||
query Page($slug: String!) { | ||
page(slug: $slug) { | ||
id | ||
template | ||
name | ||
title | ||
content | ||
extras | ||
} | ||
} | ||
` | ||
|
||
export const queryPageByID = cache(async (slug: string): Promise<Page> => { | ||
type Response = { | ||
page: Page | ||
} | ||
|
||
const response = await request<Response>(GRAPHQL_BACKEND_URL, QUERY, { | ||
variables: { | ||
slug, | ||
}, | ||
}) | ||
|
||
if (response.page === null) { | ||
throw redirect('/404') | ||
} | ||
|
||
return response.page | ||
}, 'Pages.queryPageByID') | ||
|
||
export const loadPagesPage: RouteLoadFunc = ({ params }) => { | ||
void queryPageByID(params.slug) | ||
} |
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,14 @@ | ||
export enum PageTemplate { | ||
SERVICES = 'services', | ||
} | ||
|
||
export type Page = { | ||
id: number | ||
template: PageTemplate | ||
name: string | ||
title: string | ||
content: string | ||
extras: { | ||
[attr: string]: any | ||
} | ||
} |
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,5 @@ | ||
.container { | ||
max-width: var(--content-page-width-wide); | ||
padding-inline: var(--page-padding); | ||
margin-inline: auto; | ||
} |
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,25 @@ | ||
import { Meta, Title } from '@solidjs/meta' | ||
import { createAsync, RouteSectionProps } from '@solidjs/router' | ||
import { Component, Show } from 'solid-js' | ||
import PageRenderer from '~/components/PageRenderer' | ||
import { queryPageByID } from '~/data/pages.data' | ||
import styles from './Pages.module.scss' | ||
|
||
const PagesPage: Component<RouteSectionProps> = ({ params }) => { | ||
const data = createAsync(() => queryPageByID(params.slug), { | ||
deferStream: true, | ||
}) | ||
|
||
return ( | ||
<Show when={!!data()}> | ||
<Title title="" /> | ||
<Meta property="og:title" content={data()!.title} /> | ||
|
||
<div class={styles.container}> | ||
<PageRenderer title={data()!.title} content={data()!.content} /> | ||
</div> | ||
</Show> | ||
) | ||
} | ||
|
||
export default PagesPage |