From 3a5135878b21ae6d2da992aa5ffa8d4845df51d6 Mon Sep 17 00:00:00 2001 From: danielc-n Date: Wed, 11 Sep 2024 18:06:15 +0200 Subject: [PATCH] changes for : https://github.com/bible-technology/scribe-scripture-editor/pull/361#issuecomment-2342607370 --- package.json | 7 +-- .../src/layouts/editor/InnerFramePopup.js | 50 +++++++++++++++---- yarn.lock | 12 +++++ 3 files changed, 56 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 46ff2c09..70862d07 100644 --- a/package.json +++ b/package.json @@ -88,6 +88,7 @@ "@babel/eslint-parser": "^7.5.4", "@babel/preset-env": "^7.25.4", "@babel/preset-react": "^7.17.12", + "@mui/icons-material": "^5.8.4", "@netlify/plugin-nextjs": "^4.8.0", "@playwright/test": "^1.36.2", "@svgr/webpack": "^5.5.0", @@ -118,8 +119,7 @@ "postcss": "^8.4.21", "prettier": "^2.8.3", "source-map-explorer": "^2.5.3", - "tailwindcss": "^3.2.4", - "@mui/icons-material": "^5.8.4" + "tailwindcss": "^3.2.4" }, "peerDependencies": { "@material-ui/core": "^4.x", @@ -205,6 +205,7 @@ "proskomma-core": "^0.10.4", "proskomma-json-tools": "^0.8.16", "proskomma-react-hooks": "2.4.0", + "random-words": "^2.0.1", "raw-loader": "^4.0.2", "react": "^18.2.0", "react-beautiful-dnd": "^13.1.1", @@ -248,4 +249,4 @@ "word-aligner": "$word-aligner", "@mui/lab": "$@mui/lab" } -} \ No newline at end of file +} diff --git a/renderer/src/layouts/editor/InnerFramePopup.js b/renderer/src/layouts/editor/InnerFramePopup.js index 70eef678..4f51296c 100644 --- a/renderer/src/layouts/editor/InnerFramePopup.js +++ b/renderer/src/layouts/editor/InnerFramePopup.js @@ -20,6 +20,7 @@ import { StyledSwitch, } from './pdfGenInterface/pdfGenWrappers/fieldPicker/customMuiComponent'; import { WrapperTemplate } from './pdfGenInterface/pdfGenWrappers/WrapperTemplate'; +import { generate } from "random-words"; export default function InnerFramePopup() { const { @@ -57,7 +58,7 @@ export default function InnerFramePopup() { const { t } = useTranslation(); //advenceMode allow adding new Wrapper - const [advanceMode, setAdvenceMode] = useState(false); + const [advanceMode, setAdvanceMode] = useState(false); const [infoProject, setInfoProject] = useState( findProjectInfo(selectedProject, projects), ); @@ -65,7 +66,7 @@ export default function InnerFramePopup() { //the selected headerInfo const [headerInfo, setHeaderInfo] = useState('{"sizes":"9on11","fonts":"allGentium","pages":"EXECUTIVE"}'); // const [headerInfo, setHeaderInfo] = useState('{}'); - const [nameFile, setNameFile] = useState(''); + const [nameFile, setNameFile] = useState(""); const [folder, setFolder] = useState(null); //zoom of the preview const [kitchenFaucet, setKitchenFaucet] = useState('{}'); @@ -196,22 +197,32 @@ export default function InnerFramePopup() { useEffect(() => { let validationJson = global.PdfGenStatic.validateConfig(JSON.parse(kitchenFaucet)); + console.log('call ! validationJson ==',validationJson); if (validationJson.length === 0) { let header = JSON.parse(headerInfo); - // console.log('header ==',header); + console.log('header ==',header); if ( header.workingDir && - header.outputPath && + folder && header.sizes && header.fonts && header.pages - ) + ) { + if(!header.outputPath && folder) { + setHeaderInfo((prev) => { + let data = { ...JSON.parse(prev) }; + data['outputPath'] = folder + '/' + generate({exactly: 5, wordsPerString:1}).join("-") + '.pdf'; + data['verbose'] = false; + return JSON.stringify(data); + }); + } setIsJsonValidate(true); + } } else { setIsJsonValidate(false); } // console.log("kitchenFaucet==",kitchenFaucet); - }, [kitchenFaucet, headerInfo]); + }, [selected, headerInfo, orderSelection, folder, kitchenFaucet]); const openFileDialogSettingData = async () => { try { @@ -227,6 +238,7 @@ export default function InnerFramePopup() { } if (chosenFolder.filePaths.length > 0) { setFolder(chosenFolder.filePaths[0]); + setMessagePrint((prev) => prev + '\n' + 'folder selected : ' + chosenFolder.filePaths[0]); } else { // Handle case where no folder was selected console.log('No folder was selected'); @@ -236,6 +248,24 @@ export default function InnerFramePopup() { } }; + useEffect(() => { + if (folder && nameFile == '') { + setHeaderInfo((prev) => { + let data = { ...JSON.parse(prev) }; + data['outputPath'] = folder + '/' + generate({exactly: 5, wordsPerString:1}).join("-") + '.pdf'; + data['verbose'] = false; + return JSON.stringify(data); + }); + } else if (folder && nameFile !== '') { + setHeaderInfo((prev) => { + let data = { ...JSON.parse(prev) }; + data['outputPath'] = folder + '/' + nameFile + '.pdf'; + data['verbose'] = false; + return JSON.stringify(data); + }); + } + }, [folder]); + useEffect(() => { if (folder && nameFile !== '') { setHeaderInfo((prev) => { @@ -245,7 +275,7 @@ export default function InnerFramePopup() { return JSON.stringify(data); }); } - }, [nameFile, folder]); + }, [nameFile]); useEffect(() => { const fs = window.require('fs'); @@ -269,7 +299,7 @@ export default function InnerFramePopup() { const handleInputChange = (e) => { const value = e.target.value; - const regex = /^[a-zA-Z_]*$/; // Regular expression to allow only letters and underscores + const regex = /^[a-zA-Z_-]*$/; // Regular expression to allow only letters, underscores and dashes if (regex.test(value)) { setNameFile(value); // Update state only if the input matches the regex @@ -414,7 +444,7 @@ export default function InnerFramePopup() { }}> - setAdvenceMode((prev) => !prev) + setAdvanceMode((prev) => !prev) } />