Skip to content

Commit

Permalink
Prevents editor from loading on paths without the editor
Browse files Browse the repository at this point in the history
Stopgap fix.
  • Loading branch information
steveruizok committed Jan 21, 2021
1 parent 1908e0d commit 2c5e371
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
30 changes: 28 additions & 2 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import * as React from "react"
import "../styles/globals.css"

import MonacoProvider from "components/monaco-provider"
import Head from "next/head"
import dynamic from "next/dynamic"
import { useRouter } from "next/router"
import codePanelState from "states/code-panel"

const Dialog = dynamic(() => import("components/dialog"))
const Toast = dynamic(() => import("components/toast"))
Expand All @@ -14,6 +17,25 @@ const TW_IMAGE = "https://app.state-designer.com/sd-social-og.jpg"
const URL = "https://app.state-designer.com"

function MyApp({ Component, pageProps }) {
const { pathname, events } = useRouter()

React.useEffect(() => {
function handleRouteChange() {
codePanelState.send("UNLOADED")
}

events.on("routeChangeStart", handleRouteChange)
return () => events.off("routeChangeStart", handleRouteChange)
}, [])

const isProjectPath =
pathname.includes("/p/") &&
!(
pathname.endsWith("view") ||
pathname.endsWith("chart") ||
pathname.endsWith("clean")
)

return (
<>
<Head>
Expand All @@ -28,9 +50,13 @@ function MyApp({ Component, pageProps }) {
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content="@statedesigner" />
</Head>
<MonacoProvider>
{isProjectPath ? (
<MonacoProvider>
<Component {...pageProps} />
</MonacoProvider>
) : (
<Component {...pageProps} />
</MonacoProvider>
)}
<Toast />
<Dialog />
</>
Expand Down
4 changes: 2 additions & 2 deletions states/code-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,12 @@ const codePanelState = createState({
},
updateModels(data) {
EDITOR_TABS.forEach((tab) => {
data.models[tab].setValue(data.code[tab].clean)
data.models[tab]?.setValue(data.code[tab].clean)
})
},
updateCleanViewStates(data) {
EDITOR_TABS.forEach((tab) => {
data.viewStates[tab].clean.setValue(data.code[tab].clean)
data.viewStates[tab]?.clean.setValue(data.code[tab].clean)
})
},
setStateActiveTab(data) {
Expand Down

1 comment on commit 2c5e371

@vercel
Copy link

@vercel vercel bot commented on 2c5e371 Jan 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.