diff --git a/src/App.tsx b/src/App.tsx index 6e7e374a10..76b8d4eadd 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -9,7 +9,7 @@ import Header from './components/Header' import { Global } from '@emotion/core' import { HotKeys } from 'react-hotkeys' import useShortcuts, { keyMap } from './hooks/useShortcuts' -import ErrorBoundary from './components/ErrorBoundary' +import EditorErrorBoundary from './components/errorBoundaries/EditorErrorBoundary' import { decodeShareUrl } from './utils/share' import useDispatch from './hooks/useDispatch' @@ -40,11 +40,11 @@ const App = () => { - + - + = ({ return ( {component.children.map((key: string) => ( - + ))} ) diff --git a/src/components/errorBoundaries/AppErrorBoundary.tsx b/src/components/errorBoundaries/AppErrorBoundary.tsx new file mode 100644 index 0000000000..8dcdaef561 --- /dev/null +++ b/src/components/errorBoundaries/AppErrorBoundary.tsx @@ -0,0 +1,73 @@ +import React, { Component } from 'react' +import { Box, Flex, Stack, Button } from '@chakra-ui/core' +import { FaBomb } from 'react-icons/fa' +import { gridStyles } from '../editor/Editor' +import { bugsnagClient } from '../../utils/bugsnag' + +type ErrorBoundaryState = { + hasError: boolean +} + +type ErrorBoundaryProps = {} + +export default class AppErrorBoundary extends Component< + ErrorBoundaryProps, + ErrorBoundaryState +> { + state = { hasError: false } + + static getDerivedStateFromError(error: any) { + bugsnagClient.notify(error) + return { hasError: true } + } + + render() { + if (this.state.hasError) { + return ( + + + + + Oups… +
+ Something went wrong! Clear cache and refresh. + +
+
+
+ ) + } + + return this.props.children + } +} diff --git a/src/components/ErrorBoundary.tsx b/src/components/errorBoundaries/EditorErrorBoundary.tsx similarity index 95% rename from src/components/ErrorBoundary.tsx rename to src/components/errorBoundaries/EditorErrorBoundary.tsx index 17562b5adb..8ce4ef847c 100644 --- a/src/components/ErrorBoundary.tsx +++ b/src/components/errorBoundaries/EditorErrorBoundary.tsx @@ -3,8 +3,8 @@ import { connect } from 'react-redux' import { ActionCreators as UndoActionCreators } from 'redux-undo' import { Box, Flex, Stack, Button } from '@chakra-ui/core' import { FaBomb } from 'react-icons/fa' -import { gridStyles } from './editor/Editor' -import { bugsnagClient } from '../utils/bugsnag' +import { gridStyles } from '../editor/Editor' +import { bugsnagClient } from '../../utils/bugsnag' type ErrorBoundaryState = { hasError: boolean diff --git a/src/core/models/components.ts b/src/core/models/components.ts index 2cc66f0706..102cafb3a2 100644 --- a/src/core/models/components.ts +++ b/src/core/models/components.ts @@ -85,12 +85,16 @@ const components = createModel({ let updatedComponents = { ...state.components } let component = updatedComponents[componentId] + // Remove self if (component && component.parent) { - const children = updatedComponents[component.parent].children.filter( - (el: string) => el !== component.id, + const siblings = updatedComponents[component.parent].children.filter( + (el: string) => el !== componentId, ) - updatedComponents[component.parent].children = children + updatedComponents[component.parent] = { + ...updatedComponents[component.parent], + children: siblings, + } } const deleteRecursive = ( @@ -99,18 +103,15 @@ const components = createModel({ ) => { children.forEach(child => { updatedComponents[child] && - deleteRecursive( - updatedComponents[child].children, - updatedComponents[child].id, - ) + deleteRecursive(updatedComponents[child].children, componentId) }) updatedComponents = omit(updatedComponents, id) } - deleteRecursive(component.children, component.id) + deleteRecursive(component.children, componentId) - updatedComponents = omit(updatedComponents, component.id) + updatedComponents = omit(updatedComponents, componentId) return { ...state, diff --git a/src/index.tsx b/src/index.tsx index 520071ae60..bf43bce4e8 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -5,17 +5,20 @@ import { ThemeProvider, CSSReset, theme } from '@chakra-ui/core' import { Provider } from 'react-redux' import { store } from './core/store' -import { ErrorBoundary } from './utils/bugsnag' +import { ErrorBoundary as BugsnagErrorBoundary } from './utils/bugsnag' +import AppErrorBoundary from './components/errorBoundaries/AppErrorBoundary' ReactDOM.render( - - - - - - - - , + + + + + + + + + + , document.getElementById('root'), ) diff --git a/src/utils/share.ts b/src/utils/share.ts index d116566214..fe19e5f0d1 100644 --- a/src/utils/share.ts +++ b/src/utils/share.ts @@ -1,7 +1,9 @@ import * as LZString from 'lz-string' export const createShareUrl = (components: IComponents) => - `${document.location.host}/?share=${LZString.compressToEncodedURIComponent( + `${document.location.protocol}//${ + document.location.host + }/?share=${LZString.compressToEncodedURIComponent( JSON.stringify(components), )}`