aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/pdf
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/pdf')
-rw-r--r--src/client/views/pdf/AnchorMenu.tsx27
-rw-r--r--src/client/views/pdf/GPTPopup/GPTPopup.tsx45
-rw-r--r--src/client/views/pdf/PDFViewer.tsx4
3 files changed, 17 insertions, 59 deletions
diff --git a/src/client/views/pdf/AnchorMenu.tsx b/src/client/views/pdf/AnchorMenu.tsx
index 7cb6a20f4..a0c3cf487 100644
--- a/src/client/views/pdf/AnchorMenu.tsx
+++ b/src/client/views/pdf/AnchorMenu.tsx
@@ -76,7 +76,6 @@ export class AnchorMenu extends AntimodeMenu<AntimodeMenuProps> {
* @param e pointer down event
*/
gptSummarize = async (e: React.PointerEvent) => {
- // move this logic to gptpopup, need to implement generate again
GPTPopup.Instance.setVisible(true);
GPTPopup.Instance.setMode(GPTPopupMode.SUMMARY);
GPTPopup.Instance.setLoading(true);
@@ -90,24 +89,28 @@ export class AnchorMenu extends AntimodeMenu<AntimodeMenuProps> {
GPTPopup.Instance.setLoading(false);
};
+ /**
+ * Invokes the API with the selected text and stores it in the selected text.
+ * @param e pointer down event
+ */
gptFlashcards = async (e: React.PointerEvent) => {
- // move this logic to gptpopup, need to implement generate again
- // GPTPopup.Instance.setVisible(true);
- // GPTPopup.Instance.setMode(GPTPopupMode.FLASHCARD);
- // GPTPopup.Instance.setLoading(true);
-
+ const queryText = this.selectedText;
try {
- const res = await gptAPICall(this.selectedText, GPTCallType.FLASHCARD);
-
+ const res = await gptAPICall(queryText, GPTCallType.FLASHCARD);
+ console.log(res);
GPTPopup.Instance.setText(res || 'Something went wrong.');
- this.transferToFlashcard(res);
+ this.transferToFlashcard(res || 'Something went wrong');
} catch (err) {
console.error(err);
}
GPTPopup.Instance.setLoading(false);
};
+ /*
+ * Transfers the flashcard text generated by GPT on flashcards and creates a collection out them.
+ */
transferToFlashcard = (text: string) => {
+ // put each question generated by GPT on the front of the flashcard
const senArr = text.split('Question');
const collectionArr: Doc[] = [];
for (var i = 1; i < senArr.length; i++) {
@@ -116,10 +119,11 @@ export class AnchorMenu extends AntimodeMenu<AntimodeMenuProps> {
newDoc.text = senArr[i];
collectionArr.push(newDoc);
}
+ // create a new carousel collection of these flashcards
const newCol = Docs.Create.CarouselDocument(collectionArr, {
- _width: 200,
+ _width: 250,
_height: 200,
- _layout_fitWidth: true,
+ _layout_fitWidth: false,
_layout_autoHeight: true,
});
@@ -215,6 +219,7 @@ export class AnchorMenu extends AntimodeMenu<AntimodeMenuProps> {
color={SettingsManager.userColor}
/>
)}
+ {/* Adds a create flashcards option to the anchor menu, which calls the gptFlashcard method. */}
<IconButton
tooltip="Create flashcards" //
onPointerDown={this.gptFlashcards}
diff --git a/src/client/views/pdf/GPTPopup/GPTPopup.tsx b/src/client/views/pdf/GPTPopup/GPTPopup.tsx
index 32c1721ec..0b741c85e 100644
--- a/src/client/views/pdf/GPTPopup/GPTPopup.tsx
+++ b/src/client/views/pdf/GPTPopup/GPTPopup.tsx
@@ -144,15 +144,6 @@ export class GPTPopup extends ObservableReactComponent<GPTPopupProps> {
_layout_autoHeight: true,
});
this.addDoc(newDoc, this.sidebarId);
- // const arr = [newDoc];
- // const newCol = Docs.Create.CarouselDocument(arr, {
- // _width: 200,
- // _height: 200,
- // _layout_fitWidth: true,
- // _layout_autoHeight: true,
- // });
- // this.addDoc(newDoc, this.sidebarId);
- // this.addDoc(newCol, this.sidebarId);
const anchor = AnchorMenu.Instance?.GetAnchor(undefined, false);
if (anchor) {
DocUtils.MakeLink(newDoc, anchor, {
@@ -161,25 +152,6 @@ export class GPTPopup extends ObservableReactComponent<GPTPopupProps> {
}
};
- // transferToFlashcard = () => {
- // const senArr = this.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.addDoc(newCol, this.sidebarId);
- // this.addToCollection?.(newCol);
- // };
-
/**
* Transfers the image urls to actual image docs
*/
@@ -244,23 +216,6 @@ export class GPTPopup extends ObservableReactComponent<GPTPopupProps> {
);
};
- flashcardBox = () => {
- // const textArr = this.text.split(".");
- // textArr.forEach(function(sentence) {
- // console.log(sentence);
-
- // });
- // const newDoc = Docs.Create.ComparisonDocument();
- // this.addToCollection?.(newDoc);
- // // const newDoc = Docs.Create.ComparisonDocument();
- // DocUtils.copyDragFactory(Doc.UserDoc().emptyFlashcard as Doc);
- // // this.addToCollection?.(newDoc);
- // // return newDoc;
- // <ComparisonBox/>
- const newDoc = Docs.Create.TextDocument('Hello there');
- this.addDoc?.(newDoc);
- };
-
data = () => {
return (
<div style={{ display: 'flex', flexDirection: 'column', gap: '1rem' }}>
diff --git a/src/client/views/pdf/PDFViewer.tsx b/src/client/views/pdf/PDFViewer.tsx
index cecaf17ff..fe1ed8159 100644
--- a/src/client/views/pdf/PDFViewer.tsx
+++ b/src/client/views/pdf/PDFViewer.tsx
@@ -414,12 +414,10 @@ export class PDFViewer extends ObservableReactComponent<IViewerProps> {
AnchorMenu.Instance.jumpTo(e.clientX, e.clientY);
}
- // Changing which document to add the annotation to (the currently selected PDF)
GPTPopup.Instance.setSidebarId('data_sidebar');
GPTPopup.Instance.addDoc = this._props.sidebarAddDoc;
+ // allows for creating collection
AnchorMenu.Instance.addToCollection = this._props.DocumentView?.()._props.addDocument;
- // const newDoc = Docs.Create.ComparisonDocument({ _layout_isFlashcard: true, _width: 300, _height: 300 });
- // this.props.addDocument?.(newDoc);
};
@action