Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
R1c4rdCo5t4 committed May 6, 2024
2 parents 260c7c9 + 924f71a commit 206a8ae
Show file tree
Hide file tree
Showing 39 changed files with 510 additions and 147 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:

- uses: pnpm/action-setup@v3
with:
version: 'latest'
version: '9.0.6'

- uses: actions/setup-node@v4
with:
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:

- uses: pnpm/action-setup@v3
with:
version: 'latest'
version: '9.0.6'

- name: Set up Node.js
uses: actions/setup-node@v4
Expand Down Expand Up @@ -83,7 +83,7 @@ jobs:

- uses: pnpm/action-setup@v3
with:
version: 'latest'
version: '9.0.6'

- name: Set up Node.js
uses: actions/setup-node@v4
Expand Down
4 changes: 3 additions & 1 deletion code/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"serve": "vite preview"
},
"dependencies": {
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
"@mui/material": "^5.15.16",
"@notespace/shared": "file:..\\shared",
"@testing-library/jest-dom": "^6.4.5",
"dotenv": "^16.4.5",
Expand All @@ -27,7 +30,6 @@
"msw": "^2.2.14",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-error-boundary": "^4.0.13",
"react-icons": "^5.2.0",
"react-router-dom": "^6.23.0",
"slate": "^0.103.0",
Expand Down
19 changes: 19 additions & 0 deletions code/client/src/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,25 @@
width: 100vw;
height: 100vh;
color: black;
display: flex;
flex-direction: row;
justify-content: center;
align-items: start;
overflow: clip;

.content {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: start;
align-items: center;
overflow-y: auto;

> :last-child {
width: 100%;
}
}
}

