feat: graphql client with fetches for initial pages

This commit is contained in:
Simon Emanuelsson
2024-02-01 16:19:16 +01:00
parent a91781137a
commit 5e974aa3da
56 changed files with 2580 additions and 1512 deletions

View File

@@ -0,0 +1,5 @@
import type { Asides } from "@/types/requests/currentBlockPage"
export type AsideProps = {
blocks: Asides[]
}

View File

@@ -0,0 +1,5 @@
import type { Blocks } from "@/types/requests/currentBlockPage"
export type BlocksProps = {
blocks: Blocks[]
}

View File

@@ -0,0 +1,3 @@
import type { Text } from "@/types/requests/blocks/text"
export type TextProps = Text

View File

@@ -0,0 +1,7 @@
import type { Image } from "@/types/image"
export type HeroProps = {
images: {
node: Image
}[]
}

1
types/graphql.d.ts vendored Normal file
View File

@@ -0,0 +1 @@
declare module '*.graphql'

8
types/image.ts Normal file
View File

@@ -0,0 +1,8 @@
export type Image = {
dimension: {
height: number
width: number
}
title: string
url: string
}

3
types/request.ts Normal file
View File

@@ -0,0 +1,3 @@
export type Data<T> = {
data: T
}

View File

@@ -0,0 +1,23 @@
import type { Edges } from "../utils/edges"
export type Contact = {
contact: {
contactConnection: Edges<{
mailing_address: {
city: string
country: string
name: string
street: string
zip: string
}
phone: string
title: string
visiting_address: {
city: string
country: string
street: string
zip: string
}
}>
}
}

View File

@@ -0,0 +1,8 @@
import type { Puff } from "../puff"
import type { Edges } from "../utils/edges"
export type PuffAside = {
puff: {
puffConnection: Edges<Puff>
}
}

View File

@@ -0,0 +1,46 @@
import type { Edges } from "../utils/edges"
import type { ExternalLink } from "../utils/externalLink"
import type { PageLink } from "../utils/pagelink"
enum ListItemStyleEnum {
checkmark = "checkmark",
default = "default",
}
type ListItemStyle = keyof typeof ListItemStyleEnum
type ExternalLinkListItem = {
list_item_external_link: {
link: {
href: string
title: string
}
list_item_style: ListItemStyle
subtitle?: string
}
}
type InternalLinkListItem = {
list_item_internal_link: {
link_text?: string
list_item_style: ListItemStyle
subtitle?: string
pageConnection: Edges<ExternalLink | PageLink>
}
}
type RegularListItem = {
list_item: {
list_item_style: ListItemStyle
subtitle?: string
title: string
}
}
type ListItem = ExternalLinkListItem | InternalLinkListItem | RegularListItem
export type List = {
list: {
list_items: ListItem
}
}

View File

@@ -0,0 +1,17 @@
import type { SysAsset } from "../utils/asset"
import type { Edges } from "../utils/edges"
import type { ExternalLink } from "../utils/externalLink"
import type { PageLink } from "../utils/pagelink"
export type Preamble = {
preamble: {
text: {
json: JSON
embedded_itemsConnection: Edges<
| ExternalLink
| PageLink
| SysAsset
>
}
}
}

View File

@@ -0,0 +1,8 @@
import type { Edges } from "../utils/edges"
import type { Puff } from "../puff"
export type PuffBlock = {
puffs: {
puffsConnection: Edges<Puff>
}
}

View File

@@ -0,0 +1,19 @@
import type { RTERootObject } from "@/types/rte"
import type { SysAsset } from "../utils/asset"
import type { Edges } from "../utils/edges"
import type { ExternalLink } from "../utils/externalLink"
import type { PageLink } from "../utils/pagelink"
export type Text = {
text: {
content: {
json: RTERootObject
embedded_itemsConnection: Edges<
| ExternalLink
| PageLink
| SysAsset
>
}
}
}

View File

@@ -0,0 +1,33 @@
import { BlocksTypenameEnum } from "./utils/typename"
import type { Contact } from "./asides/contact"
import type { PuffAside } from "./asides/puff"
import type { Hero } from "./hero"
import type { List } from "./blocks/list"
import type { PuffBlock } from "./blocks/puff"
import type { Preamble } from "./blocks/preamble"
import type { Text } from "./blocks/text"
import type { AllRequestResponse } from "./utils/all"
import type { AsideTypenameEnum, Typename } from "./utils/typename"
export type Asides =
| Typename<Contact, AsideTypenameEnum.CurrentBlocksPageAsideContact>
| Typename<PuffAside, AsideTypenameEnum.CurrentBlocksPageAsidePuff>
export type Blocks =
| Typename<List, BlocksTypenameEnum.CurrentBlocksPageBlocksList>
| Typename<Preamble, BlocksTypenameEnum.CurrentBlocksPageBlocksPreamble>
| Typename<PuffBlock, BlocksTypenameEnum.CurrentBlocksPageBlocksPuffs>
| Typename<Text, BlocksTypenameEnum.CurrentBlocksPageBlocksText>
export type BlockPage = {
aside: Asides[]
blocks: Blocks[]
hero: Hero
title: string
url: string
}
export type GetCurrentBlockPageData = {
all_current_blocks_page: AllRequestResponse<BlockPage>
}

