Skip to content

Commit

Permalink
Merge pull request #197 from bible-technology/enable-replace
Browse files Browse the repository at this point in the history
Enable replace alert in Edit project page
  • Loading branch information
vipinpaul authored Oct 26, 2023
2 parents 6194ae6 + 12b81f4 commit e6aea9e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 358 deletions.
36 changes: 21 additions & 15 deletions renderer/src/components/Projects/ImportPopUp.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {
useRef, Fragment, useContext, useEffect,
useRef, Fragment, useContext, useEffect, useState,
} from 'react';
import PropTypes from 'prop-types';
import { useTranslation } from 'react-i18next';
Expand All @@ -18,19 +18,20 @@ export default function ImportPopUp(props) {
open,
closePopUp,
projectType,
replaceConformation,
} = props;

const cancelButtonRef = useRef(null);
const [books, setBooks] = React.useState([]);
const [folderPath, setFolderPath] = React.useState([]);
const [valid, setValid] = React.useState(false);
const [snackBar, setOpenSnackBar] = React.useState(false);
const [snackText, setSnackText] = React.useState('');
const [notify, setNotify] = React.useState();
const [show, setShow] = React.useState(false);
const [fileFilter, setfileFilter] = React.useState([{ name: 'usfm files', extensions: ['usfm', 'sfm', 'USFM', 'SFM'] }]);
const [books, setBooks] = useState([]);
const [folderPath, setFolderPath] = useState([]);
const [valid, setValid] = useState(false);
const [snackBar, setOpenSnackBar] = useState(false);
const [snackText, setSnackText] = useState('');
const [notify, setNotify] = useState();
const [show, setShow] = useState(false);
const [fileFilter, setfileFilter] = useState([{ name: 'usfm files', extensions: ['usfm', 'sfm', 'USFM', 'SFM'] }]);
const { t } = useTranslation();
const [labelImportFiles, setLabelImportFiles] = React.useState('Choose USFM files');
const [labelImportFiles, setLabelImportFiles] = useState(t('label-choose-usfm-files'));
const {
actions: {
setImportedFiles,
Expand Down Expand Up @@ -104,10 +105,12 @@ export default function ImportPopUp(props) {
switch (projectType) {
case 'Translation': {
const usfm = fs.readFileSync(filePath, 'utf8');
const myUsfmParser = new grammar.USFMParser(usfm);
const myUsfmParser = new grammar.USFMParser(usfm, grammar.LEVEL.RELAXED);
const isJsonValid = myUsfmParser.validate();
if (isJsonValid) {
logger.debug('ImportPopUp.js', 'Valid USFM file.');
// If importing a USFM file then ask user for replace of USFM with the new content or not
replaceConformation(true);
logger.debug('ImportPopUp. js', 'Valid USFM file.');
const jsonOutput = myUsfmParser.toJSON();
files.push({ id: jsonOutput.book.bookCode, content: usfm });
} else {
Expand All @@ -121,9 +124,11 @@ export default function ImportPopUp(props) {

case 'Audio': {
const usfm = fs.readFileSync(filePath, 'utf8');
const myUsfmParser = new grammar.USFMParser(usfm);
const myUsfmParser = new grammar.USFMParser(usfm, grammar.LEVEL.RELAXED);
const isJsonValid = myUsfmParser.validate();
if (isJsonValid) {
// If importing a USFM file then ask user for replace of USFM with the new content or not
replaceConformation(true);
logger.debug('ImportPopUp.js', 'Valid USFM file.');
const jsonOutput = myUsfmParser.toJSON();
files.push({ id: jsonOutput.book.bookCode, content: usfm });
Expand Down Expand Up @@ -187,12 +192,12 @@ export default function ImportPopUp(props) {
switch (projectType) {
case 'Translation':
setfileFilter([{ name: 'usfm files', extensions: ['usfm', 'sfm', 'USFM', 'SFM'] }]);
setLabelImportFiles('Choose USFM files');
setLabelImportFiles(t('label-choose-usfm-files'));
break;

case 'OBS':
setfileFilter([{ name: 'markdown files', extensions: ['md', 'markdown', 'MD', 'MARKDOWN'] }]);
setLabelImportFiles('Choose Markdown files');
setLabelImportFiles(t('label-choose-md-files'));
break;

default:
Expand Down Expand Up @@ -334,4 +339,5 @@ ImportPopUp.propTypes = {
open: PropTypes.bool,
closePopUp: PropTypes.func,
projectType: PropTypes.string,
replaceConformation: PropTypes.bool,
};
Loading

0 comments on commit e6aea9e

Please sign in to comment.