menu from api
This commit is contained in:
1 parent
7e856bce18
commit
bc2f1f78fd
5 files changed
+45
-12
No files matched your search
@@ -6,7 +6,7 @@ import { Footer } from '../Footer'
|
||||
import { Content } from '../Content'
|
||||
import { Block } from '../Block'
|
||||
import { Breadcrumbs } from '../Breadcrumbs'
|
||||
import { IBreadcumbsPart } from 'src/types'
|
||||
import { IBreadcumbsPart, IMenu } from 'src/types'
|
||||
import { useRouter } from 'next/router'
|
||||
import { useMobile } from 'src/hooks/useMobile'
|
||||
|
||||
@@ -19,9 +19,10 @@ export interface IAppProps {
|
||||
wide?: boolean
|
||||
contentStyle?: React.CSSProperties
|
||||
breadcrumbs?: IBreadcumbsPart[]
|
||||
menu: IMenu[]
|
||||
}
|
||||
|
||||
export const App: React.FC<IAppProps> = ({ showAuthor = false, wide = false, ...props }) => {
|
||||
export const App: React.FC<IAppProps> = ({ showAuthor = false, wide = false, menu, ...props }) => {
|
||||
const hideBreadcrumbs = useMobile()
|
||||
const router = useRouter()
|
||||
const blockStyle = {
|
||||
@@ -29,7 +30,10 @@ export const App: React.FC<IAppProps> = ({ showAuthor = false, wide = false, ...
|
||||
}
|
||||
|
||||
return (
|
||||
<ConfigContext.Provider value={config}>
|
||||
<ConfigContext.Provider value={{
|
||||
...config,
|
||||
menu,
|
||||
}}>
|
||||
<Wrapper
|
||||
header={(
|
||||
<header>
|
||||
|
||||
+15
-3
@@ -1,6 +1,6 @@
|
||||
import { ImageDefinition, IPage, ITag, PageCardDto, Token } from "@/types";
|
||||
import { ImageDefinition, IMenu, IPage, ITag, PageCardDto, Token } from "@/types";
|
||||
import { asItem } from "./lib";
|
||||
import { StrapiComponentEmbed, StrapiComponent, StrapiHome, StrapiPage, StrapiPageCard, StrapiTag, StrapiMedia } from "./types";
|
||||
import { StrapiComponentEmbed, StrapiComponent, StrapiHome, StrapiPage, StrapiPageCard, StrapiTag, StrapiMedia, StrapiMenu } from "./types";
|
||||
|
||||
export function createPageUrls(pages: StrapiPage[]) {
|
||||
return {
|
||||
@@ -102,7 +102,19 @@ export function createPageTokens(components: StrapiComponent[]): Token[] {
|
||||
})
|
||||
}
|
||||
|
||||
export function createPage(res: StrapiPage | StrapiPage[]): IPage {
|
||||
export function createMenu(res: StrapiMenu): IMenu[] {
|
||||
const items: IMenu[] = res.menu.items.map(x => ({
|
||||
href: x.page.slug,
|
||||
name: x.page.title,
|
||||
}))
|
||||
|
||||
return [{
|
||||
href: '/',
|
||||
name: res.homeLabel,
|
||||
}, ...items]
|
||||
}
|
||||
|
||||
export function createPage(res: StrapiPage | StrapiPage[]): IPage | null {
|
||||
const item = asItem(res)
|
||||
if (!item) {
|
||||
return null
|
||||
|
||||
+10
-2
@@ -90,7 +90,7 @@ export type StrapiTag = {
|
||||
id: number,
|
||||
slug: string,
|
||||
name: string,
|
||||
// "page": 114,
|
||||
page: StrapiPage,
|
||||
// "created_at": "2021-01-31T20:38:39.373Z",
|
||||
// "updated_at": "2021-02-17T07:37:54.749Z"
|
||||
}
|
||||
@@ -119,9 +119,17 @@ export type StrapiHome = {
|
||||
// "updated_at": "2021-02-04T16:28:30.961Z",
|
||||
}
|
||||
|
||||
export type StrapiMenu = {
|
||||
id: number,
|
||||
homeLabel: string
|
||||
menu: StrapiComponentCardGrid
|
||||
// "created_at": "2021-02-04T04:12:38.291Z",
|
||||
// "updated_at": "2021-02-04T16:28:30.961Z",
|
||||
}
|
||||
|
||||
export type StrapiPageCard = {
|
||||
__component: 'hudozka.page-card',
|
||||
id: number,
|
||||
page: StrapiPage,
|
||||
layout: 'small' | 'medium' | 'big',
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user