1
1
/* eslint-disable max-len */
2
- import React , { useState , useEffect , useRef } from 'react' ;
2
+ import React , { useState , useRef } from 'react' ;
3
3
import { Button } from '@mui/material' ;
4
+ import ListItem from '@mui/material/ListItem' ;
5
+ import List from '@mui/material/List' ;
6
+ import ListItemText from '@mui/material/ListItemText' ;
4
7
import { useDispatch , useSelector } from 'react-redux' ;
5
- import {
6
- DeveloperMode ,
7
- VerticalAlignBottom ,
8
- VerticalAlignTop ,
9
- ZoomIn ,
10
- ZoomOut ,
11
- } from '@mui/icons-material' ;
8
+ import { DeveloperMode , ZoomIn , ZoomOut } from '@mui/icons-material' ;
12
9
import Canvas from './Canvas' ;
13
10
import { RootState } from '../../redux/store' ;
14
11
import CodePreview from '../bottom/CodePreview' ;
15
12
import { toggleCodePreview } from '../../redux/reducers/slice/appStateSlice' ;
13
+ import createModal from '../right/createModal' ;
14
+ import { resetAllState } from '../../redux/reducers/slice/appStateSlice' ;
15
+ import { emitEvent } from '../../helperFunctions/socket' ;
16
16
17
17
interface CanvasContainerProps {
18
18
zoom : number ;
@@ -55,8 +55,8 @@ function CanvasContainer(props: CanvasContainerProps): JSX.Element {
55
55
// containerRef references the container that will ultimately have the scroll functionality
56
56
const containerRef = useRef < HTMLDivElement > ( null ) ;
57
57
58
- const container = document . getElementById ( 'canvasContainer' ) ;
59
- const components = document . querySelector ( '.componentContainer' ) ;
58
+ // const container = document.getElementById('canvasContainer');
59
+ // const components = document.querySelector('.componentContainer');
60
60
61
61
const [ zoom , setZoom ] = useState ( 1 ) ;
62
62
@@ -68,19 +68,54 @@ function CanvasContainer(props: CanvasContainerProps): JSX.Element {
68
68
setZoom ( Math . max ( zoom - 0.1 , 0.1 ) ) ;
69
69
} ;
70
70
71
- // useEffect dependency is the length of the parent components. No changes in children will scroll to the bottom. Once elements surpass the view of the canvas, scroll to bottom, else, keep scroll bar to the top.
72
- useEffect ( ( ) => {
73
- if (
74
- container &&
75
- components &&
76
- state . components [ 0 ] . children . length > 0 &&
77
- components . scrollHeight === components . clientHeight
78
- ) {
79
- container . scrollTop = 0 ;
80
- } else if ( container && components ) {
81
- container . scrollTop = container . scrollHeight ;
82
- }
83
- } , [ state . components [ 0 ] . children . length , zoom ] ) ;
71
+ const [ modal , setModal ] = React . useState ( null ) ;
72
+ const roomCode = useSelector ( ( store : RootState ) => store . roomSlice . roomCode ) ;
73
+ const userName = useSelector ( ( store : RootState ) => store . roomSlice . userName ) ;
74
+
75
+ const closeModal = ( ) => setModal ( '' ) ;
76
+ const clearWorkspace = ( ) => {
77
+ // Reset state for project to initial state
78
+ const resetState = ( ) => {
79
+ if ( roomCode ) emitEvent ( 'clearCanvasAction' , roomCode , userName ) ;
80
+ else dispatch ( resetAllState ( ) ) ;
81
+ } ;
82
+ // Set modal options
83
+ const children = (
84
+ < List className = "export-preference" style = { { zIndex : '12' } } >
85
+ < ListItem
86
+ key = { 'clear' }
87
+ button
88
+ onClick = { resetState }
89
+ style = { {
90
+ backgroundColor : '#E12D39' ,
91
+ borderRadius : '50px' ,
92
+ marginBottom : '2%' ,
93
+ marginTop : '5%' ,
94
+ } }
95
+ >
96
+ < ListItemText
97
+ primary = { 'Yes, delete all project data' }
98
+ style = { { textAlign : 'center' } }
99
+ onClick = { closeModal }
100
+ />
101
+ </ ListItem >
102
+ </ List >
103
+ ) ;
104
+
105
+ // Create modal
106
+ setModal (
107
+ createModal ( {
108
+ closeModal,
109
+ children,
110
+ message : 'Are you sure you want to delete all data?' ,
111
+ primBtnLabel : null ,
112
+ primBtnAction : null ,
113
+ secBtnAction : null ,
114
+ secBtnLabel : null ,
115
+ open : true ,
116
+ } ) ,
117
+ ) ;
118
+ } ;
84
119
85
120
const buttonStyle : React . CSSProperties = {
86
121
textAlign : 'center' ,
@@ -97,11 +132,11 @@ function CanvasContainer(props: CanvasContainerProps): JSX.Element {
97
132
borderRadius : '10px' ,
98
133
} as const ;
99
134
100
- const upArrowStyle : React . CSSProperties = {
135
+ const firstButtonStyle : React . CSSProperties = {
101
136
borderRadius : '10px 0 0 10px' ,
102
137
} as const ;
103
138
104
- const zoomOutStyle : React . CSSProperties = {
139
+ const lastButtonStyle : React . CSSProperties = {
105
140
borderRadius : '0 10px 10px 0' ,
106
141
} as const ;
107
142
@@ -125,31 +160,24 @@ function CanvasContainer(props: CanvasContainerProps): JSX.Element {
125
160
</ Button >
126
161
{ ! state . codePreview && (
127
162
< div >
128
- < Button
129
- style = { { ...buttonStyle , ...upArrowStyle } }
130
- onClick = { ( ) => {
131
- container . scrollTop = 0 ;
132
- } }
133
- >
134
- < VerticalAlignTop />
135
- </ Button >
136
- < Button
137
- style = { buttonStyle }
138
- onClick = { ( ) => {
139
- container . scrollTop = container . clientHeight ;
140
- } }
141
- >
142
- < VerticalAlignBottom />
143
- </ Button >
144
- < Button style = { buttonStyle } onClick = { zoomIn } >
163
+ < Button style = { { ...buttonStyle , ...firstButtonStyle } } onClick = { zoomIn } >
145
164
< ZoomIn />
146
165
</ Button >
147
- < Button
148
- style = { { ...buttonStyle , ...zoomOutStyle } }
149
- onClick = { zoomOut }
150
- >
166
+ < Button style = { buttonStyle } onClick = { zoomOut } >
151
167
< ZoomOut />
152
168
</ Button >
169
+ < Button style = { { ...buttonStyle , ...lastButtonStyle } } onClick = { ( ) => clearWorkspace ( ) } >
170
+ < svg
171
+ xmlns = "http://www.w3.org/2000/svg"
172
+ width = "16"
173
+ height = "16"
174
+ fill = "currentColor"
175
+ className = "bi bi-trash3"
176
+ viewBox = "0 0 16 16"
177
+ >
178
+ < path d = "M6.5 1h3a.5.5 0 0 1 .5.5v1H6v-1a.5.5 0 0 1 .5-.5ZM11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3A1.5 1.5 0 0 0 5 1.5v1H2.506a.58.58 0 0 0-.01 0H1.5a.5.5 0 0 0 0 1h.538l.853 10.66A2 2 0 0 0 4.885 16h6.23a2 2 0 0 0 1.994-1.84l.853-10.66h.538a.5.5 0 0 0 0-1h-.995a.59.59 0 0 0-.01 0H11Zm1.958 1-.846 10.58a1 1 0 0 1-.997.92h-6.23a1 1 0 0 1-.997-.92L3.042 3.5h9.916Zm-7.487 1a.5.5 0 0 1 .528.47l.5 8.5a.5.5 0 0 1-.998.06L5 5.03a.5.5 0 0 1 .47-.53Zm5.058 0a.5.5 0 0 1 .47.53l-.5 8.5a.5.5 0 1 1-.998-.06l.5-8.5a.5.5 0 0 1 .528-.47ZM8 4.5a.5.5 0 0 1 .5.5v8.5a.5.5 0 0 1-1 0V5a.5.5 0 0 1 .5-.5Z" />
179
+ </ svg >
180
+ </ Button >
153
181
</ div >
154
182
) }
155
183
</ div >
0 commit comments