mirror of
https://github.com/koodo-reader/koodo-reader.git
synced 2026-06-16 03:40:53 -04:00
feat: add quote text handling in PopupAssist and PopupOption components
This commit is contained in:
@@ -36,6 +36,18 @@ class PopupAssist extends React.Component<PopupAssistProps, PopupAssistState> {
|
||||
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"
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -181,6 +181,7 @@ class PopupOption extends React.Component<PopupOptionProps> {
|
||||
const text = getSelection(this.props.currentBook.format);
|
||||
if (!text) return;
|
||||
|
||||
this.props.handleQuoteText(text);
|
||||
this.props.handleMenuMode("assistant");
|
||||
this.props.handleOpenMenu(true);
|
||||
};
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
|
||||
@@ -122,6 +122,7 @@ export type stateType = {
|
||||
currentChapterIndex: number;
|
||||
originalText: string;
|
||||
originalSentence: string;
|
||||
quoteText: string;
|
||||
htmlBook: HtmlBookModel;
|
||||
readerBackgroundImage: string;
|
||||
};
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user