Skip to content

Commit 27dbaa2

Browse files
committed
added explanations in ModifiedTable
1 parent 577d659 commit 27dbaa2

File tree

1 file changed

+121
-24
lines changed

1 file changed

+121
-24
lines changed

src/features/components/nfaToDfa/ModifiedTable.tsx

Lines changed: 121 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
Alert,
23
Box,
34
Button,
45
ButtonGroup,
@@ -8,6 +9,7 @@ import {
89
MenuItem,
910
Select,
1011
SelectChangeEvent,
12+
Snackbar,
1113
} from "@mui/material";
1214
import { GridColumns } from "@mui/x-data-grid";
1315
import { useContext, useEffect, useState } from "react";
@@ -75,26 +77,31 @@ export const ModifiedTable = (props: ModifiedTableProps) => {
7577

7678
const [open, setOpen] = useState(1);
7779

80+
const [showExplanation, setShowExplanation] = useState(false);
81+
const [openSnackbar, setOpenSnackbar] = useState(false);
82+
const [snackbarMessage, setSnackbarMessage] = useState("");
83+
7884
useEffect(() => {
7985
if (isPlaying) {
8086
let timer = setTimeout(() => {
81-
console.log("inside set timeout, index", index);
82-
const rowIndex = Math.floor(index / numberOfColumns);
87+
if (!showExplanation) {
88+
console.log("inside set timeout, index", index);
89+
const rowIndex = Math.floor(index / numberOfColumns);
8390

84-
handleUpdateData(rowIndex, props.rows.slice(0, rowIndex));
91+
handleUpdateData(rowIndex, props.rows.slice(0, rowIndex));
8592

86-
// stop if all rows have been displayed i.e., if rowIndex equals rows length and last row's last column has been displayed
87-
if (
88-
rowIndex === props.rows.length &&
89-
index % numberOfColumns === numberOfColumns - 1
90-
) {
91-
setIsComplete(true);
92-
setIsPlaying(false);
93-
} else index++;
93+
// stop if all rows have been displayed
94+
if (rowIndex > props.rows.length && index % numberOfColumns === 0) {
95+
setIsComplete(true);
96+
setIsPlaying(false);
97+
handleExplanation();
98+
}
99+
index++;
100+
} else handleExplanation();
94101
}, duration * 1000);
95102
return () => clearTimeout(timer);
96103
}
97-
}, [props, modifiedTableRows, isPlaying]);
104+
}, [props, modifiedTableRows, isPlaying, showExplanation]);
98105

99106
const handleUpdateData = (rowIndex: number, rows: RowModel[]) => {
100107
setModifiedTableRowId(rowIndex);
@@ -160,6 +167,72 @@ export const ModifiedTable = (props: ModifiedTableProps) => {
160167
};
161168
})
162169
);
170+
setShowExplanation(true);
171+
};
172+
173+
const handleExplanation = () => {
174+
let openSnackbar = true;
175+
if (index % numberOfColumns === 1)
176+
setSnackbarMessage(
177+
`Added state ${modifiedTableRows?.[
178+
modifiedTableRowId - 1
179+
]?.state?.replaceAll(ModifiedTableStateId, "")}.`
180+
);
181+
else if (index % numberOfColumns === 2)
182+
dataContext?.rows?.[modifiedTableRowId - 1]?.a
183+
? setSnackbarMessage(
184+
dataContext?.rows?.[modifiedTableRowId - 1]?.a
185+
? `Updated ${
186+
dataContext?.rows?.[modifiedTableRowId - 1]?.a
187+
} with its null closure i.e., {${dataContext?.rows?.[
188+
modifiedTableRowId - 1
189+
]?.a
190+
?.split(" ")
191+
.map((s) =>
192+
props.nullClosureRows
193+
?.find(
194+
(r) => r.state.replaceAll(NullClosureStateId, "") === s
195+
)
196+
?.nul?.replaceAll(NullClosureStateId, "")
197+
)
198+
.join(", ")}}`
199+
: ""
200+
)
201+
: (openSnackbar = false);
202+
else
203+
dataContext?.rows?.[modifiedTableRowId - 1]?.b
204+
? setSnackbarMessage(
205+
dataContext?.rows?.[modifiedTableRowId - 1]?.b
206+
? `Updated ${
207+
dataContext?.rows?.[modifiedTableRowId - 1]?.b
208+
} with its null closure i.e., {${dataContext?.rows?.[
209+
modifiedTableRowId - 1
210+
]?.b
211+
?.split(" ")
212+
.map((s) =>
213+
props.nullClosureRows
214+
?.find(
215+
(r) => r.state.replaceAll(NullClosureStateId, "") === s
216+
)
217+
?.nul?.replaceAll(NullClosureStateId, "")
218+
)
219+
.join(", ")}}`
220+
: ""
221+
)
222+
: (openSnackbar = false);
223+
224+
setOpenSnackbar(openSnackbar);
225+
setShowExplanation(false);
226+
};
227+
228+
const handleSnackbarClose = (
229+
event: React.SyntheticEvent | Event,
230+
reason?: string
231+
) => {
232+
if (reason === "clickaway") {
233+
return;
234+
}
235+
setOpenSnackbar(false);
163236
};
164237

