aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/pdf/AnchorMenu.tsx
diff options
context:
space:
mode:
authoralyssaf16 <alyssa_feinberg@brown.edu>2024-05-17 13:18:40 -0400
committeralyssaf16 <alyssa_feinberg@brown.edu>2024-05-17 13:18:40 -0400
commit5ff0bef5d3c4825aa7210a26c98aae3b24f4a835 (patch)
tree9c08c1631f8aa59d1ca1073b7064228061ff5a83 /src/client/views/pdf/AnchorMenu.tsx
parent3fb9eada221670022aa575c72fb89103638c3cbd (diff)
chatcards, quizcards, and ai flashcards
Diffstat (limited to 'src/client/views/pdf/AnchorMenu.tsx')
-rw-r--r--src/client/views/pdf/AnchorMenu.tsx27
1 files changed, 16 insertions, 11 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}