6
types/requests/hero.ts Normal file
View File

@@ -0,0 +1,6 @@
import type { Image } from "../image"
import type { Edges } from "./utils/edges"
export type Hero = {
imagesConnection: Edges<Image>
}

26
types/requests/puff.ts Normal file
View File

@@ -0,0 +1,26 @@
import type { Edges } from "./utils/edges"
import type { ExternalLink } from "./utils/externalLink"
import type { PageLink } from "./utils/pagelink"
import type { Typename } from "./utils/typename"
export type Puff = {
imageConnection: Edges<{
title: string
url: string
}>
is_internal: boolean
link: {
href: string
title: string
}
link_text?: string
pageConnection: Edges<ExternalLink | PageLink>
text: {
json: JSON
embedded_itemsConnection: Edges<Typename<{
title: string
url: string
}, "SysAsset">>
}
title: string
}

View File

@@ -0,0 +1,4 @@
export type AllRequestResponse<T> = {
items: T[]
total: number
}

View File

@@ -0,0 +1,8 @@
import type { Typename } from "./typename"
export type Asset = {
title: string
url: string
}
export type SysAsset = Typename<Asset, "SysAsset">

View File

@@ -0,0 +1,8 @@
export type Node<T> = {
node: T
}
export type Edges<T> = {
edges: Node<T>[]
totalCount: number
}

View File

@@ -0,0 +1,5 @@
export type ExternalLink = {
__typename: "TempPage"
title: string
url: string
}

View File

@@ -0,0 +1,5 @@
export type PageLink = {
__typename: "CurrentBlocksPage"
title: string
url: string
}

View File

@@ -0,0 +1,31 @@
export const AsideTypenames = {
CurrentBlocksPageAsideContact: "CurrentBlocksPageAsideContact",
CurrentBlocksPageAsidePuff: "CurrentBlocksPageAsidePuff",
}
export enum AsideTypenameEnum {
CurrentBlocksPageAsideContact = "CurrentBlocksPageAsideContact",
CurrentBlocksPageAsidePuff = "CurrentBlocksPageAsidePuff",
}
export type AsideTypename = keyof typeof AsideTypenameEnum
export const blocksTypenameEnum = {
CurrentBlocksPageBlocksList: "CurrentBlocksPageBlocksList",
CurrentBlocksPageBlocksPreamble: "CurrentBlocksPageBlocksPreamble",
CurrentBlocksPageBlocksPuffs: "CurrentBlocksPageBlocksPuffs",
CurrentBlocksPageBlocksText: "CurrentBlocksPageBlocksText",
}
export type BlocksTypename = keyof typeof blocksTypenameEnum
export enum BlocksTypenameEnum {
CurrentBlocksPageBlocksList = "CurrentBlocksPageBlocksList",
CurrentBlocksPageBlocksPreamble = "CurrentBlocksPageBlocksPreamble",
CurrentBlocksPageBlocksPuffs = "CurrentBlocksPageBlocksPuffs",
CurrentBlocksPageBlocksText = "CurrentBlocksPageBlocksText",
}
export type Typename<T, K> = T & {
__typename: K
}

58
types/rte.ts Normal file
View File

@@ -0,0 +1,58 @@
export const rteType = {
asset: "asset",
p: "p",
reference: "reference",
}
export enum RTETypeEnum {
asset = "asset",
p = "p",
reference = "reference",
}
export type RTEType = keyof typeof rteType
export type RTEText = {
text: string
}
export type RTEAssetAttrs = {
"alt": string
"asset-alt": string
"asset-link": string
"asset-name": string
"asset-type": "image/png" | "image/jpg" | "image/jpeg"
"asset-uid": string
"display-type": "display"
"class-name": string
"content-type-uid": "sys_assets"
"inline": false
"type": RTETypeEnum.asset
}
type RTEBaseObject<T> = {
type: T
uid: string
}
type AssetReferenceObject = RTEBaseObject<RTETypeEnum.reference> & {
attrs: RTEAssetAttrs
children: RTEText[]
}
export type RTEObject =
| AssetReferenceObject
| {
attrs: Record<string, any>
children: (RTEObject | RTEText)[]
type: RTEType
uid: string
}
export type RTERootObject = {
attrs: RTEAssetAttrs | Record<string, any>
children: RTEObject[]
uid: string
type: "doc"
_version: number
}