165238
const handleDurationChange = (event: SelectChangeEvent) => {
@@ -176,20 +249,24 @@ export const ModifiedTable = (props: ModifiedTableProps) => {
176249
};
177250

178251
const showNextRow = () => {
179-
const rowIndex = Math.floor(index / numberOfColumns);
180-
if (isComplete) {
181-
setIsReady(true);
182-
props.setRows(modifiedTableRows);
183-
props.setIsModifiedTransitionTableComplete(true);
184-
}
252+
if (!showExplanation) {
253+
const rowIndex = Math.floor(index / numberOfColumns);
254+
if (isComplete) {
255+
setIsReady(true);
256+
props.setRows(modifiedTableRows);
257+
props.setIsModifiedTransitionTableComplete(true);
258+
}
185259

186-
handleUpdateData(rowIndex, props.rows.slice(0, rowIndex));
260+
handleUpdateData(rowIndex, props.rows.slice(0, rowIndex));
187261

188-
// stop if all rows have been displayed i.e., if rowIndex equals rows length and last row's last column has been displayed
189-
if (rowIndex === props.rows.length && index % numberOfColumns !== 0) {
190-
setIsComplete(true);
191-
setIsPlaying(false);
192-
} else index++;
262+
// stop if all rows have been displayed
263+
if (rowIndex > props.rows.length && index % numberOfColumns === 0) {
264+
setIsComplete(true);
265+
setIsPlaying(false);
266+
handleExplanation();
267+
}
268+
index++;
269+
} else handleExplanation();
193270
};
194271

195272
const transitionTableProps: ToolsTransitionTableProps = {
@@ -229,6 +306,26 @@ export const ModifiedTable = (props: ModifiedTableProps) => {
229306
return (
230307
<>
231308
<Box sx={{ display: "flex", m: 1, mt: 5 }}>
309+
<Snackbar
310+
open={openSnackbar}
311+
autoHideDuration={
312+
isPlaying ? duration * 1000 : duration * 1000 * 1000
313+
}
314+
onClose={handleSnackbarClose}
315+
anchorOrigin={{
316+
vertical: "bottom",
317+
horizontal: "center",
318+
}}
319+
>
320+
<Alert
321+
onClose={handleSnackbarClose}
322+
severity="info"
323+
sx={{ width: "100%" }}
324+
>
325+
{snackbarMessage}
326+
</Alert>
327+
</Snackbar>
328+
232329
<AppBarAndDrawer {...appBarAndDrawerProps} />
233330

234331
<MainContent open={open} sx={{ paddingBottom: 12 }}>

0 commit comments

Comments
 (0)