diff --git a/src/components/popups/popupAssist/component.tsx b/src/components/popups/popupAssist/component.tsx index a881648d..5ee5d330 100644 --- a/src/components/popups/popupAssist/component.tsx +++ b/src/components/popups/popupAssist/component.tsx @@ -36,6 +36,18 @@ class PopupAssist extends React.Component { this.textareaRef = React.createRef(); } componentDidMount(): void { + if (this.props.quoteText) { + this.setState({ inputQuestion: this.props.quoteText + "\n" }, () => { + this.autoResizeTextarea(); + const el = this.textareaRef.current; + if (el) { + el.focus(); + const len = el.value.length; + el.setSelectionRange(len, len); + } + }); + this.props.handleQuoteText(""); + } if (!this.state.aiService) { let pluginList = this.props.plugins.filter( (item) => item.type === "assistant" diff --git a/src/components/popups/popupAssist/index.tsx b/src/components/popups/popupAssist/index.tsx index a97e722a..b625f877 100644 --- a/src/components/popups/popupAssist/index.tsx +++ b/src/components/popups/popupAssist/index.tsx @@ -5,6 +5,7 @@ import { handleFetchPlugins, handleSetting, handleSettingMode, + handleQuoteText, } from "../../../store/actions"; import { stateType } from "../../../store"; import { withTranslation } from "react-i18next"; @@ -12,6 +13,7 @@ import PopupTrans from "./component"; const mapStateToProps = (state: stateType) => { return { originalText: state.reader.originalText, + quoteText: state.reader.quoteText, plugins: state.manager.plugins, isAuthed: state.manager.isAuthed, }; @@ -22,6 +24,7 @@ const actionCreator = { handleFetchPlugins, handleSetting, handleSettingMode, + handleQuoteText, }; export default connect( mapStateToProps, diff --git a/src/components/popups/popupAssist/interface.tsx b/src/components/popups/popupAssist/interface.tsx index bb511187..20443a6c 100644 --- a/src/components/popups/popupAssist/interface.tsx +++ b/src/components/popups/popupAssist/interface.tsx @@ -1,8 +1,10 @@ import PluginModel from "../../../models/Plugin"; export interface PopupAssistProps { originalText: string; + quoteText: string; plugins: PluginModel[]; isAuthed: boolean; + handleQuoteText: (quoteText: string) => void; handleOpenMenu: (isOpenMenu: boolean) => void; handleMenuMode: (menu: string) => void; handleFetchPlugins: () => void; diff --git a/src/components/popups/popupOption/component.tsx b/src/components/popups/popupOption/component.tsx index 55b1f85b..c6547725 100644 --- a/src/components/popups/popupOption/component.tsx +++ b/src/components/popups/popupOption/component.tsx @@ -181,6 +181,7 @@ class PopupOption extends React.Component { const text = getSelection(this.props.currentBook.format); if (!text) return; + this.props.handleQuoteText(text); this.props.handleMenuMode("assistant"); this.props.handleOpenMenu(true); }; diff --git a/src/components/popups/popupOption/index.tsx b/src/components/popups/popupOption/index.tsx index db536622..7ccaa8a1 100644 --- a/src/components/popups/popupOption/index.tsx +++ b/src/components/popups/popupOption/index.tsx @@ -14,6 +14,7 @@ import { handleOriginalText, handleOriginalSentence, handleNoteKey, + handleQuoteText, } from "../../../store/actions"; import { stateType } from "../../../store"; import { withTranslation } from "react-i18next"; @@ -41,6 +42,7 @@ const actionCreator = { handleSpeechDialog, handleSpeechStartText, handleSpeechAutoStart, + handleQuoteText, }; export default connect( mapStateToProps, diff --git a/src/components/popups/popupOption/interface.tsx b/src/components/popups/popupOption/interface.tsx index ff8c5500..1b08429e 100644 --- a/src/components/popups/popupOption/interface.tsx +++ b/src/components/popups/popupOption/interface.tsx @@ -22,6 +22,7 @@ export interface PopupOptionProps { handleFetchNotes: () => void; handleOriginalText: (originalText: string) => void; handleOriginalSentence: (originalSentence: string) => void; + handleQuoteText: (quoteText: string) => void; handleChangeDirection: (isChangeDirection: boolean) => void; t: (title: string) => string; } diff --git a/src/store/actions/reader.tsx b/src/store/actions/reader.tsx index 5932b080..28f4983b 100644 --- a/src/store/actions/reader.tsx +++ b/src/store/actions/reader.tsx @@ -16,6 +16,9 @@ export function handleHighlights(highlights: NoteModel[]) { export function handleOriginalText(originalText: string) { return { type: "HANDLE_ORIGINAL_TEXT", payload: originalText }; } +export function handleQuoteText(quoteText: string) { + return { type: "HANDLE_QUOTE_TEXT", payload: quoteText }; +} export function handleOriginalSentence(originalSentence: string) { return { type: "HANDLE_ORIGINAL_SENTENCE", payload: originalSentence }; } diff --git a/src/store/index.tsx b/src/store/index.tsx index 2ea913a9..c81385b0 100644 --- a/src/store/index.tsx +++ b/src/store/index.tsx @@ -122,6 +122,7 @@ export type stateType = { currentChapterIndex: number; originalText: string; originalSentence: string; + quoteText: string; htmlBook: HtmlBookModel; readerBackgroundImage: string; }; diff --git a/src/store/reducers/reader.tsx b/src/store/reducers/reader.tsx index 7018f4c6..6bad13a2 100644 --- a/src/store/reducers/reader.tsx +++ b/src/store/reducers/reader.tsx @@ -26,6 +26,7 @@ const initState = { noteKey: "", originalText: "", originalSentence: "", + quoteText: "", htmlBook: null, scale: ConfigService.getReaderConfig("scale") || "1", margin: ConfigService.getReaderConfig("margin") || "0", @@ -110,6 +111,11 @@ export function reader( ...state, originalText: action.payload, }; + case "HANDLE_QUOTE_TEXT": + return { + ...state, + quoteText: action.payload, + }; case "HANDLE_ORIGINAL_SENTENCE": return { ...state,