Add save function
This commit is contained in:
@@ -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}>$ </span>
|
||||
<div className={styles.wrapper}>
|
||||
|
||||
Reference in New Issue
Block a user