From 9ab2f40f19168adc28a2a55efc3820471920c707 Mon Sep 17 00:00:00 2001 From: Maxim Kadushkin Date: Fri, 25 Sep 2020 21:17:45 +0300 Subject: [PATCH] [DE] added 'DocumentSettings' controller --- .../settings/controller/DocumentSettings.jsx | 3 +- .../document-settings/DocumentSettings.jsx | 64 ++++++++++--------- .../mobile/src/controller/Main.jsx | 13 +++- .../mobile/src/store/actions/actions.js | 9 +++ .../mobile/src/store/reducers/root.js | 5 ++ .../mobile/src/store/reducers/settings.js | 12 ++++ vendor/framework7-react/babel.config.js | 1 + vendor/framework7-react/package.json | 1 + 8 files changed, 75 insertions(+), 33 deletions(-) create mode 100644 apps/documenteditor/mobile/src/store/actions/actions.js create mode 100644 apps/documenteditor/mobile/src/store/reducers/settings.js diff --git a/apps/documenteditor/mobile/src/components/settings/controller/DocumentSettings.jsx b/apps/documenteditor/mobile/src/components/settings/controller/DocumentSettings.jsx index 9915ee623..9908529af 100644 --- a/apps/documenteditor/mobile/src/components/settings/controller/DocumentSettings.jsx +++ b/apps/documenteditor/mobile/src/components/settings/controller/DocumentSettings.jsx @@ -9,7 +9,8 @@ class DocumentSettingsController extends Component { } onPageOrientation(value){ - console.log(`changed page orientation: ${value}`); + const api = Common.EditorApi.get(); + api.change_PageOrient(value=='portrait'); } render() { diff --git a/apps/documenteditor/mobile/src/components/settings/document-settings/DocumentSettings.jsx b/apps/documenteditor/mobile/src/components/settings/document-settings/DocumentSettings.jsx index 331b5b22c..b254b52af 100644 --- a/apps/documenteditor/mobile/src/components/settings/document-settings/DocumentSettings.jsx +++ b/apps/documenteditor/mobile/src/components/settings/document-settings/DocumentSettings.jsx @@ -1,4 +1,5 @@ import React, {Component} from 'react'; +import { connect } from 'react-redux'; import { Page, Navbar, @@ -7,36 +8,37 @@ import { BlockTitle } from 'framework7-react'; -export default class DocumentSettings extends Component { - constructor(props) { - super(props); - } - render() { - const textDocumentSettings = "Document Settings"; - const textBack = "Back"; - const textOrientation = "Orientation"; - const textPortrait = "Portrait"; - const textLandscape = "Landscape"; - const textFormat = "Format"; - const textMargins = "Margins"; +const DocumentSettings = props => { + const textDocumentSettings = "Document Settings"; + const textBack = "Back"; + const textOrientation = "Orientation"; + const textPortrait = "Portrait"; + const textLandscape = "Landscape"; + const textFormat = "Format"; + const textMargins = "Margins"; - const format = "A4"; - const formatSize = "21 cm x 29.7 cm"; + const format = "A4"; + const formatSize = "21 cm x 29.7 cm"; - return ( - - - {textOrientation} - - this.props.onPageOrientation('portrait')}> - this.props.onPageOrientation('landscape')}> - - {textFormat} - - - - - - ) - } -}; \ No newline at end of file + return ( + + + {textOrientation} + + props.onPageOrientation('portrait')}> + props.onPageOrientation('landscape')}> + + {textFormat} + + + + + + ) +}; + +const mapStateToProps = (state) => { + return state.settings; +}; + +export default connect(mapStateToProps)(DocumentSettings); diff --git a/apps/documenteditor/mobile/src/controller/Main.jsx b/apps/documenteditor/mobile/src/controller/Main.jsx index 9176b3591..beb1b149b 100644 --- a/apps/documenteditor/mobile/src/controller/Main.jsx +++ b/apps/documenteditor/mobile/src/controller/Main.jsx @@ -1,5 +1,7 @@ import {Component} from 'react' +import {connect} from 'react-redux' +import * as Actions from '../store/actions/actions' class MainController extends Component { constructor(props) { @@ -133,6 +135,7 @@ class MainController extends Component { }); this.appOptions = {}; + this.bindEvents(); Common.Gateway.on('init', loadConfig); // Common.Gateway.on('showmessage', _.bind(me.onExternalMessage, me)); @@ -140,6 +143,7 @@ class MainController extends Component { Common.Gateway.appReady(); Common.Notifications.trigger('engineCreated', this.api); + Common.EditorApi = {get: () => this.api}; }, error => { console.log('promise failed ' + error); }); @@ -152,9 +156,16 @@ class MainController extends Component { document.body.appendChild(script); } + bindEvents() { + const {dispatch} = this.props; + this.api.asc_registerCallback('asc_onPageOrient', isPortrait => { + dispatch(Actions.changePageOrientation(isPortrait === true)); + }); + } + render() { return null } } -export default MainController; \ No newline at end of file +export default connect(null,null,null,{forwardRef:true})(MainController); diff --git a/apps/documenteditor/mobile/src/store/actions/actions.js b/apps/documenteditor/mobile/src/store/actions/actions.js new file mode 100644 index 000000000..1ae47dadb --- /dev/null +++ b/apps/documenteditor/mobile/src/store/actions/actions.js @@ -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 + } +}; diff --git a/apps/documenteditor/mobile/src/store/reducers/root.js b/apps/documenteditor/mobile/src/store/reducers/root.js index 7a876a0d0..2ef684160 100644 --- a/apps/documenteditor/mobile/src/store/reducers/root.js +++ b/apps/documenteditor/mobile/src/store/reducers/root.js @@ -1,10 +1,15 @@ import { combineReducers } from 'redux'; +import settingsReducer from './settings' import usersReducer from '../../../../../common/mobile/lib/store/users' export const initialState = { + settings: { + isPortrait: true + }, users: [] }; export const rootReducer = combineReducers({ + settings: settingsReducer, users: usersReducer }); \ No newline at end of file diff --git a/apps/documenteditor/mobile/src/store/reducers/settings.js b/apps/documenteditor/mobile/src/store/reducers/settings.js new file mode 100644 index 000000000..bfc5beb56 --- /dev/null +++ b/apps/documenteditor/mobile/src/store/reducers/settings.js @@ -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; \ No newline at end of file diff --git a/vendor/framework7-react/babel.config.js b/vendor/framework7-react/babel.config.js index 65e4452be..55b87db1c 100644 --- a/vendor/framework7-react/babel.config.js +++ b/vendor/framework7-react/babel.config.js @@ -8,5 +8,6 @@ module.exports = { plugins: [ '@babel/plugin-transform-runtime', '@babel/plugin-syntax-dynamic-import', + '@babel/plugin-proposal-class-properties', ], }; diff --git a/vendor/framework7-react/package.json b/vendor/framework7-react/package.json index 50bec7d9a..f35b6a617 100644 --- a/vendor/framework7-react/package.json +++ b/vendor/framework7-react/package.json @@ -35,6 +35,7 @@ }, "devDependencies": { "@babel/core": "^7.11.0", + "@babel/plugin-proposal-class-properties": "^7.10.4", "@babel/plugin-syntax-dynamic-import": "^7.8.3", "@babel/plugin-transform-runtime": "^7.11.0", "@babel/preset-env": "^7.11.0",