Skip to content

Commit

Permalink
Restore console code after page reloads (#75)
Browse files Browse the repository at this point in the history
* restore console code after page reload, button to reset console to initial state

* fix
  • Loading branch information
trean authored Jul 7, 2023
1 parent cb951c9 commit 944da28
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/components/CodeEditorWindow/Menu/SpeedDialMenu.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from "react";
import PropTypes from "prop-types";
import Box from "@mui/material/Box";
import SpeedDial from "@mui/material/SpeedDial";
import Bolt from "@mui/icons-material/Bolt";
import SpeedDialAction from "@mui/material/SpeedDialAction";
import SaveIcon from "@mui/icons-material/Save";
import HistoryRounded from "@mui/icons-material/HistoryRounded";
import RestartAlt from "@mui/icons-material/RestartAlt";

function SpeedDialMenu({ openSavedCode, openHistory }) {
function SpeedDialMenu({ openSavedCode, openHistory, resetConsole }) {
const [open, setOpen] = React.useState(false);
const handleOpen = () => setOpen(true);
const handleClose = () => setOpen(false);
Expand Down Expand Up @@ -36,6 +36,13 @@ function SpeedDialMenu({ openSavedCode, openHistory }) {
tooltipOpen
onClick={openHistory}
/>
<SpeedDialAction
key={"Reset"}
icon={<RestartAlt/>}
tooltipTitle={"Reset"}
tooltipOpen
onClick={resetConsole}
/>
</SpeedDial>
);
}
Expand All @@ -44,6 +51,7 @@ function SpeedDialMenu({ openSavedCode, openHistory }) {
SpeedDialMenu.propTypes = {
openSavedCode: PropTypes.func,
openHistory: PropTypes.func,
resetConsole: PropTypes.func,
};

export default SpeedDialMenu;
8 changes: 5 additions & 3 deletions src/pages/Console.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Box from "@mui/material/Box";
import { Typography, Grid } from "@mui/material";
import ErrorNotifier from "../components/ToastNotifications/ErrorNotifier";
import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
import Menu from "../components/CodeEditorWindow/Menu";
import CodeEditorWindow from "../components/CodeEditorWindow";
import ResultEditorWindow from "../components/ResultEditorWindow";
import SpeedDialMenu from "../components/CodeEditorWindow/Menu/SpeedDialMenu";
Expand Down Expand Up @@ -43,7 +42,7 @@ const defaultResult = `{}`;

function Console() {
const theme = useTheme();
const [code, setCode] = useState(query);
const [code, setCode] = useState( localStorage.getItem('qwuiConsoleCode') ?? query);
const [result, setResult] = useState(defaultResult);
const [errorMessage, setErrorMessage] = useState(null);

Expand All @@ -53,6 +52,7 @@ function Console() {
const onChangeCode = (action, data) => {
switch (action) {
case "code": {
localStorage.setItem("qwuiConsoleCode", data);
setCode(data);
break;
}
Expand Down Expand Up @@ -114,7 +114,9 @@ function Console() {
</Grid>
<SpeedDialMenu
openHistory={() => setOpenHistory(true)}
openSavedCode={() => setOpenSavedCode(true)}/>
openSavedCode={() => setOpenSavedCode(true)}
resetConsole={() => onChangeCode("code", query)}
/>
<History
code={code}
handleEditorChange={onChangeCode}
Expand Down

0 comments on commit 944da28

Please sign in to comment.