diff --git a/gatsby-browser.js b/gatsby-browser.js index bab70167e..a17bd4221 100644 --- a/gatsby-browser.js +++ b/gatsby-browser.js @@ -4,9 +4,9 @@ * See: https://www.gatsbyjs.org/docs/browser-apis/ */ -// You can delete this file if you're not using it -import wrapWithProvider from './wrap-with-provider' -export const wrapRootElement = wrapWithProvider +import 'prismjs/themes/prism-okaidia.css' +import { wrapElement, initKea } from './kea' -// gatsby-browser.js -require('prismjs/themes/prism-okaidia.css') +initKea(false) + +export const wrapRootElement = wrapElement diff --git a/gatsby-node.js b/gatsby-node.js index d45f00da9..3df2a4f1a 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -8,3 +8,17 @@ exports.createPages = require('./gatsby/createPages') exports.onCreateNode = require('./gatsby/onCreateNode') + +// Implement the Gatsby API “onCreatePage”. This is +// called after every page is created. +exports.onCreatePage = async ({ page, actions }) => { + const { createPage } = actions + // Only update the `/app` page. + if (page.path.match(/^\/plugins/)) { + // page.matchPath is a special key that's used for matching pages + // with corresponding routes only on the client. + page.matchPath = '/plugins/*' + // Update the page. + createPage(page) + } +} diff --git a/gatsby-ssr.js b/gatsby-ssr.js index 78fa62926..76262ee3a 100644 --- a/gatsby-ssr.js +++ b/gatsby-ssr.js @@ -5,5 +5,9 @@ */ // You can delete this file if you're not using it -import wrapWithProvider from './wrap-with-provider' -export const wrapRootElement = wrapWithProvider +import { wrapElement, initKea } from './kea' + +export const wrapPageElement = ({ element, props }) => { + initKea(true, props.location) + return wrapElement({ element }) +} diff --git a/kea.js b/kea.js new file mode 100644 index 000000000..3061d40b3 --- /dev/null +++ b/kea.js @@ -0,0 +1,13 @@ +import React from 'react' +import { Provider } from 'react-redux' +import { getContext, resetContext } from 'kea' +import { loadersPlugin } from 'kea-loaders' +import { routerPlugin } from 'kea-router' + +export function initKea(isServer = false, location = '') { + resetContext({ + plugins: [loadersPlugin, routerPlugin(isServer ? { location } : {})], + }) +} + +export const wrapElement = ({ element }) => {element} diff --git a/netlify.toml b/netlify.toml new file mode 100644 index 000000000..043fb614f --- /dev/null +++ b/netlify.toml @@ -0,0 +1,4 @@ +[[redirects]] + from = "/plugins/*" + to = "/plugins" + status = 200 \ No newline at end of file diff --git a/package.json b/package.json index 158243b8e..88d265611 100644 --- a/package.json +++ b/package.json @@ -47,8 +47,9 @@ "gatsby-transformer-remark": "^2.8.7", "gatsby-transformer-sharp": "^2.2.14", "katex": "^0.12.0", - "kea": "^2.2.0", + "kea": "^2.2.2", "kea-loaders": "^0.3.0", + "kea-router": "^0.5.1", "node-sass": "^4.14.1", "prismjs": "^1.21.0", "query-string": "^6.13.1", @@ -61,6 +62,7 @@ "react-modal": "^3.11.2", "react-redux": "^7.2.1", "react-responsive": "^6.1.2", + "redux": "^4.0.5", "reselect": "^4.0.0", "typescript": "^4.0.2" }, diff --git a/src/components/PluginLibrary/PluginModal.tsx b/src/components/PluginLibrary/PluginModal.tsx index 226354c21..3ccaae33d 100644 --- a/src/components/PluginLibrary/PluginModal.tsx +++ b/src/components/PluginLibrary/PluginModal.tsx @@ -8,13 +8,13 @@ import { useActions, useValues } from 'kea' import { pluginLibraryLogic } from '../../logic/pluginLibraryLogic' export const PluginModal = () => { - const { activePlugin, modalOpen, pluginLoading } = useValues(pluginLibraryLogic) - const { setModalOpen } = useActions(pluginLibraryLogic) + const { activePlugin, activePluginName, pluginLoading } = useValues(pluginLibraryLogic) + const { openLibrary } = useActions(pluginLibraryLogic) return ( setModalOpen(false)} + isOpen={!!activePluginName} + onRequestClose={openLibrary} className="pluginModalContent" overlayClassName="modalOverlay" ariaHideApp={false} @@ -32,7 +32,7 @@ export const PluginModal = () => { Learn More -