-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented Document Collaborators & Added Fixes
- Loading branch information
1 parent
84e3cf5
commit ab10f70
Showing
28 changed files
with
242 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.document { | ||
position: relative; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
code/client/src/ui/pages/document/components/collaborators/Collaborators.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.collaborators { | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
|
||
> div { | ||
width: 4vh; | ||
height: 4vh; | ||
border-radius: 50%; | ||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3); | ||
padding: 1vh; | ||
margin: 1vh; | ||
|
||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
|
||
a { | ||
text-decoration: none !important; | ||
color: white; | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
code/client/src/ui/pages/document/components/collaborators/Collaborators.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import useCollaborators from '@ui/pages/document/components/collaborators/useCollaborators'; | ||
import { Link } from 'react-router-dom'; | ||
import './Collaborators.scss'; | ||
|
||
function Collaborators() { | ||
const collaborators = useCollaborators(); | ||
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> | ||
); | ||
})} | ||
</div> | ||
); | ||
} | ||
|
||
export default Collaborators; |
26 changes: 26 additions & 0 deletions
26
code/client/src/ui/pages/document/components/collaborators/useCollaborators.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useState } from 'react'; | ||
import { Collaborator } from '@notespace/shared/src/users/types'; | ||
import useSocketListeners from '@services/communication/socket/useSocketListeners'; | ||
import { useCommunication } from '@/contexts/communication/useCommunication'; | ||
|
||
function useCollaborators() { | ||
const [collaborators, setCollaborators] = useState<Collaborator[]>([]); | ||
const { socket } = useCommunication(); | ||
|
||
const onCollaboratorsJoined = (users: Collaborator[]) => { | ||
setCollaborators(prev => [...prev, ...users]); | ||
}; | ||
|
||
const onCollaboratorLeft = (id: string) => { | ||
setCollaborators(prev => prev.filter(u => u.id !== id)); | ||
}; | ||
|
||
useSocketListeners(socket, { | ||
joinedDocument: onCollaboratorsJoined, | ||
leftDocument: onCollaboratorLeft, | ||
}); | ||
|
||
return collaborators; | ||
} | ||
|
||
export default useCollaborators; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 23 additions & 1 deletion
24
code/server/src/controllers/ws/events/document/onJoinDocument.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 10 additions & 1 deletion
11
code/server/src/controllers/ws/events/document/onLeaveDocument.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.