Skip to content

Commit

Permalink
working reset button
Browse files Browse the repository at this point in the history
  • Loading branch information
danielc-n committed Sep 11, 2024
1 parent 8e824f2 commit 760fa75
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 47 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
"is-electron": "^2.2.1",
"isomorphic-git": "^1.24.0",
"js-yaml": "^4.1.0",
"jxl-pdf": "0.6.0",
"jxl-pdf": "0.6.1",
"localforage": "1.10.0",
"lodash.isequal": "^4.5.0",
"markdown-translatable": "1.3.0",
Expand Down
71 changes: 37 additions & 34 deletions renderer/src/layouts/editor/InnerFramePopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { PdfPreview } from './pdfGenInterface/PdfPreview';
import { v4 as uuidv4 } from 'uuid';
import { ProjectContext } from '@/components/context/ProjectContext';
import { AutographaContext } from '@/components/context/AutographaContext';
import { useTranslation } from 'react-i18next';
import {
TextOnlyTooltip,
StyledSwitch,
Expand All @@ -32,6 +33,7 @@ export default function InnerFramePopup() {
const jsonWithHeaderChoice = global.PdfGenStatic.pageInfo();
//use to know if we can drag or not
const [update, setUpdate] = useState(true);
const [doReset, setDoReset] = useState(true);
//the order Of The Selected choice
const [orderSelection, setOrderSelection] = useState([0]);
//is the json is validate or not
Expand All @@ -52,6 +54,8 @@ export default function InnerFramePopup() {
changeMetaDataToWrapperSection(selectedProject, projects),
);

const { t } = useTranslation();

//advenceMode allow adding new Wrapper
const [advanceMode, setAdvenceMode] = useState(false);
const [infoProject, setInfoProject] = useState(
Expand All @@ -71,9 +75,9 @@ export default function InnerFramePopup() {
setOpenModalAddWrapper(isOpen);
};
const handleChangeHeaderInfo = (type, value) => {
let t = JSON.parse(headerInfo);
t[type] = value;
setHeaderInfo(JSON.stringify(t));
let data = JSON.parse(headerInfo);
data[type] = value;
setHeaderInfo(JSON.stringify(data));
};

let sortableListClassName = 'sortable-TESTWRAPPER-list';
Expand Down Expand Up @@ -235,10 +239,10 @@ export default function InnerFramePopup() {
useEffect(() => {
if (folder && nameFile !== '') {
setHeaderInfo((prev) => {
let t = { ...JSON.parse(prev) };
t['outputPath'] = folder + '/' + nameFile + '.pdf';
t['verbose'] = false;
return JSON.stringify(t);
let data = { ...JSON.parse(prev) };
data['outputPath'] = folder + '/' + nameFile + '.pdf';
data['verbose'] = false;
return JSON.stringify(data);
});
}
}, [nameFile, folder]);
Expand All @@ -255,9 +259,9 @@ export default function InnerFramePopup() {
console.log(err);
} else {
setHeaderInfo((prev) => {
let t = { ...JSON.parse(prev) };
t['workingDir'] = folder;
return JSON.stringify(t);
let data = { ...JSON.parse(prev) };
data['workingDir'] = folder;
return JSON.stringify(data);
});
}
});
Expand Down Expand Up @@ -341,7 +345,7 @@ export default function InnerFramePopup() {
</div>
<div
style={{
backgroundColor: '#464646',
backgroundColor: '#F50',
borderRadius: 25,
justifyContent: 'center',
color: 'white',
Expand All @@ -353,9 +357,12 @@ export default function InnerFramePopup() {
paddingBottom: 5,
paddingLeft: 11,
paddingRight: 11,
cursor: 'pointer',
}}
onClick={() => {}}>
Reset parameters
onClick={() => {
setDoReset(!doReset);
}}>
{t('label-reset')}
</div>
</div>
<TextOnlyTooltip
Expand Down Expand Up @@ -436,6 +443,7 @@ export default function InnerFramePopup() {
key={k}
style={{ margin: 10 }}>
<WrapperTemplate
doReset={doReset}
setFinalPrint={setSelected}
projectInfo={infoProject}
wrapperType={selected[k].type}
Expand Down Expand Up @@ -543,25 +551,20 @@ export default function InnerFramePopup() {
onClick={async () => {
if (isJsonValidate) {
setMessagePrint('');
let t = new global.PdfGenStatic(
let pdfGen = new global.PdfGenStatic(
JSON.parse(kitchenFaucet),
pdfCallBacks,
);

const path = t.options.global.workingDir;
setMessagePrint(
(prev) =>
prev + '\n' + 'working in ' + path,
);

const path = pdfGen.options.global.workingDir;
setMessagePrint('Generating Pdf ...');
try {
await t.doPdf(); // Ensure doPdf is awaited since it's async
await pdfGen.doPdf();
} catch (pdfError) {
setMessagePrint(
'PDF generation failed: ' +
pdfError.message,
);
setMessagePrint((prev) => prev + '\n' + 'PDF generation failed: ' + pdfError.message);
return;
}
setMessagePrint((prev) => prev + '\n' + 'Successful pdf generation.');
}
}}>
print
Expand Down Expand Up @@ -590,9 +593,9 @@ export default function InnerFramePopup() {
onClick={() => {
let i = Math.max(orderSelection) + 1;
setSelected((prev) => {
let t = { ...prev };
t[i] = { type: c, content: {} };
return t;
let data = { ...prev };
data[i] = { type: c, content: {} };
return data;
});
setOrderSelection((prev) => [
...prev,
Expand Down Expand Up @@ -637,10 +640,10 @@ function transformPrintDataToKitchenFaucet(jsonData) {
delete elem['content'];
elem.sections = [];
if (currentWrapper.content.order) {
for (let t = 0; t < currentWrapper.content.order.length; t++) {
for (let j = 0; j < currentWrapper.content.order.length; j++) {
let section = {
...currentWrapper.content.content[
currentWrapper.content.order[t]
currentWrapper.content.order[j]
],
};
let source = section.source;
Expand Down Expand Up @@ -699,8 +702,8 @@ export function findProjectInfo(meta, autoGrapha) {

function changeMetaDataToWrapperSection(meta, autoGrapha) {

let t = findProjectInfo(meta, autoGrapha);
if (t.type === 'Text Translation') {
let projInfo = findProjectInfo(meta, autoGrapha);
if (projInfo.type === 'Text Translation') {
return {
0: {
type: 'bcvWrapper',
Expand All @@ -711,7 +714,7 @@ function changeMetaDataToWrapperSection(meta, autoGrapha) {
},
},
};
} else if (t.type === 'OBS') {
} else if (projInfo.type === 'OBS') {
return {
0: {
type: 'obsWrapper',
Expand All @@ -722,7 +725,7 @@ function changeMetaDataToWrapperSection(meta, autoGrapha) {
},
},
};
} else if (t.type === "Juxtalinear"){
} else if (projInfo.type === "Juxtalinear"){
return {
0: {
type: 'bcvWrapper',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function AccordionPicker({
removeButton,
advanceMode,
wrapperType,
doReset,
}) {
const {
states: { listResourcesForPdf },
Expand Down Expand Up @@ -239,6 +240,7 @@ export function AccordionPicker({
fieldInfo={f}
open={open}
lang={language}
doReset={doReset}
/>
))}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ProjectContext } from '@/components/context/ProjectContext';
import { AutographaContext } from '@/components/context/AutographaContext';
import { findProjectInfo } from '../../InnerFramePopup';
export function WrapperTemplate({
doReset,
setFinalPrint,
projectInfo,
wrapperType,
Expand Down Expand Up @@ -242,6 +243,7 @@ export function WrapperTemplate({
display: 'flex',
}}>
<AccordionPicker
doReset={doReset}
language={i18n.language}
wrapperType={wrapperType}
projectInfo={projectInfo}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { RessourcePicker } from './RessourcePicker';
import { IntPicker } from './IntPicker';
export function FieldPicker({
fieldInfo,
doReset,
jsonSpec,
jsonSpecEntry,
setJsonSpec,
Expand Down Expand Up @@ -43,6 +44,7 @@ export function FieldPicker({
// console.log(fieldInfo);
return (
<SelectPicker
doReset={doReset}
setJsonSpec={setJsonSpec}
fieldInfo={fieldInfo}
require={require}
Expand All @@ -64,6 +66,7 @@ export function FieldPicker({
} else if (fieldInfo.typeName && fieldInfo.typeName === 'boolean') {
return (
<BooleanPicker
doReset={doReset}
setJsonSpec={setJsonSpec}
fieldInfo={fieldInfo}
require={require}
Expand All @@ -74,6 +77,7 @@ export function FieldPicker({
} else if (fieldInfo.typeName && fieldInfo.typeName === 'string') {
return (
<InputPicker
doReset={doReset}
setJsonSpec={setJsonSpec}
fieldInfo={fieldInfo}
require={require}
Expand All @@ -84,6 +88,7 @@ export function FieldPicker({
} else if (fieldInfo.id === 'scripture') {
return (
<ScripturePicker
doReset={doReset}
setJsonSpec={setJsonSpec}
fieldInfo={fieldInfo}
lang={lang}
Expand All @@ -102,6 +107,7 @@ export function FieldPicker({
if (!['scriptureSrc','obs'].includes(fieldInfo.id)) {
return (
<RessourcePicker
doReset={doReset}
setJsonSpec={setJsonSpec}
fieldInfo={fieldInfo}
ressourceKey={fieldInfo.typeName}
Expand All @@ -117,6 +123,7 @@ export function FieldPicker({
) {
return (
<IntPicker
doReset={doReset}
setJsonSpec={setJsonSpec}
fieldInfo={fieldInfo}
lang={lang}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import Box from "@mui/material/Box";
import TextField from "@mui/material/TextField";
import { useState, useEffect } from "react";

export function InputPicker({ fieldInfo, setJsonSpec, require,lang,open=true }) {
const [input, setInput] = useState("");
export function InputPicker({ doReset, fieldInfo, setJsonSpec, require,lang,open=true }) {
const [input, setInput] = useState(fieldInfo.suggestedDefault || "");
useEffect(() => {
console.log("call");
setJsonSpec((prev) => {
Expand All @@ -19,6 +19,14 @@ export function InputPicker({ fieldInfo, setJsonSpec, require,lang,open=true })
setInput(e.target.value);
};

const resetField = () => {
setInput(fieldInfo.suggestedDefault || "");
}

useEffect(() => {
resetField();
}, [doReset]);

return (
<div style={open ? {} : { display: 'none' }}>
<Box
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import TextField from '@mui/material/TextField';
import { NumericFormat } from 'react-number-format';

export function IntPicker({
doReset,
fieldInfo,
setJsonSpec,
require,
Expand Down Expand Up @@ -32,6 +33,14 @@ export function IntPicker({
setValue(newValue);
};

const resetField = () => {
setInput(fieldInfo.suggestedDefault || '');
}

useEffect(() => {
resetField();
}, [doReset]);

const NumericFormatCustom = React.forwardRef(function NumericFormatCustom(
props,
ref,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ProjectContext } from '@/components/context/ProjectContext';
import { Button, Modal } from '@mui/material';
import ScriptureContentPicker from '@/components/ScriptureContentPicker/ScriptureContentPicker';

export function RessourcePicker({ setJsonSpec, fieldInfo, ressourceKey, ressourceName, open=true }) {
export function RessourcePicker({ doReset, setJsonSpec, fieldInfo, ressourceKey, ressourceName, open=true }) {
const [selected, setSelected] = useState('');
const [infoDisplay, setInfoDiplay] = useState('');

Expand All @@ -21,6 +21,15 @@ export function RessourcePicker({ setJsonSpec, fieldInfo, ressourceKey, ressourc

}, [selected]);

const resetField = () => {
setSelected('');
setInfoDiplay('');
}

useEffect(() => {
resetField();
}, [doReset]);

const {
states: { listResourcesForPdf },
actions: { setListResourcesForPdf },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { useState, useEffect } from 'react';
import { FieldPicker } from './FieldPicker';
import { Button } from '@mui/material';
export function ScripturePicker({ fieldInfo, setJsonSpec, lang, open = true }) {
export function ScripturePicker({ doReset, fieldInfo, setJsonSpec, lang, open = true }) {
const [scriptureJson, setScriptureJson] = useState('{}');
const [scriptureTable, setScriptureTable] = useState('[]');
const [numberOfScripture, setNumberOfScripture] = useState(
fieldInfo.nValues[0],
);
const [numberOfScripture, setNumberOfScripture] = useState(fieldInfo.nValues[0]);
useEffect(() => {
setNumberOfScripture(fieldInfo.nValues[0]);
}, [fieldInfo]);
Expand All @@ -28,6 +26,16 @@ export function ScripturePicker({ fieldInfo, setJsonSpec, lang, open = true }) {
});
}, [numberOfScripture]);

const resetField = () => {
setScriptureJson('{}');
setScriptureTable('[]');
setNumberOfScripture(fieldInfo.nValues[0]);
}

useEffect(() => {
resetField();
}, [doReset]);

useEffect(() => {
setJsonSpec((prev) => {
const newState = typeof prev == "object" ? prev : JSON.parse(prev);
Expand Down
Loading

0 comments on commit 760fa75

Please sign in to comment.