Add simple store with sidebar toggle action
[MAILPOET-2450]
This commit is contained in:
committed by
Jack Kitterhing
parent
f6ad1903ba
commit
a94cf7e162
@ -1,20 +1,31 @@
|
||||
import React from 'react';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
import classnames from 'classnames';
|
||||
import Header from './header.jsx';
|
||||
import Sidebar from './sidebar.jsx';
|
||||
import FormTitle from './form_title.jsx';
|
||||
|
||||
export default () => (
|
||||
<div className="edit-post-layout is-sidebar-opened">
|
||||
<Header />
|
||||
<div className="edit-post-layout__content">
|
||||
<div className="edit-post-visual-editor editor-styles-wrapper">
|
||||
<div className="editor-writing-flow block-editor-writing-flow">
|
||||
<FormTitle />
|
||||
export default () => {
|
||||
const sidebarOpened = useSelect(
|
||||
(select) => select('mailpoet-form-editor').getSidebarOpened(),
|
||||
[]
|
||||
);
|
||||
const layoutClass = classnames('edit-post-layout', {
|
||||
'is-sidebar-opened': sidebarOpened,
|
||||
});
|
||||
return (
|
||||
<div className={layoutClass}>
|
||||
<Header />
|
||||
<div className="edit-post-layout__content">
|
||||
<div className="edit-post-visual-editor editor-styles-wrapper">
|
||||
<div className="editor-writing-flow block-editor-writing-flow">
|
||||
<FormTitle />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
{ sidebarOpened ? <Sidebar /> : '' }
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<Sidebar />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
);
|
||||
};
|
||||
|
@ -1,22 +1,31 @@
|
||||
import React from 'react';
|
||||
import { IconButton } from '@wordpress/components';
|
||||
import { useDispatch, useSelect } from '@wordpress/data';
|
||||
|
||||
export default () => (
|
||||
<div className="edit-post-header">
|
||||
<div className="edit-post-header-toolbar" />
|
||||
<div className="edit-post-header__settings">
|
||||
<button
|
||||
type="button"
|
||||
className="components-button editor-post-publish-panel__toggle is-button is-primary"
|
||||
>
|
||||
Save
|
||||
</button>
|
||||
<IconButton
|
||||
icon="admin-generic"
|
||||
label="Settings"
|
||||
onClick={() => null}
|
||||
isToggled
|
||||
/>
|
||||
export default () => {
|
||||
const sidebarOpened = useSelect(
|
||||
(select) => select('mailpoet-form-editor').getSidebarOpened(),
|
||||
[]
|
||||
);
|
||||
const { toggleSidebar } = useDispatch('mailpoet-form-editor');
|
||||
return (
|
||||
<div className="edit-post-header">
|
||||
<div className="edit-post-header-toolbar" />
|
||||
<div className="edit-post-header__settings">
|
||||
<button
|
||||
type="button"
|
||||
className="components-button editor-post-publish-panel__toggle is-button is-primary"
|
||||
>
|
||||
Save
|
||||
</button>
|
||||
<IconButton
|
||||
icon="admin-generic"
|
||||
label="Settings"
|
||||
labelPosition="down"
|
||||
onClick={() => toggleSidebar(!sidebarOpened)}
|
||||
isToggled={sidebarOpened}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
);
|
||||
};
|
||||
|
@ -1,5 +1,6 @@
|
||||
import React, { useState } from 'react';
|
||||
import { IconButton } from '@wordpress/components';
|
||||
import { useDispatch } from '@wordpress/data';
|
||||
import PropTypes from 'prop-types';
|
||||
import BlockSettings from './block_settings.jsx';
|
||||
import FormSettings from './form_settings.jsx';
|
||||
@ -26,9 +27,12 @@ SidebarHeader.propTypes = {
|
||||
|
||||
export default () => {
|
||||
const [activeTab, setActiveTab] = useState('form');
|
||||
|
||||
const { toggleSidebar } = useDispatch('mailpoet-form-editor');
|
||||
|
||||
return (
|
||||
<div className="edit-post-sidebar">
|
||||
<SidebarHeader>
|
||||
<SidebarHeader closeSidebar={() => toggleSidebar(false)}>
|
||||
<ul>
|
||||
<li>
|
||||
<button
|
||||
|
@ -1,10 +1,12 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import Editor from './components/editor.jsx';
|
||||
import initStore from './store/index.jsx';
|
||||
|
||||
const appElement = document.querySelector('#mailpoet_form_edit');
|
||||
|
||||
if (appElement) {
|
||||
initStore();
|
||||
ReactDOM.render(
|
||||
<Editor />,
|
||||
appElement
|
||||
|
8
assets/js/src/form_editor/store/actions.jsx
Normal file
8
assets/js/src/form_editor/store/actions.jsx
Normal file
@ -0,0 +1,8 @@
|
||||
export default {
|
||||
toggleSidebar(toggleTo) {
|
||||
return {
|
||||
type: 'TOGGLE_SIDEBAR',
|
||||
toggleTo,
|
||||
};
|
||||
},
|
||||
};
|
14
assets/js/src/form_editor/store/index.jsx
Normal file
14
assets/js/src/form_editor/store/index.jsx
Normal file
@ -0,0 +1,14 @@
|
||||
import { registerStore } from '@wordpress/data';
|
||||
import actions from './actions.jsx';
|
||||
import reducer from './reducer.jsx';
|
||||
import selectors from './selectors.jsx';
|
||||
|
||||
const config = {
|
||||
reducer,
|
||||
actions,
|
||||
selectors,
|
||||
controls: {},
|
||||
resolvers: {},
|
||||
};
|
||||
|
||||
export default () => (registerStore('mailpoet-form-editor', config));
|
15
assets/js/src/form_editor/store/reducer.jsx
Normal file
15
assets/js/src/form_editor/store/reducer.jsx
Normal file
@ -0,0 +1,15 @@
|
||||
const DEFAULT_STATE = {
|
||||
sidebarOpened: true,
|
||||
};
|
||||
|
||||
export default (state = DEFAULT_STATE, action) => {
|
||||
switch (action.type) {
|
||||
case 'TOGGLE_SIDEBAR':
|
||||
return {
|
||||
...state,
|
||||
sidebarOpened: action.toggleTo,
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
5
assets/js/src/form_editor/store/selectors.jsx
Normal file
5
assets/js/src/form_editor/store/selectors.jsx
Normal file
@ -0,0 +1,5 @@
|
||||
export default {
|
||||
getSidebarOpened(state) {
|
||||
return state.sidebarOpened;
|
||||
},
|
||||
};
|
Reference in New Issue
Block a user