[DE mobile] Correct structure

This commit is contained in:
SergeyEzhin 2022-02-01 00:22:31 +04:00
parent c90c0ac259
commit ddf8b23570
2 changed files with 44 additions and 24 deletions

View file

@ -79,8 +79,6 @@ class EditTableContentsController extends Component {
} }
}); });
console.log(styles);
if(props) { if(props) {
let start = props.get_OutlineStart(), let start = props.get_OutlineStart(),
end = props.get_OutlineEnd(), end = props.get_OutlineEnd(),
@ -93,7 +91,6 @@ class EditTableContentsController extends Component {
if ((start < 0 || end < 0) && count < 1) { if ((start < 0 || end < 0) && count < 1) {
start = 1; start = 1;
end = 9; end = 9;
// this.spnLevels.setValue(end, true);
} }
for (let i = 0; i < count; i++) { for (let i = 0; i < count; i++) {
@ -162,7 +159,6 @@ class EditTableContentsController extends Component {
} }
} }
// this.spnLevels.setValue(newEnd > 0 ? newEnd : '', true);
checkStyles = (disableOutlines || newStart > 1); checkStyles = (disableOutlines || newStart > 1);
} else { } else {
for (let i = this.startLevel; i <= this.endLevel; i++) { for (let i = this.startLevel; i <= this.endLevel; i++) {
@ -185,25 +181,33 @@ class EditTableContentsController extends Component {
return { return {
styles, styles,
start: this.startLevel, // start: this.startLevel,
end: this.endLevel, end: this.endLevel,
count: this.count, count: this.count,
disableOutlines, // disableOutlines,
checkStyles // checkStyles
} }
} }
addStyles(styleName, value) { addStyles(styles, styleName, value) {
const api = Common.EditorApi.get(); const api = Common.EditorApi.get();
const propsTableContents = api.asc_GetTableOfContentsPr(); const propsTableContents = api.asc_GetTableOfContentsPr();
// propsTableContents.clear_Styles(); propsTableContents.clear_Styles();
propsTableContents.add_Style(styleName, value);
// if (propsTableContents.get_StylesCount() > 0) styles.forEach(style => {
// propsTableContents.put_OutlineRange(-1, -1); if(style.name === styleName) {
// else propsTableContents.add_Style(styleName, value);
// propsTableContents.put_OutlineRange(1, 9); } else {
propsTableContents.add_Style(style.name, style.value);
}
});
if (propsTableContents.get_StylesCount() > 0) {
propsTableContents.put_OutlineRange(-1, -1);
} else {
propsTableContents.put_OutlineRange(1, 9);
}
api.asc_SetTableOfContentsPr(propsTableContents); api.asc_SetTableOfContentsPr(propsTableContents);
} }

View file

