Skip to content

Commit

Permalink
Added ErrorBoundary & Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
R1c4rdCo5t4 committed Jun 29, 2024
1 parent 9dc5815 commit 3f932c6
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions code/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"lodash": "^4.17.21",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-error-boundary": "^4.0.13",
"react-icons": "^5.2.1",
"react-router-dom": "^6.23.0",
"slate": "^0.103.0",
Expand Down
2 changes: 1 addition & 1 deletion code/client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import Login from '@ui/pages/login/Login';
import Search from '@ui/pages/search/Search';
import CommitHistory from '@ui/pages/document/components/commit-history/CommitHistory';
import Commit from '@ui/pages/document/components/commit/Commit';
import './App.scss';
import Recent from '@ui/pages/recent/Recent';
import './App.scss';

function App() {
return (
Expand Down
3 changes: 2 additions & 1 deletion code/client/src/contexts/error/ErrorContext.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import { useState, createContext, useEffect, useCallback } from 'react';
import ErrorComponent from '@ui/components/error/Error';
import { ErrorBoundary } from 'react-error-boundary';

const ERROR_TIMEOUT = 5000;

Expand Down Expand Up @@ -39,7 +40,7 @@ export function ErrorProvider({ children }: { children: React.ReactNode }) {
return (
<ErrorContext.Provider value={{ publishError: setError, errorHandler }}>
{error && <ErrorComponent error={error} />}
{children}
<ErrorBoundary FallbackComponent={ErrorComponent}>{children}</ErrorBoundary>
</ErrorContext.Provider>
);
}
4 changes: 2 additions & 2 deletions code/client/src/domain/workspaces/tree/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { TreeNode } from '@domain/workspaces/tree/types';
import { Resources } from '@/contexts/workspace/WorkspaceContext';

export function getTree(id: string, nodes: Resources): TreeNode {
export function traverseWorkspaceTree(id: string, nodes: Resources): TreeNode {
const node = nodes[id];
return {
node,
children: node.children.map(id => getTree(id, nodes)),
children: node.children.map(id => traverseWorkspaceTree(id, nodes)),
};
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import TreeResourceView from '@ui/components/sidebar/components/workspace-tree/TreeResourceView';
import { WorkspaceMeta } from '@notespace/shared/src/workspace/types/workspace';
import { getTree } from '@domain/workspaces/tree/utils';
import { traverseWorkspaceTree } from '@domain/workspaces/tree/utils';
import { ResourceType } from '@notespace/shared/src/workspace/types/resource';
import { DragEvent, useState } from 'react';
import { Resources, WorkspaceOperations } from '@/contexts/workspace/WorkspaceContext';
Expand Down Expand Up @@ -49,7 +49,7 @@ function WorkspaceTree({ workspace, resources, operations }: WorkspaceTreeProps)
<div className="workspace-tree">
<ul>
{resources[workspace.id] &&
getTree(workspace.id, resources).children.map(node => (
traverseWorkspaceTree(workspace.id, resources).children.map(node => (
<li key={node.node.id}>
<TreeResourceView
workspace={workspace.id}
Expand Down
3 changes: 3 additions & 0 deletions code/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"lodash": "^4.17.21",
"postgres": "^3.4.4",
"socket.io": "^4.7.5",
"supertest": "^6.3.4",
"uuid": "^9.0.1"
},
"devDependencies": {
Expand All @@ -32,8 +33,10 @@
"@types/cookie-parser": "^1.4.7",
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/jest": "^29.5.12",
"@types/lodash": "^4.17.1",
"@types/node": "^20.14.8",
"@types/supertest": "^6.0.2",
"@types/uuid": "^9.0.8",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
Expand Down

0 comments on commit 3f932c6

Please sign in to comment.