-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding language detection for snippet code
- Loading branch information
Showing
22 changed files
with
701 additions
and
25 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,10 @@ | |
content="CodeTotal by OX Security, a megalinter UI" | ||
/> | ||
<link rel="icon" href="/favicon.png" /> | ||
<link | ||
rel="stylesheet" | ||
href="https://cdn.jsdelivr.net/gh/devicons/[email protected]/devicon.min.css" | ||
/> | ||
<meta name="theme-color" content="#6837FF" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Code Total By OX Security</title> | ||
|
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
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
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,57 @@ | ||
import { Theme, Tooltip, useTheme } from "@mui/material"; | ||
import { FC } from "react"; | ||
import { ProgrammingLanguage } from "shared-types"; | ||
import { makeStyles } from "tss-react/mui"; | ||
|
||
export const LanguageIcon: FC<LanguageIconProps> = ({ language }) => { | ||
const { classes, cx } = useStyles(); | ||
const theme = useTheme(); | ||
const isDarkmode = theme.palette.mode === "dark"; | ||
if (!language) { | ||
return null; | ||
} | ||
|
||
// only is dark mode and only for "plain" type icons | ||
// they require a background since when used with an img tag | ||
// colors can't be applied through css and we end up with a black colored icon | ||
const requiresBackground = isDarkmode && language.icon === "plain"; | ||
|
||
return ( | ||
<Tooltip title={language.name || ""} arrow placement="top"> | ||
<span | ||
className={cx( | ||
classes.languageIcon, | ||
requiresBackground && classes.darkmode | ||
)} | ||
> | ||
<img | ||
src={`https://cdn.jsdelivr.net/gh/devicons/devicon/icons/${language.name?.toLowerCase()}/${language.name?.toLowerCase()}-${ | ||
language.icon | ||
}.svg`} | ||
className={classes.img} | ||
alt="programming language icon" | ||
/> | ||
</span> | ||
</Tooltip> | ||
); | ||
}; | ||
const useStyles = makeStyles()((theme: Theme) => ({ | ||
languageIcon: { | ||
display: "inline-flex", | ||
height: "2em", | ||
width: "2em", | ||
}, | ||
img: { | ||
width: "100%", | ||
height: "100%", | ||
}, | ||
darkmode: { | ||
backgroundColor: theme.palette.text.secondary, | ||
borderRadius: "50%", | ||
display: "inline-flex", | ||
}, | ||
})); | ||
|
||
interface LanguageIconProps { | ||
language?: ProgrammingLanguage; | ||
} |
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,15 @@ | ||
import axios from "axios"; | ||
import debounce from "lodash-es/debounce"; | ||
import { ProgrammingLanguage } from "shared-types"; | ||
import { AnalysisStore } from "../../analysis/stores/analysis-store"; | ||
import config from "../../config"; | ||
|
||
export const detect = async (snippet: string) => { | ||
const res = await axios.post<ProgrammingLanguage | undefined>( | ||
`http://${config.CODETOTAL_HTTP_HOST}:${config.CODETOTAL_HTTP_PORT}/detect`, | ||
{ snippet } | ||
); | ||
AnalysisStore.setState({ language: res.data }); | ||
}; | ||
|
||
export const fetchDetect = debounce(detect, 1000); |
Oops, something went wrong.