Skip to content

Commit

Permalink
Project refactoring
Browse files Browse the repository at this point in the history
* Moved ui-only hooks and contexts to ui folder
  • Loading branch information
GuilhermeF03 committed May 15, 2024
1 parent 5c3119d commit 9007758
Show file tree
Hide file tree
Showing 46 changed files with 90 additions and 87 deletions.
6 changes: 3 additions & 3 deletions code/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon-180x180.png" />
<link rel="icon" type="image/png" sizes="32x32" href="/favicon.ico" />
<link rel="icon" type="image/png" sizes="16x16" href="/favicon.ico" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<meta name="description" content="NoteSpace App" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
Expand Down
6 changes: 3 additions & 3 deletions code/client/src/App.tsx
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
SplitNodeOperation,
UnsetNodeOperation,
} from '@domain/editor/operations/history/types';
import { Communication } from '@/services/communication/communication';
import { Communication } from '@services/communication/communication';
import { BlockStyle, InlineStyle } from '@notespace/shared/src/document/types/styles';
import { getStyleType } from '@notespace/shared/src/document/types/styles';
import { Text, Element } from 'slate';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Cursor, Selection } from '@notespace/shared/src/document/types/cursor';
import { nodeInsert } from '@domain/editor/crdt/utils';
import { InlineStyle } from '@notespace/shared/src/document/types/styles';
import { Operation } from '@notespace/shared/src/document/types/operations.ts';
import { Communication } from '@/services/communication/communication';
import { Communication } from '@services/communication/communication';

export default (fugue: Fugue, { socket }: Communication): InputDomainOperations => {
function insertCharacter(char: string, cursor: Cursor, styles: InlineStyle[] = []) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FugueNode } from '@domain/editor/crdt/types';
import { Selection } from '@notespace/shared/src/document/types/cursor';
import { MarkdownDomainOperations } from '@domain/editor/operations/markdown/types';
import { deleteAroundSelection } from '@domain/editor/operations/markdown/utils';
import { Communication } from '@/services/communication/communication';
import { Communication } from '@services/communication/communication';
import { Operation } from '@notespace/shared/src/document/types/operations.ts';
import { isSelectionEmpty } from '@domain/editor/slate/utils/selection';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import inputHandlers from '@domain/editor/slate/handlers/input/inputHandlers';
import { Fugue } from '@domain/editor/crdt/fugue';
import inputDomainOperations from '@domain/editor/operations/input/operations';
import markdownDomainOperations from '@domain/editor/operations/markdown/operations';
import { Communication } from '@/services/communication/communication';
import { Communication } from '@services/communication/communication';
import markdownHandlers from '@domain/editor/slate/handlers/markdown/markdownHandlers';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import operations from './operations/editorOperations';
import markdownHandlers from '@domain/editor/operations/markdown/operations';
import { MarkdownDomainOperations } from '@domain/editor/operations/markdown/types';
import { Fugue } from '@domain/editor/crdt/fugue';
import { Communication } from '@/services/communication/communication';
import { Communication } from '@services/communication/communication';

