Skip to content

Commit

Permalink
Added Fixes & Features
Browse files Browse the repository at this point in the history
  • Loading branch information
R1c4rdCo5t4 committed Jun 28, 2024
1 parent 5b9d00d commit c39d2b4
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ export const getLeafRenderer = ({ attributes, leaf, children }: RenderLeafProps)
children = renderer(children);
}
if (leaf.cursor) {
const { color, range, styles } = leaf.cursor;
const { color, range, styles, id } = leaf.cursor;
children = Range.isCollapsed(range!) ? (
<Cursor color={color} styles={styles} children={children} />
<Cursor id={id} color={color} styles={styles} children={children} />
) : (
<Selection color={color} children={children} />
);
Expand Down
40 changes: 20 additions & 20 deletions code/client/src/pwa/manifest-config.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import {ManifestOptions} from "vite-plugin-pwa";
import { ManifestOptions } from 'vite-plugin-pwa';

const manifestConfig : Partial<ManifestOptions> = {
name: 'NoteSpace',
short_name: 'NoteSpace',
description: 'A multiplatform note management and sharing app',
theme_color: '#ffffff',
icons: [
{
src: '/assets/icon.png',
sizes: '192x192',
type: 'image/png',
},
{
src: '/assets/icon.png',
sizes: '512x512',
type: 'image/png',
},
],
}
const manifestConfig: Partial<ManifestOptions> = {
name: 'NoteSpace',
short_name: 'NoteSpace',
description: 'A multiplatform note management and sharing app',
theme_color: '#ffffff',
icons: [
{
src: '/assets/icon.png',
sizes: '192x192',
type: 'image/png',
},
{
src: '/assets/icon.png',
sizes: '512x512',
type: 'image/png',
},
],
};

export default manifestConfig;
export default manifestConfig;
18 changes: 9 additions & 9 deletions code/client/src/pwa/pwa-config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {VitePWAOptions} from "vite-plugin-pwa";
import { VitePWAOptions } from 'vite-plugin-pwa';
//import manifestConfig from "./manifest-config";

const pwaConfig : Partial<VitePWAOptions> = {
registerType: 'autoUpdate',
//manifest: manifestConfig,
//devOptions: {
// enabled: true,
//}
}
export default pwaConfig;
const pwaConfig: Partial<VitePWAOptions> = {
registerType: 'autoUpdate',
//manifest: manifestConfig,
//devOptions: {
// enabled: true,
//}
};
export default pwaConfig;
2 changes: 1 addition & 1 deletion code/client/src/ui/components/sidebar/Sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
border: none;
color: black;
font-size: 5vh;
padding: 0;
padding: 0 0 2vh 0;
margin: 0;
transition: transform 1s ease-in-out;

Expand Down
9 changes: 7 additions & 2 deletions code/client/src/ui/components/sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ function Sidebar() {

if (!isLoaded || !isLoggedIn) return null;
return (
<div className="sidebar" style={{ width }} onMouseLeave={handlers.handleMouseLeave}>
<div
className="sidebar"
style={{ width }}
onMouseEnter={handlers.handleMouseEnter}
onMouseLeave={handlers.handleMouseLeave}
>
<div onMouseDown={handlers.handleMouseDown} className="dragger" />
<div className="sidebar-header">
<button onMouseEnter={handlers.handleMouseEnter} onClick={handlers.handleClick}>
<button onClick={handlers.handleClick}>
{isLocked ? (
<RiMenuFoldLine className="icon" />
) : isOpen ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
top: 0;
right: 0;

> div {
width: 4vh;
height: 4vh;
> button {
width: 5vh;
height: 5vh;
border-radius: 50%;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
padding: 1vh;
padding: 3vh;
margin: 1vh;

display: flex;
justify-content: center;
align-items: center;
font-size: 3vh;

a {
text-decoration: none !important;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
import useCollaborators from '@ui/pages/document/components/collaborators/useCollaborators';
import { Link } from 'react-router-dom';
import { useNavigate } from 'react-router-dom';
import './Collaborators.scss';

function Collaborators() {
const collaborators = useCollaborators();
const navigate = useNavigate();

function scrollIntoView(id: string) {
const target = document.getElementById(id);
if (target) {
target.scrollIntoView({ behavior: 'smooth' });
}
}

return (
<div className="collaborators">
{collaborators.map(collaborator => {
const nameParts = collaborator.name.split(' ');
const initials =
nameParts.length > 1 ? `${nameParts[0][0]}${nameParts[nameParts.length - 1][0]}` : nameParts[0][0];
return (
<div key={collaborator.id} title={collaborator.name} style={{ backgroundColor: collaborator.color }}>
<Link to={`/profile/${collaborator.id}`}>{initials}</Link>
</div>
<button
key={collaborator.id}
title={collaborator.name}
style={{ backgroundColor: collaborator.color }}
onClick={() => scrollIntoView(collaborator.socketId)}
onContextMenu={e => {
e.preventDefault();
navigate(`/profile/${collaborator.id}`);
}}
>
{initials}
</button>
);
})}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ import { InlineStyle } from '@notespace/shared/src/document/types/styles';
import './Cursor.scss';

type CursorProps = {
id: string;
color: string;
styles: InlineStyle[];
children: ReactNode;
};

function Cursor({ children, styles, color }: CursorProps) {
function Cursor({ children, styles, color, id }: CursorProps) {
const width = styles.includes('bold') ? '1.5px' : '1px';
const angle = styles.includes('italic') ? '11deg' : '0deg';
return (
<>
<span
id={id}
className="cursor"
style={{
outline: `${width} solid ${color}`,
Expand Down
10 changes: 3 additions & 7 deletions code/client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import tsconfigPaths from 'vite-tsconfig-paths';
import { config } from 'dotenv';
import {VitePWA} from "vite-plugin-pwa";
import pwaConfig from "./src/pwa/pwa-config";
import { VitePWA } from 'vite-plugin-pwa';
import pwaConfig from './src/pwa/pwa-config';

// Load environment variables from .env file
config();
Expand All @@ -16,11 +16,7 @@ export default defineConfig({
server: {
port: Number.parseInt(process.env.VITE_PORT) || 5173,
},
plugins: [
tsconfigPaths(),
react(),
VitePWA(pwaConfig)
],
plugins: [tsconfigPaths(), react(), VitePWA(pwaConfig)],
test: {
globals: true,
alias: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,4 @@ export default function errorMiddleware(error: Error, req: Request, res: Respons
const message = response.statusCode === 500 ? 'Internal server error' : error.message;
response.send({ error: message });
ErrorLogger.logError(error.message);
console.log('name', error.name);
console.error(error);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function getCursorColor(socketId: string) {
const randomColor = getRandomColor();
cursorColorsMap.set(socketId, randomColor);
}
return cursorColorsMap.get(socketId);
return cursorColorsMap.get(socketId)!;
}

function getRandomColor(): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import rooms from '@controllers/ws/rooms/rooms';
import { InvalidParameterError } from '@domain/errors/errors';
import { getUserFromSocket } from '@controllers/ws/utils';
import { getCursorColor } from '@controllers/ws/events/document/onCursorChange';
import { Collaborator } from '@notespace/shared/src/users/types';

function onJoinDocument() {
return function (socket: Socket, documentId: string) {
Expand All @@ -16,18 +17,20 @@ function onJoinDocument() {
rooms.documents.join(socket, documentId, user);

// broadcast to all clients in the document
socket.in(documentId).emit('joinedDocument', [{ ...user, color: getCursorColor(socket.id) }]);
const collaborator: Collaborator = { ...user, color: getCursorColor(socket.id), socketId: socket.id };
socket.in(documentId).emit('joinedDocument', [collaborator]);

// send the clients that are already in the document to the new client
const room = rooms.documents.getRoom(documentId)!;
const users = room
const collaborators: Collaborator[] = room
.getClients()
.map(client => ({
...client.user,
color: getCursorColor(client.socketId),
socketId: client.socketId,
}))
.filter(u => u.id !== user.id);
socket.emit('joinedDocument', users);
socket.emit('joinedDocument', collaborators);
};
}

Expand Down
1 change: 1 addition & 0 deletions code/shared/src/users/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export type User = UserData & {

export type Collaborator = UserData & {
color: string;
socketId: string;
};

0 comments on commit c39d2b4

Please sign in to comment.