From 2aef089966ee7471a1293e1c2da7a141cd9b21d6 Mon Sep 17 00:00:00 2001 From: Guilherme_F Date: Wed, 15 May 2024 11:27:15 +0100 Subject: [PATCH] Project refactoring * Moved ui-only hooks and contexts to ui folder --- code/client/index.html | 6 +++--- code/client/src/App.tsx | 6 +++--- code/client/src/domain/editor/slate/types.ts | 2 +- .../workspaces/{hooks => tree}/useWorkspaceTree.ts | 0 .../src/services/resource/useResourceService.ts | 2 +- .../src/services/workspace/useWorkspaceService.ts | 2 +- code/client/src/ui/components/sidebar/Sidebar.tsx | 4 ++-- .../communication}/CommunicationContext.tsx | 0 .../contexts/communication}/useCommunication.ts | 2 +- .../hooks => ui/contexts/error}/ErrorContext.tsx | 0 .../error/hooks => ui/contexts/error}/useError.ts | 2 +- .../contexts/workspace}/WorkspaceContext.tsx | 6 +++--- .../contexts/workspace}/useResources.ts | 2 +- .../contexts/workspace}/useWorkspace.ts | 2 +- code/client/src/ui/pages/document/Document.tsx | 4 ++-- .../ui/pages/document/components/editor/Editor.tsx | 12 ++++++------ .../components/editor}/hooks/useCursors.ts | 0 .../components/editor}/hooks/useDecorate.ts | 2 +- .../document/components/editor}/hooks/useEditor.ts | 0 .../document/components}/editor/hooks/useEvents.ts | 0 .../components/editor}/hooks/useHistory.ts | 0 .../components/editor}/hooks/useRenderers.ts | 0 code/client/src/ui/pages/home/Home.tsx | 8 ++++---- .../pages/home}/hooks/useWorkspaces.ts | 2 +- code/client/src/ui/pages/workspace/Workspace.tsx | 14 ++++++++------ ...DocumentContextMenu.tsx => FileContextMenu.tsx} | 4 ++-- .../components/{DocumentView.tsx => FileView.tsx} | 8 ++++---- .../components/{ => header}/WorkspaceHeader.scss | 0 .../components/{ => header}/WorkspaceHeader.tsx | 0 code/server/package.json | 1 + .../ts/databases/postgres/PostgresResourcesDB.ts | 2 +- 31 files changed, 48 insertions(+), 45 deletions(-) rename code/client/src/domain/workspaces/{hooks => tree}/useWorkspaceTree.ts (100%) rename code/client/src/{services/communication/context => ui/contexts/communication}/CommunicationContext.tsx (100%) rename code/client/src/{services/communication/context => ui/contexts/communication}/useCommunication.ts (68%) rename code/client/src/{domain/error/hooks => ui/contexts/error}/ErrorContext.tsx (100%) rename code/client/src/{domain/error/hooks => ui/contexts/error}/useError.ts (61%) rename code/client/src/{domain/workspaces/hooks => ui/contexts/workspace}/WorkspaceContext.tsx (89%) rename code/client/src/{domain/resources/hooks => ui/contexts/workspace}/useResources.ts (94%) rename code/client/src/{domain/workspaces/hooks => ui/contexts/workspace}/useWorkspace.ts (60%) rename code/client/src/{domain/editor/slate => ui/pages/document/components/editor}/hooks/useCursors.ts (100%) rename code/client/src/{domain/editor/slate => ui/pages/document/components/editor}/hooks/useDecorate.ts (91%) rename code/client/src/{domain/editor/slate => ui/pages/document/components/editor}/hooks/useEditor.ts (100%) rename code/client/src/{domain => ui/pages/document/components}/editor/hooks/useEvents.ts (100%) rename code/client/src/{domain/editor/slate => ui/pages/document/components/editor}/hooks/useHistory.ts (100%) rename code/client/src/{domain/editor/slate => ui/pages/document/components/editor}/hooks/useRenderers.ts (100%) rename code/client/src/{domain/workspaces => ui/pages/home}/hooks/useWorkspaces.ts (95%) rename code/client/src/ui/pages/workspace/components/{DocumentContextMenu.tsx => FileContextMenu.tsx} (83%) rename code/client/src/ui/pages/workspace/components/{DocumentView.tsx => FileView.tsx} (79%) rename code/client/src/ui/pages/workspace/components/{ => header}/WorkspaceHeader.scss (100%) rename code/client/src/ui/pages/workspace/components/{ => header}/WorkspaceHeader.tsx (100%) diff --git a/code/client/index.html b/code/client/index.html index f4ecdc8b..c768af22 100644 --- a/code/client/index.html +++ b/code/client/index.html @@ -2,9 +2,9 @@ - - - + + + diff --git a/code/client/src/App.tsx b/code/client/src/App.tsx index 8adf1004..04d23b6c 100644 --- a/code/client/src/App.tsx +++ b/code/client/src/App.tsx @@ -1,13 +1,13 @@ import { BrowserRouter as Router, Route, Routes } from 'react-router-dom'; -import { CommunicationProvider } from '@/services/communication/context/CommunicationContext'; +import { CommunicationProvider } from '@ui/contexts/communication/CommunicationContext.tsx'; import Document from '@ui/pages/document/Document'; import Header from '@ui/components/header/Header'; import Workspace from '@ui/pages/workspace/Workspace'; import NotFound from '@ui/pages/notfound/NotFound'; import './App.scss'; -import { ErrorProvider } from '@domain/error/hooks/ErrorContext.tsx'; +import { ErrorProvider } from '@/ui/contexts/error/ErrorContext'; import Sidebar from '@ui/components/sidebar/Sidebar'; -import { WorkspaceProvider } from '@domain/workspaces/hooks/WorkspaceContext.tsx'; +import { WorkspaceProvider } from '@/ui/contexts/workspace/WorkspaceContext'; import Home from '@ui/pages/home/Home.tsx'; function App() { diff --git a/code/client/src/domain/editor/slate/types.ts b/code/client/src/domain/editor/slate/types.ts index 26844eb2..5b63f9d7 100644 --- a/code/client/src/domain/editor/slate/types.ts +++ b/code/client/src/domain/editor/slate/types.ts @@ -2,7 +2,7 @@ import { type BaseEditor, Descendant } from 'slate'; import { type ReactEditor } from 'slate-react'; import { type HistoryEditor } from 'slate-history'; import { type BlockStyle, InlineStyle } from '@notespace/shared/src/document/types/styles'; -import { CursorData } from '@/domain/editor/slate/hooks/useCursors'; +import { CursorData } from '@/ui/pages/document/components/editor/hooks/useCursors'; export interface CustomFormat { bold?: boolean; diff --git a/code/client/src/domain/workspaces/hooks/useWorkspaceTree.ts b/code/client/src/domain/workspaces/tree/useWorkspaceTree.ts similarity index 100% rename from code/client/src/domain/workspaces/hooks/useWorkspaceTree.ts rename to code/client/src/domain/workspaces/tree/useWorkspaceTree.ts diff --git a/code/client/src/services/resource/useResourceService.ts b/code/client/src/services/resource/useResourceService.ts index cb18132d..74bbf1b7 100644 --- a/code/client/src/services/resource/useResourceService.ts +++ b/code/client/src/services/resource/useResourceService.ts @@ -1,5 +1,5 @@ import { useMemo } from 'react'; -import { useCommunication } from '@/services/communication/context/useCommunication.ts'; +import { useCommunication } from '@ui/contexts/communication/useCommunication.ts'; import { useParams } from 'react-router-dom'; import resourceService from '@/services/resource/resourceService.ts'; diff --git a/code/client/src/services/workspace/useWorkspaceService.ts b/code/client/src/services/workspace/useWorkspaceService.ts index 248edcdf..b902f969 100644 --- a/code/client/src/services/workspace/useWorkspaceService.ts +++ b/code/client/src/services/workspace/useWorkspaceService.ts @@ -1,5 +1,5 @@ import { useMemo } from 'react'; -import { useCommunication } from '@/services/communication/context/useCommunication.ts'; +import { useCommunication } from '@ui/contexts/communication/useCommunication.ts'; import workspaceService from '@/services/workspace/workspaceService.ts'; function useWorkspaceService() { diff --git a/code/client/src/ui/components/sidebar/Sidebar.tsx b/code/client/src/ui/components/sidebar/Sidebar.tsx index 53bb2a28..7165ab41 100644 --- a/code/client/src/ui/components/sidebar/Sidebar.tsx +++ b/code/client/src/ui/components/sidebar/Sidebar.tsx @@ -1,14 +1,14 @@ import { IoMenu } from 'react-icons/io5'; import { Link, useParams } from 'react-router-dom'; import { RiMenuFold2Line, RiMenuFoldLine } from 'react-icons/ri'; -import useWorkspace from '@domain/workspaces/hooks/useWorkspace.ts'; +import useWorkspace from '@/ui/contexts/workspace/useWorkspace'; import useSidebarState from '@ui/components/sidebar/hooks/useSidebarState.ts'; import ResourceView from '@ui/components/sidebar/components/ResourceView.tsx'; import './Sidebar.scss'; function Sidebar() { const { isOpen, isLocked, handleClick, handleMouseEnter, handleMouseLeave } = useSidebarState(); - const { workspace, resources, operations } = useWorkspace(); + const { workspace, resources } = useWorkspace(); const { wid } = useParams(); return ( diff --git a/code/client/src/services/communication/context/CommunicationContext.tsx b/code/client/src/ui/contexts/communication/CommunicationContext.tsx similarity index 100% rename from code/client/src/services/communication/context/CommunicationContext.tsx rename to code/client/src/ui/contexts/communication/CommunicationContext.tsx diff --git a/code/client/src/services/communication/context/useCommunication.ts b/code/client/src/ui/contexts/communication/useCommunication.ts similarity index 68% rename from code/client/src/services/communication/context/useCommunication.ts rename to code/client/src/ui/contexts/communication/useCommunication.ts index 8bea4a9f..d95a8e59 100644 --- a/code/client/src/services/communication/context/useCommunication.ts +++ b/code/client/src/ui/contexts/communication/useCommunication.ts @@ -1,6 +1,6 @@ import { Communication } from '@/services/communication/communication.ts'; import { useContext } from 'react'; -import { CommunicationContext } from '@/services/communication/context/CommunicationContext.tsx'; +import { CommunicationContext } from '@ui/contexts/communication/CommunicationContext.tsx'; export function useCommunication(): Communication { return useContext(CommunicationContext); diff --git a/code/client/src/domain/error/hooks/ErrorContext.tsx b/code/client/src/ui/contexts/error/ErrorContext.tsx similarity index 100% rename from code/client/src/domain/error/hooks/ErrorContext.tsx rename to code/client/src/ui/contexts/error/ErrorContext.tsx diff --git a/code/client/src/domain/error/hooks/useError.ts b/code/client/src/ui/contexts/error/useError.ts similarity index 61% rename from code/client/src/domain/error/hooks/useError.ts rename to code/client/src/ui/contexts/error/useError.ts index 05f29861..539c587b 100644 --- a/code/client/src/domain/error/hooks/useError.ts +++ b/code/client/src/ui/contexts/error/useError.ts @@ -1,5 +1,5 @@ import { useContext } from 'react'; -import { ErrorContext } from '@domain/error/hooks/ErrorContext.tsx'; +import { ErrorContext } from '@/ui/contexts/error/ErrorContext'; const useError = () => useContext(ErrorContext); diff --git a/code/client/src/domain/workspaces/hooks/WorkspaceContext.tsx b/code/client/src/ui/contexts/workspace/WorkspaceContext.tsx similarity index 89% rename from code/client/src/domain/workspaces/hooks/WorkspaceContext.tsx rename to code/client/src/ui/contexts/workspace/WorkspaceContext.tsx index 2bb6f9ba..b8c9c7e2 100644 --- a/code/client/src/domain/workspaces/hooks/WorkspaceContext.tsx +++ b/code/client/src/ui/contexts/workspace/WorkspaceContext.tsx @@ -1,11 +1,11 @@ import * as React from 'react'; import { useState, createContext, useEffect } from 'react'; import { Workspace, WorkspaceMetaData } from '@notespace/shared/src/workspace/types/workspace.ts'; -import { useCommunication } from '@/services/communication/context/useCommunication.ts'; -import useError from '@domain/error/hooks/useError.ts'; +import { useCommunication } from '@ui/contexts/communication/useCommunication.ts'; +import useError from '@/ui/contexts/error/useError'; import { useParams } from 'react-router-dom'; import useWorkspaceService from '@/services/workspace/useWorkspaceService.ts'; -import useResources from '@domain/resources/hooks/useResources.ts'; +import useResources from '@/ui/contexts/workspace/useResources'; import { ResourceType, WorkspaceResource } from '@notespace/shared/src/workspace/types/resource.ts'; type ResourceOperationsType = { diff --git a/code/client/src/domain/resources/hooks/useResources.ts b/code/client/src/ui/contexts/workspace/useResources.ts similarity index 94% rename from code/client/src/domain/resources/hooks/useResources.ts rename to code/client/src/ui/contexts/workspace/useResources.ts index b9255c97..b7bf68b6 100644 --- a/code/client/src/domain/resources/hooks/useResources.ts +++ b/code/client/src/ui/contexts/workspace/useResources.ts @@ -1,7 +1,7 @@ import { ResourceType, WorkspaceResource } from '@notespace/shared/src/workspace/types/resource.ts'; import useResourceService from '@/services/resource/useResourceService.ts'; import useSocketListeners from '@/services/communication/socket/useSocketListeners.ts'; -import { useCommunication } from '@/services/communication/context/useCommunication.ts'; +import { useCommunication } from '@ui/contexts/communication/useCommunication.ts'; import { useState } from 'react'; function useResources() { diff --git a/code/client/src/domain/workspaces/hooks/useWorkspace.ts b/code/client/src/ui/contexts/workspace/useWorkspace.ts similarity index 60% rename from code/client/src/domain/workspaces/hooks/useWorkspace.ts rename to code/client/src/ui/contexts/workspace/useWorkspace.ts index 410930a5..14fdd5f6 100644 --- a/code/client/src/domain/workspaces/hooks/useWorkspace.ts +++ b/code/client/src/ui/contexts/workspace/useWorkspace.ts @@ -1,5 +1,5 @@ import { useContext } from 'react'; -import { WorkspaceContext } from '@domain/workspaces/hooks/WorkspaceContext.tsx'; +import { WorkspaceContext } from '@/ui/contexts/workspace/WorkspaceContext'; const useWorkspace = () => useContext(WorkspaceContext); diff --git a/code/client/src/ui/pages/document/Document.tsx b/code/client/src/ui/pages/document/Document.tsx index ad1b1e50..152de0ad 100644 --- a/code/client/src/ui/pages/document/Document.tsx +++ b/code/client/src/ui/pages/document/Document.tsx @@ -2,8 +2,8 @@ import Editor from '@ui/pages/document/components/editor/Editor'; import useFugue from '@domain/editor/crdt/useFugue'; import { useEffect, useState } from 'react'; import { useParams, useNavigate } from 'react-router-dom'; -import { useCommunication } from '@/services/communication/context/useCommunication'; -import useError from '@domain/error/hooks/useError.ts'; +import { useCommunication } from '@ui/contexts/communication/useCommunication.ts'; +import useError from '@/ui/contexts/error/useError'; import useDocumentService from '@/services/resource/useResourceService'; import { DocumentResource } from '@notespace/shared/src/workspace/types/resource.ts'; import './Document.scss'; diff --git a/code/client/src/ui/pages/document/components/editor/Editor.tsx b/code/client/src/ui/pages/document/components/editor/Editor.tsx index 32478203..6028a951 100644 --- a/code/client/src/ui/pages/document/components/editor/Editor.tsx +++ b/code/client/src/ui/pages/document/components/editor/Editor.tsx @@ -6,14 +6,14 @@ import { descendant } from '@domain/editor/slate/utils/slate'; import { Communication } from '@/services/communication/communication'; import { getMarkdownPlugin } from '@domain/editor/slate/plugins/markdown/withMarkdown'; import { Fugue } from '@domain/editor/crdt/fugue'; -import useEvents from '@domain/editor/hooks/useEvents'; -import useRenderers from '@domain/editor/slate/hooks/useRenderers'; +import useEvents from '@/ui/pages/document/components/editor/hooks/useEvents'; +import useRenderers from '@/ui/pages/document/components/editor/hooks/useRenderers'; import Toolbar from '@ui/pages/document/components/toolbar/Toolbar'; import Title from '@ui/pages/document/components/title/Title'; -import useEditor from '@domain/editor/slate/hooks/useEditor'; -import useHistory from '@domain/editor/slate/hooks/useHistory'; -import useDecorate from '@domain/editor/slate/hooks/useDecorate'; -import useCursors from '@domain/editor/slate/hooks/useCursors'; +import useEditor from '@/ui/pages/document/components/editor/hooks/useEditor'; +import useHistory from '@/ui/pages/document/components/editor/hooks/useHistory'; +import useDecorate from '@/ui/pages/document/components/editor/hooks/useDecorate'; +import useCursors from '@/ui/pages/document/components/editor/hooks/useCursors'; import getEventHandlers from '@domain/editor/slate/handlers/getEventHandlers'; import getFugueOperations from '@domain/editor/operations/fugue/operations'; import './Editor.scss'; diff --git a/code/client/src/domain/editor/slate/hooks/useCursors.ts b/code/client/src/ui/pages/document/components/editor/hooks/useCursors.ts similarity index 100% rename from code/client/src/domain/editor/slate/hooks/useCursors.ts rename to code/client/src/ui/pages/document/components/editor/hooks/useCursors.ts diff --git a/code/client/src/domain/editor/slate/hooks/useDecorate.ts b/code/client/src/ui/pages/document/components/editor/hooks/useDecorate.ts similarity index 91% rename from code/client/src/domain/editor/slate/hooks/useDecorate.ts rename to code/client/src/ui/pages/document/components/editor/hooks/useDecorate.ts index d058beb6..af9015b6 100644 --- a/code/client/src/domain/editor/slate/hooks/useDecorate.ts +++ b/code/client/src/ui/pages/document/components/editor/hooks/useDecorate.ts @@ -1,4 +1,4 @@ -import { CursorData } from '@domain/editor/slate/hooks/useCursors'; +import { CursorData } from '@/ui/pages/document/components/editor/hooks/useCursors'; import { BaseRange, Editor, NodeEntry, Path, Range, Text } from 'slate'; function useDecorate(editor: Editor, cursors: CursorData[]) { diff --git a/code/client/src/domain/editor/slate/hooks/useEditor.ts b/code/client/src/ui/pages/document/components/editor/hooks/useEditor.ts similarity index 100% rename from code/client/src/domain/editor/slate/hooks/useEditor.ts rename to code/client/src/ui/pages/document/components/editor/hooks/useEditor.ts diff --git a/code/client/src/domain/editor/hooks/useEvents.ts b/code/client/src/ui/pages/document/components/editor/hooks/useEvents.ts similarity index 100% rename from code/client/src/domain/editor/hooks/useEvents.ts rename to code/client/src/ui/pages/document/components/editor/hooks/useEvents.ts diff --git a/code/client/src/domain/editor/slate/hooks/useHistory.ts b/code/client/src/ui/pages/document/components/editor/hooks/useHistory.ts similarity index 100% rename from code/client/src/domain/editor/slate/hooks/useHistory.ts rename to code/client/src/ui/pages/document/components/editor/hooks/useHistory.ts diff --git a/code/client/src/domain/editor/slate/hooks/useRenderers.ts b/code/client/src/ui/pages/document/components/editor/hooks/useRenderers.ts similarity index 100% rename from code/client/src/domain/editor/slate/hooks/useRenderers.ts rename to code/client/src/ui/pages/document/components/editor/hooks/useRenderers.ts diff --git a/code/client/src/ui/pages/home/Home.tsx b/code/client/src/ui/pages/home/Home.tsx index 2aaf3860..d3d4cf14 100644 --- a/code/client/src/ui/pages/home/Home.tsx +++ b/code/client/src/ui/pages/home/Home.tsx @@ -1,8 +1,8 @@ -import useWorkspaces from '@domain/workspaces/hooks/useWorkspaces.ts'; +import useWorkspaces from '@/ui/pages/home/hooks/useWorkspaces'; import WorkspaceView from '@ui/pages/home/components/WorkspaceView.tsx'; -import WorkspaceHeader from '@ui/pages/workspace/components/WorkspaceHeader.tsx'; +import WorkspaceHeader from '@ui/pages/workspace/components/header/WorkspaceHeader.tsx'; import CreateWorkspaceDialog from '@ui/pages/home/components/CreateWorkspaceDialog.tsx'; -import useError from '@domain/error/hooks/useError.ts'; +import useError from '@/ui/contexts/error/useError'; import './Home.scss'; import '../workspace/Workspace.scss'; @@ -22,7 +22,7 @@ function Home() { key={workspace.id} workspace={workspace} onDelete={() => deleteWorkspace(workspace.id).catch(publishError)} - onRename={name => updateWorkspace(workspace.id, {...workspace, name: name + "-copy" }).catch(publishError)} + onRename={name => updateWorkspace(workspace.id, { ...workspace, name: name + '-copy' }).catch(publishError)} onInvite={() => {}} /> ))} diff --git a/code/client/src/domain/workspaces/hooks/useWorkspaces.ts b/code/client/src/ui/pages/home/hooks/useWorkspaces.ts similarity index 95% rename from code/client/src/domain/workspaces/hooks/useWorkspaces.ts rename to code/client/src/ui/pages/home/hooks/useWorkspaces.ts index 3c642b3e..877a53fd 100644 --- a/code/client/src/domain/workspaces/hooks/useWorkspaces.ts +++ b/code/client/src/ui/pages/home/hooks/useWorkspaces.ts @@ -1,7 +1,7 @@ import { useEffect, useState } from 'react'; import { WorkspaceInputModel, WorkspaceMetaData } from '@notespace/shared/src/workspace/types/workspace.ts'; import useSocketListeners from '@/services/communication/socket/useSocketListeners.ts'; -import { useCommunication } from '@/services/communication/context/useCommunication.ts'; +import { useCommunication } from '@ui/contexts/communication/useCommunication.ts'; import useWorkspaceService from '@/services/workspace/useWorkspaceService.ts'; function useWorkspaces() { diff --git a/code/client/src/ui/pages/workspace/Workspace.tsx b/code/client/src/ui/pages/workspace/Workspace.tsx index bc1e710c..f03f2fcf 100644 --- a/code/client/src/ui/pages/workspace/Workspace.tsx +++ b/code/client/src/ui/pages/workspace/Workspace.tsx @@ -1,8 +1,8 @@ -import WorkspaceHeader from '@ui/pages/workspace/components/WorkspaceHeader'; -import DocumentView from '@ui/pages/workspace/components/DocumentView.tsx'; -import useError from '@domain/error/hooks/useError.ts'; +import WorkspaceHeader from '@ui/pages/workspace/components/header/WorkspaceHeader.tsx'; +import FileView from '@ui/pages/workspace/components/FileView.tsx'; +import useError from '@/ui/contexts/error/useError'; import './Workspace.scss'; -import useWorkspace from '@domain/workspaces/hooks/useWorkspace.ts'; +import useWorkspace from '@/ui/contexts/workspace/useWorkspace'; import { DocumentResourceMetadata, ResourceType } from '@notespace/shared/src/workspace/types/resource.ts'; function Workspace() { @@ -19,11 +19,13 @@ function Workspace() { {resources ?.filter(resource => resource.type === ResourceType.DOCUMENT) .map(resource => ( - operations?.deleteResource(resource.id).catch(publishError)} - onDuplicate={() => operations?.createResource(resource.name + "-copy", ResourceType.DOCUMENT).catch(publishError)} + onDuplicate={() => + operations?.createResource(resource.name + '-copy', ResourceType.DOCUMENT).catch(publishError) + } onRename={name => operations?.updateResource(resource.id, { name }).catch(publishError)} /> ))} diff --git a/code/client/src/ui/pages/workspace/components/DocumentContextMenu.tsx b/code/client/src/ui/pages/workspace/components/FileContextMenu.tsx similarity index 83% rename from code/client/src/ui/pages/workspace/components/DocumentContextMenu.tsx rename to code/client/src/ui/pages/workspace/components/FileContextMenu.tsx index 91a9342d..f83ac86f 100644 --- a/code/client/src/ui/pages/workspace/components/DocumentContextMenu.tsx +++ b/code/client/src/ui/pages/workspace/components/FileContextMenu.tsx @@ -10,7 +10,7 @@ type DocumentContextMenuProps = { onDuplicate: () => void; }; -function DocumentContextMenu({ item, onRename, onDelete, onDuplicate }: DocumentContextMenuProps) { +function FileContextMenu({ item, onRename, onDelete, onDuplicate }: DocumentContextMenuProps) { return (