Skip to content

Commit f12418a

Browse files
committed
Most up-to-date Dev w/ Lauren changes + Working toggle switch + Addevent router
1 parent 483c438 commit f12418a

File tree

1 file changed

+39
-13
lines changed

1 file changed

+39
-13
lines changed

app/src/components/main/Canvas.tsx

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,18 @@ function Canvas(props: {}): JSX.Element {
2727
//-------cursors tracking-------
2828
console.log('canvas is rendered');
2929

30+
//remote cursor data
3031
const [remoteCursors, setRemoteCursors] = useState([]);
32+
33+
// toggle switch
3134
const [toggleSwitch, setToggleSwitch] = useState(true);
3235

36+
// toggle text
37+
const [toggleText, setToggleText] = useState('off');
38+
const toggleButton = () => {
39+
setToggleText(toggleText === 'on' ? 'off' : 'on');
40+
};
41+
3342
const debounceSetPosition = debounce((newX, newY) => {
3443
//emit socket event every 300ms when cursor moves
3544
if (userList.length > 1)
@@ -125,6 +134,12 @@ function Canvas(props: {}): JSX.Element {
125134

126135
console.log('Toggle Switch:', toggleSwitch);
127136

137+
//Function to handle the click events.
138+
const multipleClicks = () => {
139+
handleToggleSwitch();
140+
toggleButton();
141+
};
142+
128143
const socket = getSocket();
129144
//wrap the socket event listener in useEffect with dependency array as [socket], so the the effect will run only when: 1. After the initial rendering of the component 2. Every time the socket instance changes(connect, disconnect)
130145
useEffect(() => {
@@ -169,7 +184,7 @@ function Canvas(props: {}): JSX.Element {
169184
childId?: number | null
170185
) => {
171186
dispatch(changeFocus({ componentId, childId }));
172-
//if room exists, send focus dispatcht to all users
187+
//if room exists, send focus dispatch to all users
173188
if (roomCode) {
174189
emitEvent('changeFocusAction', roomCode, {
175190
componentId: componentId,
@@ -350,18 +365,29 @@ function Canvas(props: {}): JSX.Element {
350365
)
351366
)}
352367

353-
<label
354-
className="switch"
355-
style={{
356-
position: 'relative',
357-
display: 'inline-block',
358-
width: '60px',
359-
height: '34px'
360-
}}
361-
>
362-
<button className="btn-toggle" onClick={handleToggleSwitch}>
363-
On/Off
364-
</button>
368+
<label className="switch">
369+
{userList.length > 1 && (
370+
<button
371+
className="btn-toggle"
372+
onClick={multipleClicks}
373+
style={{
374+
position: 'fixed',
375+
width: 'max-content',
376+
height: 'max-content',
377+
bottom: '100px',
378+
left: '51vw',
379+
textAlign: 'center',
380+
color: '#FFFFFF',
381+
backgroundColor: '#151515',
382+
zIndex: 0,
383+
padding: '5px',
384+
borderColor: '#46C0A5',
385+
borderRadius: '5px'
386+
}}
387+
>
388+
{toggleText === 'on' ? 'View Cursors' : 'Hide Cursors'}
389+
</button>
390+
)}
365391
</label>
366392
</div>
367393
);

0 commit comments

Comments
 (0)