[DE mobile] Add popover in Edit Settings of tablet, refactoring

This commit is contained in:
JuliaSvinareva 2020-10-21 15:40:46 +03:00
parent 80cec1f6c1
commit 209a7d54ca
3 changed files with 82 additions and 60 deletions

View file

@ -1,26 +1,61 @@
import React, {useState, useEffect} from 'react'; import React, {useState, useEffect} from 'react';
import {observer, inject} from "mobx-react"; import {observer, inject} from "mobx-react";
import { Page, Navbar, NavRight, NavLeft, NavTitle, Link, Sheet, Tabs, Tab, View } from 'framework7-react'; import { Popover, Sheet, View, Page, Navbar, NavRight, NavLeft, NavTitle, Tabs, Tab, Link } from 'framework7-react';
import { f7 } from 'framework7-react'; import { f7 } from 'framework7-react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import {Device} from '../../../../../common/mobile/utils/device';
import EditTextController from "./controller/EditText"; import EditTextController from "./controller/EditText";
import EditParagraphController from "./controller/EditParagraph"; import EditParagraphController from "./controller/EditParagraph";
import {PageAdditionalFormatting, PageBullets, PageFonts, PageLineSpacing, PageNumbers} from "./EditText";
import {PageAdvancedSettings} from "./EditParagraph";
const routes = [
//Edit text
{
path: '/edit-text-fonts/',
component: PageFonts,
},
{
path: '/edit-text-add-formatting/',
component: PageAdditionalFormatting,
},
{
path: '/edit-text-bullets/',
component: PageBullets,
},
{
path: '/edit-text-numbers/',
component: PageNumbers,
},
{
path: '/edit-text-line-spacing/',
component: PageLineSpacing,
},
//Edit paragraph
{
path: '/edit-paragraph-adv/',
component: PageAdvancedSettings,
}
];
const EmptyEditLayout = () => { const EmptyEditLayout = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const _t = t('Edit', {returnObjects: true});
return ( return (
<Page> <Page>
<div className="content-block inset"> <div className="content-block inset">
<div className="content-block-inner"> <div className="content-block-inner">
<p>{t("Edit.textSelectObjectToEdit")}</p> <p>{_t.textSelectObjectToEdit}</p>
</div> </div>
</div> </div>
</Page> </Page>
) )
}; };
const EditLayoutNavbar = ({ editors }) => { const EditLayoutNavbar = ({ editors, inPopover }) => {
const { t } = useTranslation(); const { t } = useTranslation();
const _t = t('Edit', {returnObjects: true});
return ( return (
<Navbar> <Navbar>
{ {
@ -30,9 +65,7 @@ const EditLayoutNavbar = ({ editors }) => {
</NavLeft> : </NavLeft> :
<NavTitle>{ editors[0].caption }</NavTitle> <NavTitle>{ editors[0].caption }</NavTitle>
} }
<NavRight> { !inPopover && <NavRight><Link sheetClose>{_t.textClose}</Link></NavRight> }
<Link sheetClose>{t("Edit.textClose")}</Link>
</NavRight>
</Navbar> </Navbar>
) )
}; };
@ -57,70 +90,71 @@ const EditLayoutContent = ({ editors }) => {
} }
}; };
const EditSheet = props => { const EditTabs = props => {
const { t } = useTranslation(); const { t } = useTranslation();
const _t = t('Edit', {returnObjects: true});
const settings = props.storeFocusObjects.settings; const settings = props.storeFocusObjects.settings;
const headerType = props.storeFocusObjects.headerType; const headerType = props.storeFocusObjects.headerType;
let editors = []; let editors = [];
if (settings.length < 1) { if (settings.length < 1) {
editors.push({ editors.push({
caption: t("Edit.textSettings"), caption: _t.textSettings,
component: <EmptyEditLayout /> component: <EmptyEditLayout />
}); });
} else { } else {
if (settings.indexOf('text') > -1) { if (settings.indexOf('text') > -1) {
editors.push({ editors.push({
caption: t("Edit.textText"), caption: _t.textText,
id: 'edit-text', id: 'edit-text',
component: <EditTextController /> component: <EditTextController />
}) })
} }
if (settings.indexOf('paragraph') > -1) { if (settings.indexOf('paragraph') > -1) {
editors.push({ editors.push({
caption: t("Edit.textParagraph"), caption: _t.textParagraph,
id: 'edit-paragraph', id: 'edit-paragraph',
component: <EditParagraphController /> component: <EditParagraphController />
}) })
} }
/*if (settings.indexOf('table') > -1) { /*if (settings.indexOf('table') > -1) {
editors.push({ editors.push({
caption: t("Edit.textTable"), caption: _t.textTable,
id: 'edit-table', id: 'edit-table',
component: <EditTable /> component: <EditTable />
}) })
} }
if (settings.indexOf('header') > -1) { if (settings.indexOf('header') > -1) {
editors.push({ editors.push({
caption: headerType==2 ? t("Edit.textFooter") : t("Edit.textHeader"), caption: headerType==2 ? _t.textFooter : _t.textHeader,
id: 'edit-header', id: 'edit-header',
component: <EditHeader /> component: <EditHeader />
}) })
} }
if (settings.indexOf('shape') > -1) { if (settings.indexOf('shape') > -1) {
editors.push({ editors.push({
caption: t("Edit.textShape"), caption: _t.textShape,
id: 'edit-shape', id: 'edit-shape',
component: <EditShape /> component: <EditShape />
}) })
} }
if (settings.indexOf('image') > -1) { if (settings.indexOf('image') > -1) {
editors.push({ editors.push({
caption: t("Edit.textImage"), caption: _t.textImage,
id: 'edit-image', id: 'edit-image',
component: <EditImage /> component: <EditImage />
}) })
} }
if (settings.indexOf('chart') > -1) { if (settings.indexOf('chart') > -1) {
editors.push({ editors.push({
caption: t("Edit.textChart"), caption: _t.textChart,
id: 'edit-chart', id: 'edit-chart',
component: <EditChart /> component: <EditChart />
}) })
} }
if (settings.indexOf('hyperlink') > -1) { if (settings.indexOf('hyperlink') > -1) {
editors.push({ editors.push({
caption: t("Edit.textHyperlink"), caption: _t.textHyperlink,
id: 'edit-link', id: 'edit-link',
component: <EditHyperlink /> component: <EditHyperlink />
}) })
@ -128,34 +162,52 @@ const EditSheet = props => {
} }
return ( return (
<Sheet className="edit__sheet" push onSheetClosed={e => props.onclosed()}> <View style={props.style} stackPages={true} routes={routes}>
<View> <Page pageContent={false}>
<Page pageContent={false}> <EditLayoutNavbar editors={editors} inPopover={props.inPopover}/>
<EditLayoutNavbar editors={editors} /> <EditLayoutContent editors={editors} />
<EditLayoutContent editors={editors} /> </Page>
</Page> </View>
</View>
</Sheet>
) )
}; };
const HOC_EditSheet = inject("storeFocusObjects")(observer(EditSheet)); const EditTabsContainer = inject("storeFocusObjects")(observer(EditTabs));
const EditView = props => {
const onOptionClick = (page) => {
$f7.views.current.router.navigate(page);
};
const show_popover = props.usePopover;
return (
show_popover ?
<Popover id="edit-popover" className="popover__titled" onPopoverClosed={() => props.onClosed()}>
<EditTabsContainer inPopover={true} onOptionClick={onOptionClick} style={{height: '410px'}} />
</Popover> :
<Sheet id="edit-sheet" push onSheetClosed={() => props.onClosed()}>
<EditTabsContainer onOptionClick={onOptionClick} />
</Sheet>
)
};
const EditOptions = props => { const EditOptions = props => {
useEffect(() => { useEffect(() => {
f7.sheet.open('.edit__sheet'); if ( Device.phone )
f7.sheet.open('#edit-sheet');
else f7.popover.open('#edit-popover', '#btn-edit');
return () => { return () => {
// component will unmount // component will unmount
} }
}); });
const onsheetclosed = () => { const onviewclosed = () => {
if ( props.onclosed ) props.onclosed(); if ( props.onclosed )
props.onclosed();
}; };
return ( return (
<HOC_EditSheet onclosed={onsheetclosed} /> <EditView usePopover={!Device.phone} onClosed={onviewclosed} />
) )
}; };

View file

@ -8,40 +8,10 @@ import RequestAndLoad from '../pages/request-and-load.jsx';
import { PageCollaboration, PageUsers } from '../../../../common/mobile/lib/view/Collaboration.jsx'; import { PageCollaboration, PageUsers } from '../../../../common/mobile/lib/view/Collaboration.jsx';
// Edit
import { PageFonts, PageAdditionalFormatting, PageBullets, PageNumbers, PageLineSpacing } from "../components/edit/EditText";
import { PageAdvancedSettings } from "../components/edit/EditParagraph";
var routes = [ var routes = [
{ {
path: '/', path: '/',
component: HomePage, component: HomePage,
},
//Edit text
{
path: '/edit-text-fonts/',
component: PageFonts,
},
{
path: '/edit-text-add-formatting/',
component: PageAdditionalFormatting,
},
{
path: '/edit-text-bullets/',
component: PageBullets,
},
{
path: '/edit-text-numbers/',
component: PageNumbers,
},
{
path: '/edit-text-line-spacing/',
component: PageLineSpacing,
},
//Edit paragraph
{
path: '/edit-paragraph-adv/',
component: PageAdvancedSettings,
}, },
{ {
path: '/users/', path: '/users/',

View file

@ -55,8 +55,8 @@ export default class Home extends Component {
<Link>Redo</Link> <Link>Redo</Link>
</NavLeft> </NavLeft>
<NavRight> <NavRight>
<Link href={false} onClick={e => this.handleClickToOpenOptions('edit')}>Edit</Link>
<Link href={false} onClick={e => this.handleClickToOpenOptions('coauth')}>Users</Link> <Link href={false} onClick={e => this.handleClickToOpenOptions('coauth')}>Users</Link>
<Link href={false} onClick={e => this.handleClickToOpenOptions('edit')} id='btn-edit'>Edit</Link>
<Link href={false} onClick={e => this.handleClickToOpenOptions('settings')} id='btn-settings'>Settings</Link> <Link href={false} onClick={e => this.handleClickToOpenOptions('settings')} id='btn-settings'>Settings</Link>
</NavRight> </NavRight>
</Navbar> </Navbar>