Hide the task list and store the state in the store
[MAILPOET-4826]
This commit is contained in:
committed by
Aschepikov
parent
be592dbf9b
commit
b0e8263e2f
@@ -1,9 +1,17 @@
|
|||||||
import { MailPoet } from 'mailpoet';
|
import { MailPoet } from 'mailpoet';
|
||||||
|
import { useSelect, useDispatch } from '@wordpress/data';
|
||||||
import { DropdownMenu } from '@wordpress/components';
|
import { DropdownMenu } from '@wordpress/components';
|
||||||
import { moreVertical } from '@wordpress/icons';
|
import { moreVertical } from '@wordpress/icons';
|
||||||
|
import { storeName } from 'homepage/store/store';
|
||||||
|
|
||||||
export function TaskList(): JSX.Element {
|
export function TaskList(): JSX.Element {
|
||||||
return (
|
const isTaskListHidden = useSelect(
|
||||||
|
(select) => select(storeName).getIsTaskListHidden(),
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
const { hideTaskList } = useDispatch(storeName);
|
||||||
|
|
||||||
|
return isTaskListHidden ? null : (
|
||||||
<>
|
<>
|
||||||
<h1>{MailPoet.I18n.t('welcomeToMailPoet')}</h1>
|
<h1>{MailPoet.I18n.t('welcomeToMailPoet')}</h1>
|
||||||
<h2>{MailPoet.I18n.t('beginByCompletingSetup')}</h2>
|
<h2>{MailPoet.I18n.t('beginByCompletingSetup')}</h2>
|
||||||
@@ -13,7 +21,7 @@ export function TaskList(): JSX.Element {
|
|||||||
controls={[
|
controls={[
|
||||||
{
|
{
|
||||||
title: MailPoet.I18n.t('hideList'),
|
title: MailPoet.I18n.t('hideList'),
|
||||||
onClick: () => {},
|
onClick: hideTaskList,
|
||||||
icon: null,
|
icon: null,
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import { useEffect } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { GlobalContext, useGlobalContextValue } from 'context/index.jsx';
|
import { GlobalContext, useGlobalContextValue } from 'context/index.jsx';
|
||||||
import { TopBarWithBeamer } from 'common/top_bar/top_bar';
|
import { TopBarWithBeamer } from 'common/top_bar/top_bar';
|
||||||
import { HomepageNotices } from 'homepage/notices';
|
import { HomepageNotices } from 'homepage/notices';
|
||||||
@@ -7,20 +7,21 @@ import { TaskList } from './components/task-list';
|
|||||||
import { createStore } from './store/store';
|
import { createStore } from './store/store';
|
||||||
|
|
||||||
function App(): JSX.Element {
|
function App(): JSX.Element {
|
||||||
|
const [isStoreInitialized, setIsStoreInitialized] = useState(false);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
createStore();
|
createStore();
|
||||||
|
setIsStoreInitialized(true);
|
||||||
}, []);
|
}, []);
|
||||||
return (
|
return (
|
||||||
<GlobalContext.Provider value={useGlobalContextValue(window)}>
|
<GlobalContext.Provider value={useGlobalContextValue(window)}>
|
||||||
<TopBarWithBeamer />
|
<TopBarWithBeamer />
|
||||||
<HomepageNotices />
|
<HomepageNotices />
|
||||||
<TaskList />
|
{isStoreInitialized ? <TaskList /> : null}
|
||||||
</GlobalContext.Provider>
|
</GlobalContext.Provider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const container = document.getElementById('mailpoet_homepage_container');
|
const container = document.getElementById('mailpoet_homepage_container');
|
||||||
|
|
||||||
if (container) {
|
if (container) {
|
||||||
ReactDOM.render(<App />, container);
|
ReactDOM.render(<App />, container);
|
||||||
}
|
}
|
||||||
|
3
mailpoet/assets/js/src/homepage/store/actions.ts
Normal file
3
mailpoet/assets/js/src/homepage/store/actions.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export const hideTaskList = () => ({
|
||||||
|
type: 'SET_TASK_LIST_HIDDEN',
|
||||||
|
});
|
9
mailpoet/assets/js/src/homepage/store/initial-state.ts
Normal file
9
mailpoet/assets/js/src/homepage/store/initial-state.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { State } from './types';
|
||||||
|
|
||||||
|
export function getInitialState(): State {
|
||||||
|
return {
|
||||||
|
taskList: {
|
||||||
|
isTaskListHidden: false,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
17
mailpoet/assets/js/src/homepage/store/reducer.ts
Normal file
17
mailpoet/assets/js/src/homepage/store/reducer.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { Action } from '@wordpress/data';
|
||||||
|
import { State } from './types';
|
||||||
|
|
||||||
|
export function reducer(state: State, action: Action): State {
|
||||||
|
switch (action.type) {
|
||||||
|
case 'SET_TASK_LIST_HIDDEN':
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
taskList: {
|
||||||
|
...state.taskList,
|
||||||
|
isTaskListHidden: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
5
mailpoet/assets/js/src/homepage/store/selectors.ts
Normal file
5
mailpoet/assets/js/src/homepage/store/selectors.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import { State } from './types';
|
||||||
|
|
||||||
|
export function getIsTaskListHidden(state: State): boolean {
|
||||||
|
return state.taskList.isTaskListHidden;
|
||||||
|
}
|
@@ -5,31 +5,27 @@ import {
|
|||||||
StoreDescriptor,
|
StoreDescriptor,
|
||||||
} from '@wordpress/data';
|
} from '@wordpress/data';
|
||||||
import { OmitFirstArgs } from 'types';
|
import { OmitFirstArgs } from 'types';
|
||||||
|
import { getInitialState } from './initial-state';
|
||||||
|
import * as actions from './actions';
|
||||||
|
import * as selectors from './selectors';
|
||||||
|
import { reducer } from './reducer';
|
||||||
|
import { State } from './types';
|
||||||
|
|
||||||
const storeName = 'mailpoet/homepage';
|
export const storeName = 'mailpoet/homepage';
|
||||||
const actions = {};
|
|
||||||
const selectors = {};
|
|
||||||
const controls = {};
|
const controls = {};
|
||||||
const reducer = (state) => state;
|
|
||||||
const initialState = {};
|
|
||||||
|
|
||||||
type StoreType = Omit<StoreDescriptor, 'name'> & {
|
type StoreType = Omit<StoreDescriptor, 'name'> & {
|
||||||
name: typeof storeName;
|
name: typeof storeName;
|
||||||
};
|
};
|
||||||
type State = {
|
|
||||||
[K in string]: never;
|
|
||||||
};
|
|
||||||
type EditorStoreConfigType = StoreConfig<State>;
|
type EditorStoreConfigType = StoreConfig<State>;
|
||||||
|
|
||||||
export const createStore = (): StoreType => {
|
export const createStore = (): StoreType => {
|
||||||
const storeConfig = {
|
const storeConfig = {
|
||||||
actions,
|
actions,
|
||||||
controls,
|
controls,
|
||||||
selectors,
|
selectors,
|
||||||
reducer,
|
reducer,
|
||||||
initialState,
|
initialState: getInitialState(),
|
||||||
} as EditorStoreConfigType;
|
} as EditorStoreConfigType;
|
||||||
|
|
||||||
const store = createReduxStore<State>(storeName, storeConfig) as StoreType;
|
const store = createReduxStore<State>(storeName, storeConfig) as StoreType;
|
||||||
register(store);
|
register(store);
|
||||||
return store;
|
return store;
|
||||||
|
7
mailpoet/assets/js/src/homepage/store/types.ts
Normal file
7
mailpoet/assets/js/src/homepage/store/types.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
export type TaskListState = {
|
||||||
|
isTaskListHidden: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type State = {
|
||||||
|
taskList: TaskListState;
|
||||||
|
};
|
Reference in New Issue
Block a user