::-webkit-scrollbar {
Expand Down
38 changes: 22 additions & 16 deletions code/client/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
import { BrowserRouter as Router, Route, Routes, Navigate } from 'react-router-dom';
import { CommunicationProvider } from '@/domain/communication/context/CommunicationContext';
import { communication } from '@/domain/communication/communication';
import { ErrorBoundary } from 'react-error-boundary';
import Document from '@/ui/pages/document/Document';
import Header from '@/ui/components/header/Header';
import Workspace from '@/ui/pages/workspace/Workspace';
import Error from '@/ui/components/error/Error';
import './App.scss';
import NotFound from '@/ui/pages/notfound/NotFound';
import './App.scss';
import { ErrorProvider } from '@domain/error/ErrorContext';
import Sidebar from '@ui/components/sidebar/Sidebar';
import { WorkspaceProvider } from '@domain/workspace/WorkspaceContext';

function App() {
return (
<div className="app">
<CommunicationProvider communication={communication}>
<Router>
<Header />
<ErrorBoundary FallbackComponent={Error}>
<Routes>
<Route path="/" element={<Navigate to={`/documents`} />} />
<Route path="/documents" element={<Workspace />} />
<Route path="/documents/:id" element={<Document />} />
<Route path="*" element={<NotFound />} />
</Routes>
</ErrorBoundary>
</Router>
</CommunicationProvider>
<ErrorProvider>
<CommunicationProvider communication={communication}>
<WorkspaceProvider>
<Router>
<Sidebar />
<div className="content">
<Header />
<Routes>
<Route path="/" element={<Navigate to={`/documents`} />} />
<Route path="/documents" element={<Workspace />} />
<Route path="/documents/:id" element={<Document />} />
<Route path="*" element={<NotFound />} />
</Routes>
</div>
</Router>
</WorkspaceProvider>
</CommunicationProvider>
</ErrorProvider>
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type EmitType = (event: string, data?: any) => void;
type ListenType = (eventHandlers: SocketEventHandlers) => void;
export type SocketEventHandlers = Record<string, (...args: any[]) => void>;

const OPTIONS = { autoConnect: false };
const OPTIONS = { autoConnect: true };
export const socket: Socket = io(config.SOCKET_SERVER_URL, OPTIONS);
const operationEmitter = new OperationEmitter();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpCommunication } from '@/domain/communication/http/httpCommunication';
import documentServices from '@/domain/editor/services/documentServices';
import { HttpCommunication } from '@domain/communication/http/httpCommunication';
import documentServices from '@/services/documentServices';

function useDocumentServices(http: HttpCommunication) {
async function getDocument(id: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ function toHistoryOperations(editor: Editor, operations: Batch | undefined, reve
operation: BaseInsertNodeOperation | BaseRemoveNodeOperation,
insert_mode: boolean
): InsertNodeOperation | RemoveNodeOperation | undefined {
console.log(insert_mode ? 'insertNodeOperation' : 'removeNodeOperation', operation);
if (operation.node.text === '') return undefined;

const offset = (line: number) => (line === 0 ? 0 : 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ export const getLeafRenderer = (leaf: CustomText, children: ReactNode) => {
children = renderer(children);
}
if (leaf.cursor) {
const { color, id, range, styles } = leaf.cursor;

children = Range.isCollapsed(range!) ? (
<Cursor color={color} styles={styles} key={id} children={children} />
) : (
<Selection color={color} children={children} />
);
const { color, range, styles } = leaf.cursor;
if (Range.isCollapsed(range!)) {
children = <Cursor color={color} styles={styles} children={children} />;
} else {
children = <Selection color={color} children={children} />;
}
}
return children;
};
32 changes: 32 additions & 0 deletions code/client/src/domain/error/ErrorContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as React from 'react';
import { useState, createContext, useEffect } from 'react';
import ErrorComponent from '@ui/components/error/Error';

const ERROR_TIMEOUT = 5000;

export type ErrorContextType = {
showError: (error: Error) => void;
};

export const ErrorContext = createContext<ErrorContextType>({
showError: () => {},
});

export function ErrorProvider({ children }: { children: React.ReactNode }) {
const [error, setError] = useState<Error | undefined>();

useEffect(() => {
if (error) {
setTimeout(() => {
setError(undefined);
}, ERROR_TIMEOUT);
}
}, [error]);

return (
<ErrorContext.Provider value={{ showError: setError }}>
{error && <ErrorComponent error={error} />}
{children}
</ErrorContext.Provider>
);
}
8 changes: 8 additions & 0 deletions code/client/src/domain/error/useError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useContext } from 'react';
import { ErrorContext } from '@domain/error/ErrorContext';

function useError() {
return useContext(ErrorContext);
}

export default useError;
17 changes: 17 additions & 0 deletions code/client/src/domain/workspace/WorkspaceContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as React from 'react';
import { useState, createContext } from 'react';

export type WorkspaceContextType = {
filePath: string | undefined;
setFilePath: (path: string) => void;
};

export const WorkspaceContext = createContext<WorkspaceContextType>({
filePath: undefined,
setFilePath: () => {},
});

export function WorkspaceProvider({ children }: { children: React.ReactNode }) {
const [filePath, setFilePath] = useState<string | undefined>(undefined);
return <WorkspaceContext.Provider value={{ filePath, setFilePath }}>{children}</WorkspaceContext.Provider>;
}
8 changes: 8 additions & 0 deletions code/client/src/domain/workspace/useWorkspace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useContext } from 'react';
import { WorkspaceContext } from '@domain/workspace/WorkspaceContext';

function useWorkspace() {
return useContext(WorkspaceContext);
}

export default useWorkspace;
5 changes: 0 additions & 5 deletions code/client/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ button {
border: none;
}

button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}

@media (prefers-color-scheme: light) {
:root {
color: #213547;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpCommunication } from '@/domain/communication/http/httpCommunication';
import { HttpCommunication } from '@domain/communication/http/httpCommunication';
import { Document } from '@notespace/shared/crdt/types/document';

async function getDocument(http: HttpCommunication, id: string): Promise<Document> {
Expand Down
36 changes: 36 additions & 0 deletions code/client/src/ui/components/context-menu/ContextMenu.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.menu {
ul {
background-color: black;
width: 100px;
border-radius: 5px;
}

.menu-items {
display: flex;
flex-direction: column;
background-color: black;

button {
display: flex;
flex-direction: row;
justify-content: left;
color: white;
background-color: black;
border: none;
padding: 2vh;
margin: 0 1vh 0 1vh;
font-size: 10px;
cursor: pointer;
transition: background-color 0.3s;

&:hover {
background-color: white;
color: black;
}

:first-child {
margin-right: 1.5vh;
}
}
}
}
43 changes: 43 additions & 0 deletions code/client/src/ui/components/context-menu/ContextMenu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { MouseEvent, ReactNode, useState } from 'react';
import { Menu, PopoverPosition } from '@mui/material';
import './ContextMenu.scss';

type ContextMenuProps = {
item: ReactNode;
children: ReactNode;
};

function ContextMenu({ item, children }: ContextMenuProps) {
const [mousePosition, setMousePosition] = useState<PopoverPosition | null>(null);

function onContextMenu(e: MouseEvent<HTMLElement>) {
if (mousePosition !== null) return; // don't show context menu if it's already open
e.preventDefault();
setMousePosition({
left: e.clientX - 2,
top: e.clientY - 4,
});
}

function onClose() {
setMousePosition(null);
}

return (
<div onContextMenu={onContextMenu} onClick={onClose}>
{item}
<Menu
className="menu"
open={mousePosition !== null}
onClose={onClose}
anchorReference="anchorPosition"
anchorPosition={mousePosition || undefined}
keepMounted
>
<div className="menu-items">{children}</div>
</Menu>
</div>
);
}

export default ContextMenu;
17 changes: 2 additions & 15 deletions code/client/src/ui/components/error/Error.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
import './Error.scss';
import { MdError } from 'react-icons/md';
import { useState, useEffect } from 'react';

type ErrorProps = {
error: Error;
error?: Error;
};

const ERROR_TIMEOUT = 5000;

function Error({ error }: ErrorProps) {
const [showError, setShowError] = useState(true);

useEffect(() => {
const id = setTimeout(() => {
setShowError(false);
}, ERROR_TIMEOUT);
return () => clearTimeout(id);
}, []);

if (!showError) {
if (!error) {
return null;
}

return (
<div className="error" role="alert">
<span>
Expand Down
15 changes: 10 additions & 5 deletions code/client/src/ui/components/header/Header.scss
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
header {
position: sticky;
width: 100%;
height: 5vh;
top: 0;
left: 0;
color: black;
background: white;
width: 100%;
padding: 1vh 0 1vh 5vh;
padding: 1vh 0 1vh 15vh;
box-shadow: black 0 0 1px;
display: flex;
align-items: center;
z-index: 1;

.title {
font-size: 3vh;
p {
font-size: 2.5vh;
padding: 1vh;
margin: 0 0 0 1vh;
margin: 0 0 0 2vh;
font-weight: 500;
}
}
Loading

0 comments on commit 206a8ae

Please sign in to comment.