-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from StagBIN/dev
Add a very basic Static code checker
- Loading branch information
Showing
7 changed files
with
153 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
const API_URL = "https://api.stagb.in/dev/content/"; | ||
const EXPLAIN_URL = "https://api.stagb.in/dev/explain/"; | ||
const RAW_URL = "https://raw.stagb.in/StagBIN-Raw/"; | ||
|
||
export { API_URL, RAW_URL }; | ||
export { API_URL, RAW_URL, EXPLAIN_URL }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { useState } from "react"; | ||
import axios from "axios"; | ||
import Dialog from "@material-ui/core/Dialog"; | ||
import DialogTitle from "@material-ui/core/DialogTitle"; | ||
import DialogContent from "@material-ui/core/DialogContent"; | ||
import DialogContentText from "@material-ui/core/DialogContentText"; | ||
import DialogActions from "@material-ui/core/DialogActions"; | ||
import Button from "@material-ui/core/Button"; | ||
import MDEditor from "@uiw/react-md-editor"; | ||
import { Box } from "@material-ui/core"; | ||
import CircularProgress from "@material-ui/core/CircularProgress"; | ||
|
||
import { EXPLAIN_URL } from "../Constants"; | ||
export default function ExplainDialog({ data, exCss = {} }) { | ||
// AI | ||
const [open, setOpen] = useState(false); | ||
const [explanation, setExplanation] = useState(""); | ||
|
||
const handleOpen = () => { | ||
setOpen(true); | ||
axios | ||
.post(EXPLAIN_URL, { data: data }) | ||
.then((res) => { | ||
console.log("res", res.data.body); | ||
setExplanation(res.data.body); | ||
}) | ||
.catch((err) => { | ||
console.log(err); | ||
setExplanation("Failed to understand the content"); | ||
}); | ||
}; | ||
|
||
const handleClose = () => { | ||
setOpen(false); | ||
setExplanation(""); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<Button | ||
color="primary" | ||
aria-label="add" | ||
variant="contained" | ||
onClick={handleOpen} | ||
style={{ | ||
position: "fixed", | ||
bottom: "40px", | ||
right: "20px", | ||
opacity: "0.7", | ||
size: "large", | ||
display: data ? "block" : "none", | ||
}} | ||
> | ||
Explain Content | ||
</Button> | ||
<Dialog open={open} onClose={handleClose}> | ||
<DialogTitle | ||
style={{ | ||
backgroundColor: "#1a1a1a", | ||
color: "white", | ||
borderBottom: "1px solid white", | ||
}} | ||
> | ||
Explanation | ||
</DialogTitle> | ||
<DialogContent style={{ backgroundColor: "#0d1117" }}> | ||
<DialogContentText style={{ color: "white" }}> | ||
{!explanation && "Understanding your content..."} | ||
<Box | ||
display="flex" | ||
justifyContent="center" | ||
alignItems="center" | ||
height="100%" | ||
overflow="auto" | ||
p={2} | ||
style={{ backgroundColor: "#0d1117" }} | ||
> | ||
{explanation ? ( | ||
<MDEditor.Markdown source={explanation} /> | ||
) : ( | ||
<CircularProgress /> | ||
)} | ||
</Box> | ||
</DialogContentText> | ||
</DialogContent> | ||
<DialogActions | ||
style={{ backgroundColor: "#1a1a1a", borderTop: "1px solid white" }} | ||
> | ||
<Button | ||
onClick={handleClose} | ||
color="primary" | ||
style={exCss ? exCss : { color: "white" }} | ||
> | ||
Close | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const detectLanguage = (code) => { | ||
if (code.includes("import java")) { | ||
return "java"; | ||
} else if (code.includes("import ") && code.includes("print(")) { | ||
return "python"; | ||
} else if (code.includes("#include") && code.includes("cout")) { | ||
return "cpp"; | ||
} else if (code.includes("#include")) { | ||
return "c"; | ||
} else if (code.includes("<html>") || code.includes("</html>")) { | ||
return "html"; | ||
} else if (code.includes("func main()")) { | ||
return "go"; | ||
} else if (code.includes("function") && code.includes(";")) { | ||
return "javascript"; | ||
} else if (code.includes("#") && code.includes("-")) { | ||
return "markdown"; | ||
} else if (code.includes("{") && code.includes("}") && code.includes(":")) { | ||
return "css"; | ||
} else { | ||
return "javascript"; | ||
} | ||
}; | ||
|
||
export default detectLanguage; |