Skip to content

Commit

Permalink
fixed bug
Browse files Browse the repository at this point in the history
  • Loading branch information
HETTski committed Aug 12, 2024
1 parent fc56c78 commit 266eb2f
Showing 1 changed file with 0 additions and 43 deletions.
43 changes: 0 additions & 43 deletions src/components/CodeEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,69 +27,26 @@ const CodeEditor = ({ onExecute, isError }) => {
}, [visibleIndex]);
// local storage things

const [code, setCode] = useState(() => {
const savedCode = localStorage.getItem("code");
return savedCode !== null
? JSON.parse(savedCode)
: ["/* Kod idzie tutaj */"];
});

useEffect(() => {
localStorage.setItem("code", JSON.stringify(code));
}, [code]);

const [visibleIndex, setVisibleIndex] = useState(() => {
const savedIndex = localStorage.getItem("visibleIndex");
return savedIndex !== null ? JSON.parse(savedIndex) : 0;
});

useEffect(() => {
localStorage.setItem("visibleIndex", JSON.stringify(visibleIndex));
}, [visibleIndex]);
// local storage things


const handleVisibility = (index) => {
setVisibleIndex(index);
};
const handleVisibility = (index) => {
setVisibleIndex(index);
};

const handleTextChange = (value, index) => {
const newCode = [...code];
newCode[index] = value;
setCode(newCode);
};
const handleTextChange = (value, index) => {
const newCode = [...code];
newCode[index] = value;
setCode(newCode);
};

const handleExecute = () => {
onExecute(code[visibleIndex]);
};
const handleExecute = () => {
onExecute(code[visibleIndex]);
};

const addTextarea = () => {
setCode([...code, ""]);
setVisibleIndex(code.length);
};
const addTextarea = () => {
setCode([...code, ""]);
setVisibleIndex(code.length);
};

const removeTextarea = () => {
if (code.length > 1) {
const newCode = code.slice(0, -1);
setCode(newCode);
setVisibleIndex(newCode.length - 1);
}
};
const removeTextarea = () => {
if (code.length > 1) {
const newCode = code.slice(0, -1);
Expand Down

0 comments on commit 266eb2f

Please sign in to comment.