Skip to content

Commit

Permalink
Merge pull request #195 from bible-technology/fix/import-status
Browse files Browse the repository at this point in the history
Fix/import status
  • Loading branch information
vipinpaul authored Oct 26, 2023
2 parents e6aea9e + cba56f0 commit 438d463
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
8 changes: 6 additions & 2 deletions renderer/src/components/LoadingSpinner/LoadingSpinner.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
export default function LoadingSpinner() {
export default function LoadingSpinner({
height = 'h-10',
width = 'w-10',
colorTW = 'text-primary',
}) {
return (
<div className="h-full items-center justify-center flex">
<svg className="animate-spin h-10 w-10 text-primary" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
<svg className={`animate-spin ${height} ${width} ${colorTW}`} xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" />
</svg>
Expand Down
19 changes: 19 additions & 0 deletions renderer/src/core/burrito/importBurrito.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,16 @@ const updateAudioDir = async (dir, path, fs, status) => {
}
};

const checkTheProjectIsAudioChapterLevel = async (metadata) => {
const chapterPathRegex = /^[0-9]{1,3}\.(mp3|wav)/gm;
const chapterLevel = Object.keys(metadata.ingredients).some((path) => {
const pathArr = path.split('/');
const fileName = pathArr[pathArr.length - 1];
return chapterPathRegex.test(fileName);
});
return chapterLevel;
};

// Core Function Handle Burrito Import for all type of Projects
const importBurrito = async (filePath, currentUser, updateBurritoVersion, concatedLangs = []) => {
logger.debug('importBurrito.js', 'Inside importBurrito');
Expand All @@ -187,6 +197,15 @@ const importBurrito = async (filePath, currentUser, updateBurritoVersion, concat
logger.debug('importBurrito.js', 'Project has Burrito file metadata.json.');
let sb = fs.readFileSync(path.join(filePath, 'metadata.json'));
let metadata = JSON.parse(sb);
// check if its an audio import and not the import burrito is for chapter level export
if (metadata.type?.flavorType?.flavor?.name === 'audioTranslation') {
const chapterLevel = await checkTheProjectIsAudioChapterLevel(metadata);
if (chapterLevel) {
logger.error('importBurrito.js', 'Import not supported for chapter level audio projects');
status.push({ type: 'error', value: 'Import not supported for chapter level audio projects' });
return status;
}
}
// Fixing the issue of previous version of AG. The dateCreated was left empty and it will fail the validation.
if (!metadata?.meta?.dateCreated) {
const agId = Object.keys(metadata?.identification?.primary?.scribe);
Expand Down
3 changes: 2 additions & 1 deletion renderer/src/layouts/projects/Export/ExportProjectPopUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import updateTranslationSB from '@/core/burrito/updateTranslationSB';
import updateObsSB from '@/core/burrito/updateObsSB';
import { SnackBar } from '@/components/SnackBar';
// import useSystemNotification from '@/components/hooks/useSystemNotification';
import { LoadingSpinner } from '@/components/LoadingSpinner';
import CloseIcon from '@/illustrations/close-button-black.svg';
import { validate } from '../../../util/validate';
import * as logger from '../../../logger';
Expand Down Expand Up @@ -311,7 +312,7 @@ export default function ExportProjectPopUp(props) {
type="button"
className="py-2 px-7 rounded shadow bg-success text-white uppercase text-xs tracking-widest font-semibold"
>
{t('btn-export')}
{exportStart ? <LoadingSpinner height="h-4" width="w-4" colorTW="text-white" /> : t('btn-export')}
</button>
</div>
</div>
Expand Down
5 changes: 4 additions & 1 deletion renderer/src/layouts/projects/ImportProjectPopUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import * as logger from '../../logger';
import ConfirmationModal from '../editor/ConfirmationModal';
import burrito from '../../lib/BurritoTemplete.json';
import { mergeProject } from './Import/mergeProject';
import { LoadingSpinner } from '@/components/LoadingSpinner';

export default function ImportProjectPopUp(props) {
const {
Expand Down Expand Up @@ -325,7 +326,9 @@ export default function ImportProjectPopUp(props) {
className="py-2 px-7 rounded shadow bg-success text-white uppercase text-xs tracking-widest font-semibold"
onClick={() => importProject()}
>
{t('btn-import')}
{importProgress.importStarted
? <LoadingSpinner height='h-4' width='w-4' colorTW='text-white'/>
: t('btn-import')}
</button>
)}
</div>
Expand Down

0 comments on commit 438d463

Please sign in to comment.