Add save function

This commit is contained in:
Daniel Kluge
2022-06-21 18:44:20 +02:00
parent de0e758ebb
commit 9531ab7006
10 changed files with 99 additions and 30 deletions
+15 -3
View File
@@ -1,8 +1,8 @@
import type { NextPage } from "next";
import { MutableRefObject, useState, createRef } from "react";
import { MutableRefObject, useState, createRef, useEffect } from "react";
import { CommandInterface } from "../../lib/commands";
import styles from "../../styles/REPL/REPLInput.module.css";
import { useCommands } from "../contexts/CommandInterface";
import { useCommands } from "../../lib/commands/ContextProvider";
import { useModalFunctions } from "../contexts/ModalFunctions";
interface REPLInputParams {
@@ -19,9 +19,11 @@ const REPLInput: NextPage<REPLInputParams> = ({historyCallback, historyClear, in
const [inCmdHistory, setInCmdHistory] = useState<number>(-1);
const [cmdHistory, setCmdHistory] = useState<string[]>([]);
const [usrInputTmp, setUsrInputTmp] = useState<string>("");
const {cmdContext: cmdIf} = useCommands();
const {cmdContext: cmdIf, updateCallbacks} = useCommands();
const { modalFunctions } = useModalFunctions();
updateCallbacks({ getCmdHistory: () => cmdHistory });
const setInput = (inputRef: HTMLInputElement, input: string) => {
const nativeSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value")?.set;
if (!nativeSetter) return;
@@ -145,6 +147,16 @@ const REPLInput: NextPage<REPLInputParams> = ({historyCallback, historyClear, in
}
};
useEffect(() => {
if (!window || !cmdIf) return;
const color = window.localStorage.getItem("color");
if(color) cmdIf.executeCommand(`color ${color}`);
const history = window.localStorage.getItem("history");
try {
if (history) setCmdHistory(JSON.parse(history));
} catch {}
}, [cmdIf]);
return <div className={styles.wrapperwrapper}>
<span className={styles.inputstart}>$&nbsp;</span>
<div className={styles.wrapper}>