/**
* Adds markdown support to the editor.
Expand Down
2 changes: 1 addition & 1 deletion code/client/src/domain/editor/slate/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions code/client/src/services/communication/communication.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { socketCommunication, SocketCommunication } from '@/services/communication/socket/socketCommunication.ts';
import { httpCommunication, HttpCommunication } from '@/services/communication/http/httpCommunication.ts';
import { socketCommunication, SocketCommunication } from '@services/communication/socket/socketCommunication.ts';
import { httpCommunication, HttpCommunication } from '@services/communication/http/httpCommunication.ts';

export interface Communication {
socket: SocketCommunication;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { io } from 'socket.io-client';
import config from '@/config.ts';
import { OperationEmitter } from '@/services/communication/socket/operationEmitter.ts';
import { OperationEmitter } from '@services/communication/socket/operationEmitter.ts';

type EmitType = (event: string, data?: any) => void;
type ListenType = (eventHandlers: SocketEventHandlers) => void;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect } from 'react';
import { SocketCommunication, SocketEventHandlers } from '@/services/communication/socket/socketCommunication.ts';
import { SocketCommunication, SocketEventHandlers } from '@services/communication/socket/socketCommunication.ts';

function useSocketListeners(socket: SocketCommunication, eventHandlers: SocketEventHandlers) {
useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion code/client/src/services/resource/resourceService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpCommunication } from '@/services/communication/http/httpCommunication.ts';
import { HttpCommunication } from '@services/communication/http/httpCommunication.ts';
import { ResourceInputModel, ResourceType, WorkspaceResource } from '@notespace/shared/src/workspace/types/resource.ts';

function resourceService(http: HttpCommunication, wid: string) {
Expand Down
4 changes: 2 additions & 2 deletions code/client/src/services/resource/useResourceService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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';
import resourceService from '@services/resource/resourceService.ts';

function useResourceService() {
const { http } = useCommunication();
Expand Down
4 changes: 2 additions & 2 deletions code/client/src/services/workspace/useWorkspaceService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMemo } from 'react';
import { useCommunication } from '@/services/communication/context/useCommunication.ts';
import workspaceService from '@/services/workspace/workspaceService.ts';
import { useCommunication } from '@ui/contexts/communication/useCommunication.ts';
import workspaceService from '@services/workspace/workspaceService.ts';

function useWorkspaceService() {
const { http } = useCommunication();
Expand Down
2 changes: 1 addition & 1 deletion code/client/src/services/workspace/workspaceService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpCommunication } from '@/services/communication/http/httpCommunication.ts';
import { HttpCommunication } from '@services/communication/http/httpCommunication.ts';
import { WorkspaceInputModel, WorkspaceMetaData } from '@notespace/shared/src/workspace/types/workspace.ts';
import { Workspace } from '@notespace/shared/src/workspace/types/workspace.ts';

Expand Down
4 changes: 2 additions & 2 deletions code/client/src/ui/components/sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createContext, ReactElement } from 'react';
import { communication, Communication } from '@/services/communication/communication.ts';
import { communication, Communication } from '@services/communication/communication.ts';

export const CommunicationContext = createContext<Communication>(communication);

Expand Down
7 changes: 7 additions & 0 deletions code/client/src/ui/contexts/communication/useCommunication.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Communication } from '@services/communication/communication.ts';
import { useContext } from 'react';
import { CommunicationContext } from '@ui/contexts/communication/CommunicationContext.tsx';

export function useCommunication(): Communication {
return useContext(CommunicationContext);
}
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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 useWorkspaceService from '@services/workspace/useWorkspaceService.ts';
import useResources from '@ui/contexts/workspace/useResources';
import { ResourceType, WorkspaceResource } from '@notespace/shared/src/workspace/types/resource.ts';

type ResourceOperationsType = {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 useResourceService from '@services/resource/useResourceService.ts';
import useSocketListeners from '@services/communication/socket/useSocketListeners.ts';
import { useCommunication } from '@ui/contexts/communication/useCommunication.ts';
import { useState } from 'react';

function useResources() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
6 changes: 3 additions & 3 deletions code/client/src/ui/pages/document/Document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ 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 useDocumentService from '@/services/resource/useResourceService';
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';

Expand Down
14 changes: 7 additions & 7 deletions code/client/src/ui/pages/document/components/editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import { Editable, Slate, withReact } from 'slate-react';
import { withHistory } from 'slate-history';
import { toSlate } from '@domain/editor/slate/utils/slate';
import { descendant } from '@domain/editor/slate/utils/slate';
import { Communication } from '@/services/communication/communication';
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';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Range } from 'slate';
import { useState } from 'react';
import useSocketListeners from '@/services/communication/socket/useSocketListeners';
import { Communication } from '@/services/communication/communication';
import useSocketListeners from '@services/communication/socket/useSocketListeners';
import { Communication } from '@services/communication/communication';
import { InlineStyle } from '@notespace/shared/src/document/types/styles';

export type CursorData = {
Expand Down
Original file line number Diff line number Diff line change
@@ -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[]) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import useSocketListeners from '@/services/communication/socket/useSocketListeners';
import useSocketListeners from '@services/communication/socket/useSocketListeners';
import { type Operation } from '@notespace/shared/src/document/types/operations.ts';
import { Communication } from '@/services/communication/communication';
import { Communication } from '@services/communication/communication';
import { FugueDomainOperations } from '@domain/editor/operations/fugue/types';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import historyDomainOperations from '@domain/editor/operations/history/operation
import historyHandlers from '@domain/editor/slate/handlers/history/historyHandlers';
import { Editor } from 'slate';
import { Fugue } from '@domain/editor/crdt/fugue';
import { Communication } from '@/services/communication/communication';
import { Communication } from '@services/communication/communication';

function useHistory(editor: Editor, fugue: Fugue, communication: Communication) {
useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getElementRenderer, getLeafRenderer } from '@domain/editor/slate/plugin
import { Editor } from 'slate';
import { Fugue } from '@domain/editor/crdt/fugue';
import { BlockStyle } from '@notespace/shared/src/document/types/styles';
import { Communication } from '@/services/communication/communication.ts';
import { Communication } from '@services/communication/communication.ts';

/**
* Returns the renderers for the editor.
Expand Down
6 changes: 3 additions & 3 deletions code/client/src/ui/pages/document/components/title/Title.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useState } from 'react';
import { ReactEditor, useSlate } from 'slate-react';
import { Communication } from '@/services/communication/communication';
import { Communication } from '@services/communication/communication';
import { useParams } from 'react-router-dom';
import useSocketListeners from '@/services/communication/socket/useSocketListeners.ts';
import useSocketListeners from '@services/communication/socket/useSocketListeners.ts';
import { WorkspaceResource } from '@notespace/shared/src/workspace/types/resource.ts';
import useDocumentService from '@/services/resource/useResourceService.ts';
import useDocumentService from '@services/resource/useResourceService.ts';

interface TitleProps extends React.InputHTMLAttributes<HTMLInputElement> {
title: string;
Expand Down
8 changes: 4 additions & 4 deletions code/client/src/ui/pages/home/Home.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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={() => {}}
/>
))}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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 useWorkspaceService from '@/services/workspace/useWorkspaceService.ts';
import useSocketListeners from '@services/communication/socket/useSocketListeners.ts';
import { useCommunication } from '@ui/contexts/communication/useCommunication.ts';
import useWorkspaceService from '@services/workspace/useWorkspaceService.ts';

function useWorkspaces() {
const { socket } = useCommunication();
Expand Down
Loading

0 comments on commit 9007758

Please sign in to comment.