Skip to content

Commit 3d1aaec

Browse files
committed
PEER-234: Add userId
Signed-off-by: SeeuSim <[email protected]>
1 parent 957b009 commit 3d1aaec

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

frontend/entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/sh
22

3-
envsubst '${FRONTEND_PORT} ${VITE_USER_SERVICE} ${VITE_QUESTION_SERVICE} ${VITE_COLLAB_SERVICE} ${VITE_COLLAB_WS} ${VITE_MATCHING}' < /etc/nginx/nginx.conf.template > /etc/nginx/conf.d/default.conf
3+
envsubst '${FRONTEND_PORT} ${VITE_USER_SERVICE} ${VITE_QUESTION_SERVICE} ${VITE_COLLAB_SERVICE} ${VITE_COLLAB_WS} ${VITE_MATCHING_SERVICE}' < /etc/nginx/nginx.conf.template > /etc/nginx/conf.d/default.conf
44

55
nginx -g 'daemon off;'

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
"@radix-ui/react-separator": "^1.1.0",
2424
"@radix-ui/react-slot": "^1.1.0",
2525
"@radix-ui/react-tabs": "^1.1.0",
26-
"@replit/codemirror-vscode-keymap": "^6.0.2",
2726
"@radix-ui/react-visually-hidden": "^1.1.0",
27+
"@replit/codemirror-vscode-keymap": "^6.0.2",
2828
"@tanstack/react-query": "^5.56.2",
2929
"@tanstack/react-query-devtools": "^5.56.2",
3030
"@tanstack/react-table": "^8.20.5",

frontend/src/components/blocks/interview/editor.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { ChevronLeftIcon } from '@radix-ui/react-icons';
12
import { useWindowSize } from '@uidotdev/usehooks';
23
import type { LanguageName } from '@uiw/codemirror-extensions-langs';
34
import CodeMirror from '@uiw/react-codemirror';
45
import { useMemo, useState } from 'react';
56

7+
import { Button } from '@/components/ui/button';
68
import { Label } from '@/components/ui/label';
79
import {
810
Select,
@@ -13,8 +15,6 @@ import {
1315
} from '@/components/ui/select';
1416
import { getTheme, type IEditorTheme, languages, themeOptions } from '@/lib/editor/extensions';
1517
import { useCollab } from '@/lib/hooks/use-collab';
16-
import { Button } from '@/components/ui/button';
17-
import { ChevronLeftIcon } from '@radix-ui/react-icons';
1818

1919
const EXTENSION_HEIGHT = 250;
2020
const MIN_EDITOR_HEIGHT = 350;
@@ -77,7 +77,7 @@ export const Editor = ({ room }: EditorProps) => {
7777
}}
7878
key={index}
7979
>
80-
<span className='translate-x-[calc(-50%+12px)]'>{member.name}</span>
80+
<span className='translate-x-[calc(-50%+12px)]'>{member.userId}</span>
8181
</div>
8282
))}
8383
</div>

frontend/src/lib/hooks/use-collab.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as Y from 'yjs';
77

88
import { extensions as baseExtensions, getLanguage } from '@/lib/editor/extensions';
99
import { COLLAB_WS } from '@/services/api-clients';
10+
import { getUserId } from '@/services/user-service';
1011

1112
// credit: https://github.com/yjs/y-websocket
1213
const usercolors = [
@@ -28,6 +29,7 @@ type IYjsUserState = { user: { name: string; userId: string; color: string; colo
2829

2930
// TODO: Test if collab logic works
3031
export const useCollab = (roomId: string) => {
32+
const [userId] = useState(getUserId());
3133
const [code, setCode] = useState('');
3234
const editorRef = useRef<ReactCodeMirrorRef>(null);
3335
const [extensions, setExtensions] = useState<Array<Extension>>(baseExtensions);
@@ -44,6 +46,7 @@ export const useCollab = (roomId: string) => {
4446
if (editorRef.current) {
4547
const doc = new Y.Doc();
4648
let provider = null;
49+
4750
try {
4851
provider = new WebsocketProvider(COLLAB_WS, roomId, doc);
4952
provider.connect();
@@ -54,6 +57,7 @@ export const useCollab = (roomId: string) => {
5457
);
5558
return;
5659
}
60+
5761
const ytext = doc.getText('codemirror');
5862
const undoManager = new Y.UndoManager(ytext);
5963
const awareness = provider.awareness;
@@ -72,7 +76,7 @@ export const useCollab = (roomId: string) => {
7276
// TODO: Get user name, ID
7377
const userState: IYjsUserState['user'] = {
7478
name: `Anon`,
75-
userId: '',
79+
userId: userId ?? 'null',
7680
color,
7781
colorLight: light,
7882
};
@@ -81,12 +85,14 @@ export const useCollab = (roomId: string) => {
8185
const collabExt = yCollab(ytext, awareness, { undoManager });
8286
setCode(ytext.toString());
8387
setExtensions([...extensions, collabExt]);
88+
8489
return () => {
8590
doc.destroy();
86-
provider.disconnect();
91+
provider.destroy();
8792
};
8893
}
8994
}, [editorRef, roomId]);
95+
9096
return {
9197
editorRef,
9298
extensions: [...extensions, langExtension],

0 commit comments

Comments
 (0)