@ -10,7 +10,6 @@ const EditTableContents = props => {
const api = Common.EditorApi.get(); const api = Common.EditorApi.get();
const propsTableContents = api.asc_GetTableOfContentsPr(); const propsTableContents = api.asc_GetTableOfContentsPr();
const stylesCount = propsTableContents.get_StylesCount(); const stylesCount = propsTableContents.get_StylesCount();
console.log(propsTableContents);
const [type, setType] = useState(0); const [type, setType] = useState(0);
const [styleValue, setStyleValue] = useState(propsTableContents.get_StylesType()); const [styleValue, setStyleValue] = useState(propsTableContents.get_StylesType());
const [pageNumbers, setPageNumbers] = useState(propsTableContents.get_ShowPageNumbers()); const [pageNumbers, setPageNumbers] = useState(propsTableContents.get_ShowPageNumbers());
@ -186,12 +185,20 @@ const PageEditStructureTableContents = props => {
const isAndroid = Device.android; const isAndroid = Device.android;
const api = Common.EditorApi.get(); const api = Common.EditorApi.get();
const propsTableContents = api.asc_GetTableOfContentsPr(); const propsTableContents = api.asc_GetTableOfContentsPr();
const {styles, start, end, count, disableOutlines, checkStyles} = props.fillTOCProps(propsTableContents); const {styles, end, count} = props.fillTOCProps(propsTableContents);
console.log(styles, start, end, count, disableOutlines, checkStyles); const chosenStyles = styles.filter(style => style.checked);
const [structure, setStructure] = useState(count ? 1 : 0); const [structure, setStructure] = useState(count ? 1 : 0);
const [amountLevels, setAmountLevels] = useState(end); const [amountLevels, setAmountLevels] = useState(end);
const addNewStyle = (style) => {
let indexStyle = chosenStyles.findIndex(currentStyle => currentStyle.name === style.name);
if(indexStyle === -1) {
chosenStyles.push(style);
}
}
return ( return (
<Page> <Page>
<Navbar title={t('Edit.textStructure')} backLink={_t.textBack}> <Navbar title={t('Edit.textStructure')} backLink={_t.textBack}>
@ -210,7 +217,7 @@ const PageEditStructureTableContents = props => {
{structure === 0 ? {structure === 0 ?
<List> <List>
<ListItem title={t('Edit.textAmountOfLevels')}> <ListItem title={t('Edit.textAmountOfLevels')}>
{!isAndroid && <div slot='after-start'>{amountLevels}</div>} {!isAndroid && <div slot='after-start'>{amountLevels === -1 ? '-' : amountLevels}</div>}
<div slot='after'> <div slot='after'>
<Segmented> <Segmented>
<Button outline className='decrement item-link' onClick={() => { <Button outline className='decrement item-link' onClick={() => {
@ -221,11 +228,16 @@ const PageEditStructureTableContents = props => {
}}> }}>
{isAndroid ? <Icon icon="icon-expand-down"></Icon> : ' - '} {isAndroid ? <Icon icon="icon-expand-down"></Icon> : ' - '}
</Button> </Button>
{isAndroid && <label>{amountLevels}</label>} {isAndroid && <label>{amountLevels === -1 ? '-' : amountLevels}</label>}
<Button outline className='increment item-link' onClick={() => { <Button outline className='increment item-link' onClick={() => {
if(amountLevels < 9) { if(amountLevels < 9) {
setAmountLevels(amountLevels + 1); if(amountLevels === -1) {
props.onLevelsChange(amountLevels + 1); setAmountLevels(9);
props.onLevelsChange(9);
} else {
setAmountLevels(amountLevels + 1);
props.onLevelsChange(amountLevels + 1);
}
} }
}}> }}>
{isAndroid ? <Icon icon="icon-expand-up"></Icon> : ' + '} {isAndroid ? <Icon icon="icon-expand-up"></Icon> : ' + '}
@ -244,7 +256,9 @@ const PageEditStructureTableContents = props => {
<Segmented> <Segmented>
<Button outline className='decrement item-link' onClick={() => { <Button outline className='decrement item-link' onClick={() => {
if(style.value > 1) { if(style.value > 1) {
props.addStyles(style.name, style.value - 1); setAmountLevels(-1);
addNewStyle(style);
props.addStyles(chosenStyles, style.name, style.value - 1);
} }
}}> }}>
{isAndroid ? <Icon icon="icon-expand-down"></Icon> : ' - '} {isAndroid ? <Icon icon="icon-expand-down"></Icon> : ' - '}
@ -252,7 +266,9 @@ const PageEditStructureTableContents = props => {
{isAndroid && <label>{style.value}</label>} {isAndroid && <label>{style.value}</label>}
<Button outline className='increment item-link' onClick={() => { <Button outline className='increment item-link' onClick={() => {
if(style.value < 9) { if(style.value < 9) {
props.addStyles(style.name, style.value + 1); setAmountLevels(-1);
addNewStyle(style);
props.addStyles(chosenStyles, style.name, style.value + 1);
} }
}}> }}>
{isAndroid ? <Icon icon="icon-expand-up"></Icon> : ' + '} {isAndroid ? <Icon icon="icon-expand-up"></Icon> : ' + '}