Skip to content
Snippets Groups Projects
Commit b5f1c696 authored by victor mutai's avatar victor mutai
Browse files

chore: use onMouseDown

parent 0a582c98
No related branches found
No related tags found
1 merge request!540Allow book owner to set AI use
...@@ -10,12 +10,7 @@ class ToggleAiTool extends Tools { ...@@ -10,12 +10,7 @@ class ToggleAiTool extends Tools {
renderTool(view) { renderTool(view) {
return ( return (
<ToggleAiComponent <ToggleAiComponent item={this.toJSON()} key={uuidv4()} view={view} />
displayed={false}
item={this.toJSON()}
key={uuidv4()}
view={view}
/>
); );
} }
} }
......
...@@ -110,7 +110,7 @@ const AskAIOverlay = ({ setPosition, position, config }) => { ...@@ -110,7 +110,7 @@ const AskAIOverlay = ({ setPosition, position, config }) => {
const [result, setResult] = useState(''); const [result, setResult] = useState('');
const [isSubmitted, setIsSubmitted] = useState(false); const [isSubmitted, setIsSubmitted] = useState(false);
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const { AskAiContentTransformation, AiOn } = config; const { AskAiContentTransformation } = config;
const inputRef = useRef(null); const inputRef = useRef(null);
useLayoutEffect(() => { useLayoutEffect(() => {
...@@ -135,7 +135,7 @@ const AskAIOverlay = ({ setPosition, position, config }) => { ...@@ -135,7 +135,7 @@ const AskAIOverlay = ({ setPosition, position, config }) => {
} }
setPosition({ ...position, left, top }); setPosition({ ...position, left, top });
}, [position.left, options.AiOn, AiOn]); }, [position.left, options.AiOn]);
const tryAgain = () => { const tryAgain = () => {
// Reset the state to initial values // Reset the state to initial values
...@@ -198,7 +198,7 @@ const AskAIOverlay = ({ setPosition, position, config }) => { ...@@ -198,7 +198,7 @@ const AskAIOverlay = ({ setPosition, position, config }) => {
} }
}; };
return options?.AiOn && AiOn ? ( return options?.AiOn ? (
<Wrapper id="ai-overlay"> <Wrapper id="ai-overlay">
<AskAIForm> <AskAIForm>
<AskAIFormInput <AskAIFormInput
......
import React, { useContext, useMemo } from 'react'; import React, { useContext, useMemo, useState } from 'react';
import { WaxContext, MenuButton } from 'wax-prosemirror-core'; import { WaxContext, MenuButton } from 'wax-prosemirror-core';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
const ToggleAiComponent = ({ item }) => { const ToggleAiComponent = ({ item }) => {
const { app, pmViews, options } = useContext(WaxContext); const [checked, setChecked] = useState(false);
const enableService = app.config.get('config.AskAiContentService'); const context = useContext(WaxContext);
const {
pmViews: { main },
} = context;
let isDisabled = false; let isDisabled = false;
const { main } = pmViews;
const isEditable = main.props.editable(editable => { const isEditable = main.props.editable(editable => {
return editable; return editable;
}); });
if (!isEditable) isDisabled = true; if (!isEditable) isDisabled = true;
const onMouseDown = () => {
context.setOption({ AiOn: !checked });
setChecked(!checked);
main.dispatch(main.state.tr.setMeta('addToHistory', false));
main.focus();
};
return useMemo( return useMemo(
() => () => (
enableService.AiOn ? ( <MenuButton
<MenuButton active={checked}
active={false} disabled={!isEditable}
disabled={!isEditable || !options?.AiOn} iconName={item.icon}
iconName={item.icon} onMouseDown={onMouseDown}
title={item.title} title={item.title}
/> />
) : null, ),
[enableService.AiOn, isDisabled], [checked, isDisabled],
); );
}; };
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment