[DE] added 'DocumentSettings' controller

This commit is contained in:
Maxim Kadushkin 2020-09-25 21:17:45 +03:00
parent 37b297ca7e
commit 9ab2f40f19
8 changed files with 75 additions and 33 deletions

View file

@ -9,7 +9,8 @@ class DocumentSettingsController extends Component {
} }
onPageOrientation(value){ onPageOrientation(value){
console.log(`changed page orientation: ${value}`); const api = Common.EditorApi.get();
api.change_PageOrient(value=='portrait');
} }
render() { render() {

View file

@ -1,4 +1,5 @@
import React, {Component} from 'react'; import React, {Component} from 'react';
import { connect } from 'react-redux';
import { import {
Page, Page,
Navbar, Navbar,
@ -7,11 +8,7 @@ import {
BlockTitle BlockTitle
} from 'framework7-react'; } from 'framework7-react';
export default class DocumentSettings extends Component { const DocumentSettings = props => {
constructor(props) {
super(props);
}
render() {
const textDocumentSettings = "Document Settings"; const textDocumentSettings = "Document Settings";
const textBack = "Back"; const textBack = "Back";
const textOrientation = "Orientation"; const textOrientation = "Orientation";
@ -28,8 +25,8 @@ export default class DocumentSettings extends Component {
<Navbar title={textDocumentSettings} backLink={textBack} /> <Navbar title={textDocumentSettings} backLink={textBack} />
<BlockTitle>{textOrientation}</BlockTitle> <BlockTitle>{textOrientation}</BlockTitle>
<List> <List>
<ListItem radio title={textPortrait} name="orientation-checkbox" defaultChecked onChange={e => this.props.onPageOrientation('portrait')}></ListItem> <ListItem radio title={textPortrait} name="orientation-checkbox" checked={props.isPortrait} onClick={e => props.onPageOrientation('portrait')}></ListItem>
<ListItem radio title={textLandscape} name="orientation-checkbox" onChange={e => this.props.onPageOrientation('landscape')}></ListItem> <ListItem radio title={textLandscape} name="orientation-checkbox" checked={!props.isPortrait} onClick={e => props.onPageOrientation('landscape')}></ListItem>
</List> </List>
<BlockTitle>{textFormat}</BlockTitle> <BlockTitle>{textFormat}</BlockTitle>
<List mediaList> <List mediaList>
@ -38,5 +35,10 @@ export default class DocumentSettings extends Component {
</List> </List>
</Page> </Page>
) )
}
}; };
const mapStateToProps = (state) => {
return state.settings;
};
export default connect(mapStateToProps)(DocumentSettings);

View file

@ -1,5 +1,7 @@
import {Component} from 'react' import {Component} from 'react'
import {connect} from 'react-redux'
import * as Actions from '../store/actions/actions'
class MainController extends Component { class MainController extends Component {
constructor(props) { constructor(props) {
@ -133,6 +135,7 @@ class MainController extends Component {
}); });
this.appOptions = {}; this.appOptions = {};
this.bindEvents();
Common.Gateway.on('init', loadConfig); Common.Gateway.on('init', loadConfig);
// Common.Gateway.on('showmessage', _.bind(me.onExternalMessage, me)); // Common.Gateway.on('showmessage', _.bind(me.onExternalMessage, me));
@ -140,6 +143,7 @@ class MainController extends Component {
Common.Gateway.appReady(); Common.Gateway.appReady();
Common.Notifications.trigger('engineCreated', this.api); Common.Notifications.trigger('engineCreated', this.api);
Common.EditorApi = {get: () => this.api};
}, error => { }, error => {
console.log('promise failed ' + error); console.log('promise failed ' + error);
}); });
@ -152,9 +156,16 @@ class MainController extends Component {
document.body.appendChild(script); document.body.appendChild(script);
} }
bindEvents() {
const {dispatch} = this.props;
this.api.asc_registerCallback('asc_onPageOrient', isPortrait => {
dispatch(Actions.changePageOrientation(isPortrait === true));
});
}
render() { render() {
return null return null
} }
} }
export default MainController; export default connect(null,null,null,{forwardRef:true})(MainController);

View file

@ -0,0 +1,9 @@
export const SETTINGS_PAGE_ORIENTATION_CHANGED = 'PAGE_ORIENTATION_CHANGED';
export const changePageOrientation = isPortrait => {
return {
type: SETTINGS_PAGE_ORIENTATION_CHANGED,
isPortrait: isPortrait
}
};

View file

@ -1,10 +1,15 @@
import { combineReducers } from 'redux'; import { combineReducers } from 'redux';
import settingsReducer from './settings'
import usersReducer from '../../../../../common/mobile/lib/store/users' import usersReducer from '../../../../../common/mobile/lib/store/users'
export const initialState = { export const initialState = {
settings: {
isPortrait: true
},
users: [] users: []
}; };
export const rootReducer = combineReducers({ export const rootReducer = combineReducers({
settings: settingsReducer,
users: usersReducer users: usersReducer
}); });

View file

@ -0,0 +1,12 @@
import * as actionTypes from '../actions/actions'
const settingsReducer = (state = [], action) => {
if (action.type == actionTypes.SETTINGS_PAGE_ORIENTATION_CHANGED) {
return {isPortrait: action.isPortrait};
}
return state;
};
export default settingsReducer;

View file

@ -8,5 +8,6 @@ module.exports = {
plugins: [ plugins: [
'@babel/plugin-transform-runtime', '@babel/plugin-transform-runtime',
'@babel/plugin-syntax-dynamic-import', '@babel/plugin-syntax-dynamic-import',
'@babel/plugin-proposal-class-properties',
], ],
}; };

View file

@ -35,6 +35,7 @@
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.11.0", "@babel/core": "^7.11.0",
"@babel/plugin-proposal-class-properties": "^7.10.4",
"@babel/plugin-syntax-dynamic-import": "^7.8.3", "@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.11.0", "@babel/plugin-transform-runtime": "^7.11.0",
"@babel/preset-env": "^7.11.0", "@babel/preset-env": "^7.11.0",