mirror of
https://github.com/silverstripe/doc.silverstripe.org
synced 2024-06-28 15:39:44 +02:00
8ffc3eeb5b
* Docs/userguide switching * Initial commit of userdocs merge * Remove service worker, fix rendering * Remove limited sources * UX improvements per Paul design * Tweak version select for FF * Fix mobile view * Final tweaks to UI * Tweaks to search bar, clean up conflicts * Fix icons * Hide search if no API key
66 lines
1.4 KiB
TypeScript
66 lines
1.4 KiB
TypeScript
import React, { StatelessComponent, ReactElement } from 'react';
|
|
import NodeContext from '../contexts/NodeContext';
|
|
import { useStaticQuery, graphql } from 'gatsby';
|
|
import { HierarchyQuery } from '../types';
|
|
import {
|
|
getChildren,
|
|
getCurrentNode,
|
|
getCurrentVersion,
|
|
getHomePage,
|
|
getNavChildren,
|
|
getNodes,
|
|
getParent,
|
|
getSiblings,
|
|
initialise,
|
|
setCurrentPath,
|
|
} from '../utils/nodes';
|
|
|
|
const NodeProvider: StatelessComponent<{}> = ({ children, pageContext: { slug } }): ReactElement => {
|
|
const result:HierarchyQuery = useStaticQuery(graphql`
|
|
{
|
|
allSilverstripeDocument {
|
|
nodes {
|
|
title
|
|
summary
|
|
isIndex
|
|
introduction
|
|
icon
|
|
iconBrand
|
|
hideChildren
|
|
slug
|
|
parentSlug
|
|
fileTitle
|
|
fileAbsolutePath
|
|
category
|
|
}
|
|
}
|
|
}
|
|
`
|
|
);
|
|
if (!getNodes()) {
|
|
const nodes = result.allSilverstripeDocument.nodes.map(node => ({
|
|
...node,
|
|
}));
|
|
initialise(nodes);
|
|
}
|
|
|
|
setCurrentPath(slug);
|
|
|
|
return (
|
|
<NodeContext.Provider value={{
|
|
getChildren,
|
|
getCurrentNode,
|
|
getCurrentVersion,
|
|
getHomePage,
|
|
getNavChildren,
|
|
getNodes,
|
|
getParent,
|
|
getSiblings,
|
|
setCurrentPath,
|
|
}}>
|
|
{children}
|
|
</NodeContext.Provider>
|
|
)
|
|
};
|
|
|
|
export default NodeProvider; |