mirror of
https://github.com/WenPai-org/wpmind.git
synced 2025-08-04 03:29:33 +08:00
added main store, which contains the selectors from mindData variable
This commit is contained in:
parent
24e76280d4
commit
742c0a0bf1
7 changed files with 48 additions and 9 deletions
|
@ -60,8 +60,8 @@ class Mind_Assets {
|
||||||
'mind-editor',
|
'mind-editor',
|
||||||
'mindData',
|
'mindData',
|
||||||
array(
|
array(
|
||||||
'connected' => ! ! $openai_key,
|
'connected' => ! ! $openai_key,
|
||||||
'settingsURL' => admin_url( 'admin.php?page=mind' ),
|
'settingsPageURL' => admin_url( 'admin.php?page=mind' ),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import './style.scss';
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
|
import './store/core';
|
||||||
import './store/blocks';
|
import './store/blocks';
|
||||||
import './store/popup';
|
import './store/popup';
|
||||||
import './popup';
|
import './popup';
|
||||||
|
|
|
@ -7,10 +7,17 @@ import './style.scss';
|
||||||
* WordPress dependencies
|
* WordPress dependencies
|
||||||
*/
|
*/
|
||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
|
import { useSelect } from '@wordpress/data';
|
||||||
const { settingsURL } = window.mindData;
|
|
||||||
|
|
||||||
export default function NotConnectedScreen() {
|
export default function NotConnectedScreen() {
|
||||||
|
const { settingsPageURL } = useSelect((select) => {
|
||||||
|
const { getSettingsPageURL } = select('mind');
|
||||||
|
|
||||||
|
return {
|
||||||
|
settingsPageURL: getSettingsPageURL(),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mind-popup-connected-screen">
|
<div className="mind-popup-connected-screen">
|
||||||
<h2>{__('OpenAI Key', 'mind')}</h2>
|
<h2>{__('OpenAI Key', 'mind')}</h2>
|
||||||
|
@ -25,7 +32,7 @@ export default function NotConnectedScreen() {
|
||||||
<div>
|
<div>
|
||||||
<a
|
<a
|
||||||
className="mind-popup-connected-screen-button"
|
className="mind-popup-connected-screen-button"
|
||||||
href={settingsURL}
|
href={settingsPageURL}
|
||||||
>
|
>
|
||||||
{__('Go to Settings', 'mind')}
|
{__('Go to Settings', 'mind')}
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -22,17 +22,15 @@ import Content from './components/content';
|
||||||
import Footer from './components/footer';
|
import Footer from './components/footer';
|
||||||
import NotConnectedScreen from './components/not-connected-screen';
|
import NotConnectedScreen from './components/not-connected-screen';
|
||||||
|
|
||||||
const { connected } = window.mindData;
|
|
||||||
|
|
||||||
const POPUP_CONTAINER_CLASS = 'mind-popup-container';
|
const POPUP_CONTAINER_CLASS = 'mind-popup-container';
|
||||||
|
|
||||||
export default function Popup() {
|
export default function Popup() {
|
||||||
const { setHighlightBlocks } = useDispatch('mind/blocks');
|
const { setHighlightBlocks } = useDispatch('mind/blocks');
|
||||||
|
|
||||||
const { close, reset } = useDispatch('mind/popup');
|
const { close, reset } = useDispatch('mind/popup');
|
||||||
|
|
||||||
const { isOpen, insertionPlace, loading, response } = useSelect(
|
const { connected, isOpen, insertionPlace, loading, response } = useSelect(
|
||||||
(select) => {
|
(select) => {
|
||||||
|
const { isConnected } = select('mind');
|
||||||
const {
|
const {
|
||||||
isOpen: checkIsOpen,
|
isOpen: checkIsOpen,
|
||||||
getInsertionPlace,
|
getInsertionPlace,
|
||||||
|
@ -41,6 +39,7 @@ export default function Popup() {
|
||||||
} = select('mind/popup');
|
} = select('mind/popup');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
connected: isConnected(),
|
||||||
isOpen: checkIsOpen(),
|
isOpen: checkIsOpen(),
|
||||||
insertionPlace: getInsertionPlace(),
|
insertionPlace: getInsertionPlace(),
|
||||||
loading: getLoading(),
|
loading: getLoading(),
|
||||||
|
|
18
src/store/core/index.js
Normal file
18
src/store/core/index.js
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/**
|
||||||
|
* Internal dependencies
|
||||||
|
*/
|
||||||
|
import * as selectors from './selectors';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WordPress dependencies
|
||||||
|
*/
|
||||||
|
import { createReduxStore, register } from '@wordpress/data';
|
||||||
|
|
||||||
|
const store = createReduxStore('mind', {
|
||||||
|
selectors,
|
||||||
|
reducer(state) {
|
||||||
|
return state;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
register(store);
|
9
src/store/core/selectors.js
Normal file
9
src/store/core/selectors.js
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
const { connected, settingsPageURL } = window.mindData;
|
||||||
|
|
||||||
|
export function isConnected() {
|
||||||
|
return connected === '1';
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getSettingsPageURL() {
|
||||||
|
return settingsPageURL;
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ import apiFetch from '@wordpress/api-fetch';
|
||||||
* Internal dependencies.
|
* Internal dependencies.
|
||||||
*/
|
*/
|
||||||
import getSelectedBlocksContent from '../../utils/get-selected-blocks-content';
|
import getSelectedBlocksContent from '../../utils/get-selected-blocks-content';
|
||||||
|
import { isConnected } from '../core/selectors';
|
||||||
|
|
||||||
export function open() {
|
export function open() {
|
||||||
return {
|
return {
|
||||||
|
@ -78,6 +79,10 @@ export function setError(error) {
|
||||||
|
|
||||||
export function requestAI() {
|
export function requestAI() {
|
||||||
return ({ dispatch, select }) => {
|
return ({ dispatch, select }) => {
|
||||||
|
if (!isConnected) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const loading = select.getLoading();
|
const loading = select.getLoading();
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue