Skip to content

Commit 92092e2

Browse files
authored
Merge pull request #54 from Eclipse-Dominator/fix-concurrent-access-to-edits
Decentralized initiation of shared values
2 parents 1481a2b + f0103e3 commit 92092e2

File tree

13 files changed

+663
-298
lines changed

13 files changed

+663
-298
lines changed

collab_service/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
"version": "1.0.0",
44
"description": "",
55
"main": "index.js",
6-
"type": "module",
76
"scripts": {
87
"test": "echo \"Error: no test specified\" && exit 1",
9-
"start": "node ./y-webrtc-signaling"
8+
"start": "y-webrtc-signaling"
109
},
1110
"keywords": [],
1211
"author": "",

collab_service/y-webrtc-signaling.js

Lines changed: 0 additions & 141 deletions
This file was deleted.

frontend/src/components/CollabEditor/CollabEditor.component.tsx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,34 @@ import {
77
EditorState,
88
EditorView,
99
Extension,
10-
ViewUpdate,
1110
basicSetup,
1211
} from "@uiw/react-codemirror";
1312
import { Flex } from "@chakra-ui/react";
1413
import { language, useSharedEditor } from "../../contexts/sharededitor.context";
1514

1615
const toLangSyntax = (lang: language) => {
1716
switch (lang) {
18-
case "C++17":
17+
case "c++17":
1918
return cpp();
20-
case "Python3":
19+
case "python3":
2120
return python();
22-
case "Java":
21+
case "java":
2322
return java();
2423
}
2524
};
2625

2726
const CollabEditor = () => {
2827
const editorRef = useRef<HTMLDivElement>(null);
29-
const { setCode, lang, codeUndo, ycode, provider } = useSharedEditor();
28+
const { lang, codeUndo, ycode, provider } = useSharedEditor();
3029

3130
useEffect(() => {
32-
if (!editorRef.current || !ycode || !codeUndo || !provider) return () => {}; // nothing to reset
31+
if (!editorRef.current || !ycode || !codeUndo || !provider || !lang)
32+
return () => {}; // nothing to reset
3333

3434
const extensions: Extension[] = [
3535
basicSetup(),
3636
toLangSyntax(lang),
37-
EditorView.updateListener.of((v: ViewUpdate) => {
38-
if (v.docChanged) {
39-
setCode(v.state.doc.toString());
40-
}
41-
}),
37+
EditorView.lineWrapping,
4238
yCollab(ycode, provider?.awareness, { undoManager: codeUndo }),
4339
];
4440

@@ -58,7 +54,7 @@ const CollabEditor = () => {
5854
editorRef.current.removeChild(view.dom);
5955
}
6056
};
61-
}, [editorRef, lang, provider]);
57+
}, [editorRef, lang, provider, ycode]);
6258

6359
return <Flex h="100%" w="100%" ref={editorRef}></Flex>;
6460
};

frontend/src/components/MatchMakeBtn/MatchMakeBtn.component.tsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { ChevronDownIcon } from "@chakra-ui/icons";
2-
import { Button, Menu, MenuButton, MenuItem, MenuList } from "@chakra-ui/react";
2+
import {
3+
Button,
4+
HStack,
5+
Menu,
6+
MenuButton,
7+
MenuItem,
8+
MenuList,
9+
Text,
10+
} from "@chakra-ui/react";
311
import { useMatchmake } from "../../contexts/matchmake.context";
412

513
const diffRange = [
@@ -9,12 +17,26 @@ const diffRange = [
917
[8, 9.9],
1018
];
1119

20+
const CollaborateBtn = () => {
21+
return (
22+
<HStack>
23+
<Text>In Room</Text>
24+
</HStack>
25+
);
26+
};
27+
1228
const MatchMakeBtn = () => {
13-
const { findMatch } = useMatchmake();
29+
const { findMatch, isMatching, matchedRoom } = useMatchmake();
1430

15-
return (
31+
return matchedRoom ? (
32+
<CollaborateBtn />
33+
) : (
1634
<Menu>
17-
<MenuButton as={Button} rightIcon={<ChevronDownIcon />}>
35+
<MenuButton
36+
as={Button}
37+
rightIcon={<ChevronDownIcon />}
38+
isLoading={isMatching}
39+
>
1840
Collaborate
1941
</MenuButton>
2042
<MenuList>

frontend/src/components/Navbar/Navbar.component.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ export const Navbar = () => {
1616
const isAdmin = useSelector(selectIsAdmin);
1717

1818
return (
19-
<chakra.header boxShadow={"md"} minH="10vh" zIndex="999">
20-
<Flex w="100%" px="6" py="2vh" align={"center"} justify={"space-between"}>
19+
<chakra.header boxShadow="md" minH="10vh" zIndex="2" pos="sticky">
20+
{/* chakra dont recomment zindex > 2 */}
21+
<Flex w="100%" px="6" py="2vh" align="center" justify="space-between">
2122
<HStack spacing="4px">
2223
<Link to="/">
2324
<Button colorScheme="linkedin" variant="outline">

frontend/src/components/QnSubmissionHistory/QnSubmissionHistory.component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const QnSubmissionHistory = () => {
7575
position="sticky"
7676
top={0}
7777
bg="gray.200"
78-
zIndex={1}
78+
zIndex="1"
7979
boxShadow="base"
8080
>
8181
<Tr>

frontend/src/components/QnTable/QuestionEntry.component.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function QuestionEntry(props : QuestionEntryProps) {
2424
}
2525

2626
return (
27-
<Tr>
27+
<Tr key={qn.id}>
2828
<Td>
2929
<Link to={`/view/${qn._id}`}>
3030
<Text>{qn.displayedQuestion}</Text>
@@ -49,7 +49,10 @@ export function QuestionEntry(props : QuestionEntryProps) {
4949
icon={<EditIcon />}
5050
></IconButton>
5151
</Link>
52-
<DeleteQnBtn qn={qn} onSubmit={() => onDelete(qn._id)}></DeleteQnBtn>
52+
<DeleteQnBtn
53+
qn={qn}
54+
onSubmit={() => onDelete(qn._id)}
55+
></DeleteQnBtn>
5356
</ButtonGroup>
5457
</Td>
5558
) : (

frontend/src/contexts/matchmake.context.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import { useToast } from "@chakra-ui/react";
1313

1414
interface RoomDetail {
1515
partner: string;
16-
host: string;
16+
init: boolean;
1717
qn: string;
18+
room: string;
1819
}
1920

2021
interface MatchmakeContextInterface {

0 commit comments

Comments
 (0)