Skip to content

Commit

Permalink
wrk n save code
Browse files Browse the repository at this point in the history
  • Loading branch information
pr-a-s-h-a-n-t committed Apr 7, 2023
1 parent 33acc3a commit 07f4dd6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
13 changes: 7 additions & 6 deletions jarvis/src/components/Editor/EditContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ function EditContainer({
isFullScreen,
setIsFullScreen,
getFile,
currentInput,
setCurrentInput,
}) {
// const { openModal } = useContext(ModalContext);
const themeOptions = [
Expand Down Expand Up @@ -87,7 +89,7 @@ function EditContainer({
// save the current code to local storage!

console.log(currentCode, " this is currentCode");
localStorage.setItem("code", currentCode);
localStorage.setItem("code", JSON.stringify(currentCode));
}

return (
Expand Down Expand Up @@ -138,8 +140,7 @@ function EditContainer({
setCurrentCode={setCurrentCode}
isFullScreen={isFullScreen}
/>
{/* Home work */}
{/* Foooter */}

<div className="bg-white flex w-full justify-between p-4">
<button
className="flex gap-3 items-center"
Expand All @@ -149,13 +150,13 @@ function EditContainer({
{isFullScreen ? "Minimize Screen" : "Full Screen"}
</button>

<lable className="flex gap-3 items-center" htmlFor="codefile">
<lable className="flex gap-3 items-center" htmlFor="inputfile" >
<input
id="inputfile"
className="hidden"
type="file"
accept="."
id="codefile"
onChange={(e) => getFile((e, setCurrentCode))}
onChange={(e) => getFile(e, setCurrentCode)}
/>
<BiImport style={{ fontSize: "1.5rem" }} /> Import Code
</lable>
Expand Down
11 changes: 7 additions & 4 deletions jarvis/src/components/Editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ function CodeEditor({
// console.log(currentCode, " this is my currentCode");

//get the current code from local storage
const [savedCode, setSavedCode] = useState("");
const [code, setSavedCode] = useState("");

useEffect(() => {
let savedCode = JSON.stringify(localStorage.getItem(currentCode));
let savedCode = JSON.stringify(localStorage.getItem("code"));

setSavedCode(() => savedCode);
}, [currentCode]);
console.log(savedCode, "SSSSSSSS");
}, []);

useEffect(() => {
if (currentTheme === "githubDark") {
Expand All @@ -83,7 +86,7 @@ function CodeEditor({
}, [currentTheme]);
return (
<CodeMirror
value={savedCode}
value={currentCode ? currentCode : code}
height={`${isFullScreen ? "92vh" : "76vh"}`}
theme={theme}
extensions={[
Expand Down
11 changes: 6 additions & 5 deletions jarvis/src/components/PlayGround/PlayGround.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import React, { useContext, useState } from "react";
import { useParams } from "react-router-dom";
import { PlaygroundContext, languageMap } from "../../contex/EditorContext";

import { Buffer } from "buffer";
import axios from "axios";
import Navbar from "../NavBar";
import EditContainer from "../../components/Editor/EditContainer";
import InputConsole from "../../components/Editor/InputScreen";
import OutputConsole from "../../components/Editor/OutputScreen";

function PlayGround() {
const { folderId, playgroundId } = useParams();
const { folders, savePlayground } = useContext(PlaygroundContext);

const [currentInput, setCurrentInput] = useState("");
const [currentOutput, setCurrentOutput] = useState("");
const [isFullScreen, setIsFullScreen] = useState(false);
Expand Down Expand Up @@ -102,6 +102,7 @@ playground error fix
"X-RapidAPI-Host": "judge0-ce.p.rapidapi.com",
},
};

const res = await axios.request(options);
if (res.data.status_id <= 2) {
const res2 = await getOutput(token);
Expand All @@ -111,7 +112,6 @@ playground error fix
};

const runCode = async () => {

const language_id = languageMap[currentLanguage].id;
const source_code = encode(currentCode);
const std_in = encode(currentInput);
Expand All @@ -136,7 +136,6 @@ playground error fix
final_output = decoded_output;
}
setCurrentOutput(status_name + "\n\n" + final_output);

};

function readFileContent(file) {
Expand Down Expand Up @@ -178,6 +177,8 @@ playground error fix
isFullScreen={isFullScreen}
setIsFullScreen={setIsFullScreen}
getFile={getFile}
currentInput={currentInput}
setCurrentInput={setCurrentInput}
/>
</div>
{!isFullScreen && (
Expand Down
File renamed without changes.

1 comment on commit 07f4dd6

@vercel
Copy link

@vercel vercel bot commented on 07f4dd6 Apr 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.