aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/pdf/AnchorMenu.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/pdf/AnchorMenu.tsx')
-rw-r--r--src/client/views/pdf/AnchorMenu.tsx24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/client/views/pdf/AnchorMenu.tsx b/src/client/views/pdf/AnchorMenu.tsx
index 844c1e36d..7cb6a20f4 100644
--- a/src/client/views/pdf/AnchorMenu.tsx
+++ b/src/client/views/pdf/AnchorMenu.tsx
@@ -15,6 +15,7 @@ import { AntimodeMenu, AntimodeMenuProps } from '../AntimodeMenu';
import { LinkPopup } from '../linking/LinkPopup';
import './AnchorMenu.scss';
import { GPTPopup, GPTPopupMode } from './GPTPopup/GPTPopup';
+import { PDFViewer } from 'pdfjs-dist/web/pdf_viewer.mjs';
@observer
export class AnchorMenu extends AntimodeMenu<AntimodeMenuProps> {
@@ -57,6 +58,7 @@ export class AnchorMenu extends AntimodeMenu<AntimodeMenuProps> {
public get Active() {
return this._left > 0;
}
+ public addToCollection: ((doc: Doc | Doc[], annotationKey?: string | undefined) => boolean) | undefined;
componentWillUnmount() {
this._disposer?.();
@@ -96,14 +98,34 @@ export class AnchorMenu extends AntimodeMenu<AntimodeMenuProps> {
try {
const res = await gptAPICall(this.selectedText, GPTCallType.FLASHCARD);
+
GPTPopup.Instance.setText(res || 'Something went wrong.');
- GPTPopup.Instance.transferToFlashcard();
+ this.transferToFlashcard(res);
} catch (err) {
console.error(err);
}
GPTPopup.Instance.setLoading(false);
};
+ transferToFlashcard = (text: string) => {
+ const senArr = text.split('Question');
+ const collectionArr: Doc[] = [];
+ for (var i = 1; i < senArr.length; i++) {
+ console.log('Arr ' + i + ': ' + senArr[i]);
+ const newDoc = Docs.Create.ComparisonDocument(senArr[i], { _layout_isFlashcard: true, _width: 300, _height: 300 });
+ newDoc.text = senArr[i];
+ collectionArr.push(newDoc);
+ }
+ const newCol = Docs.Create.CarouselDocument(collectionArr, {
+ _width: 200,
+ _height: 200,
+ _layout_fitWidth: true,
+ _layout_autoHeight: true,
+ });
+
+ this.addToCollection?.(newCol);
+ };
+
pointerDown = (e: React.PointerEvent) => {
setupMoveUpEvents(
this,