* turn article.scss into a module + componentized * Update Survey to use only component styles, add cancel button * Update GenericError + 404 page to use only standard classes * update LearningTrack to not use markdown-body * remove / consolidate stylesheets * cleanup Graphiql explorer page and scss * Componentize Breadcrumb styles * Componentize DeprecationBanner styles * scope h2 a link style to markdown-body * cleanup nav, organize page-header and page-footer components * remove unused scroll-button.scss * organize LanguagePicker and ProductPicker * add declarations file * remove featured-links.scss, update tests * update list utility and toc test * fix bad merge resolution * update breadcrumbs test
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import pick from 'lodash/pick'
|
|
import { createContext, useContext } from 'react'
|
|
import { FeaturedLink, getFeaturedLinksFromReq } from './ProductLandingContext'
|
|
|
|
export type TocItem = {
|
|
fullPath: string
|
|
title: string
|
|
intro?: string
|
|
}
|
|
|
|
export type TocLandingContextT = {
|
|
title: string
|
|
introPlainText: string
|
|
productCallout: string
|
|
tocItems: Array<TocItem>
|
|
variant?: 'compact' | 'expanded'
|
|
featuredLinks: Record<string, Array<FeaturedLink>>
|
|
renderedPage: string
|
|
}
|
|
|
|
export const TocLandingContext = createContext<TocLandingContextT | null>(null)
|
|
|
|
export const useTocLandingContext = (): TocLandingContextT => {
|
|
const context = useContext(TocLandingContext)
|
|
|
|
if (!context) {
|
|
throw new Error('"useTocLandingContext" may only be used inside "TocLandingContext.Provider"')
|
|
}
|
|
|
|
return context
|
|
}
|
|
|
|
export const getTocLandingContextFromRequest = (req: any): TocLandingContextT => {
|
|
const isEarlyAccess = req.context.page?.documentType === 'early-access'
|
|
return {
|
|
title: req.context.page.title,
|
|
productCallout: req.context.page.product || '',
|
|
introPlainText: req.context.page.introPlainText,
|
|
tocItems: (req.context.genericTocFlat || req.context.genericTocNested || []).map((obj: any) =>
|
|
pick(obj, ['fullPath', 'title', 'intro', 'childTocItems'])
|
|
),
|
|
variant: req.context.genericTocFlat ? 'expanded' : 'compact',
|
|
|
|
featuredLinks: getFeaturedLinksFromReq(req),
|
|
renderedPage: isEarlyAccess ? req.context.renderedPage : '',
|
|
}
|
|
}
|