Skip to content

Commit

Permalink
Merge pull request #433 from bobronaud/fix-new-snippet-html
Browse files Browse the repository at this point in the history
Closed #432
  • Loading branch information
dzencot authored Feb 26, 2024
2 parents ff3aeaa + 91f466b commit 854f95c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions frontend/src/components/Modals/NewSnippet.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ import { useAuth, useSnippets } from '../../hooks';
import { snippetName } from '../../utils/validationSchemas';
import { actions as modalActions } from '../../slices/modalSlice.js';
import JavaScriptIcon from '../../assets/images/icons/javascript.svg';
import HtmlIcon from '../../assets/images/icons/html.svg';
import PhpIcon from '../../assets/images/icons/php.svg';
import PythonIcon from '../../assets/images/icons/python.svg';

const icons = new Map()
.set('javascript', JavaScriptIcon)
.set('html', HtmlIcon)
.set('python', PythonIcon)
.set('php', PhpIcon);

Expand All @@ -47,8 +49,8 @@ function NewSnippet({ handleClose, isOpen }) {
const navigate = useNavigate();
const inputRefTemplate = useRef(null);
const inputRefName = useRef(null);
const supportedLanguages = ['javascript']; // #TODO: later change it to a selector with data on support languages
const username = useSelector((state) => state.user.userInfo.username);
const { supportedLanguages } = useSelector((state) => state.languages);
const [selectedLng, setSelectedLng] = useState([]);
const [once, setOnce] = useState(false);
const [isLoading, setIsLoading] = useState(false);
Expand Down Expand Up @@ -103,7 +105,7 @@ function NewSnippet({ handleClose, isOpen }) {
const [language] = selectedLng;
const code = t(`codeTemplates.${language}`);
// TODO: Тут не должно быть проверок, нужно создать абстракцию сервиса, который будет работать с любыми языками
if (language === 'javascript') {
if (supportedLanguages.includes(language)) {
try {
const snipName = `${values.name}.${extensions.get(language)}`;
const id = await snippetApi.saveSnippet(code, snipName, language);
Expand Down

0 comments on commit 854f95c

Please sign in to comment.