aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2025-06-11 13:01:44 -0400
committerbobzel <zzzman@gmail.com>2025-06-11 13:01:44 -0400
commit05845fa3e5a6d71a58845d058a15233ccf6d72c0 (patch)
treeb7ee99e171a2595d6656f15e2cfdcd596ccf4cc3 /src/client/views/collections
parentb4db1e2467337468139d0e92ef94799c4143a0fc (diff)
refactor unwrapPlaceholder duplicated code to DocUtils.
Diffstat (limited to 'src/client/views/collections')
-rw-r--r--src/client/views/collections/collectionFreeForm/ImageLabelBox.tsx7
-rw-r--r--src/client/views/collections/collectionFreeForm/MarqueeView.tsx19
2 files changed, 8 insertions, 18 deletions
diff --git a/src/client/views/collections/collectionFreeForm/ImageLabelBox.tsx b/src/client/views/collections/collectionFreeForm/ImageLabelBox.tsx
index 038b1c6f9..e3a3f9b05 100644
--- a/src/client/views/collections/collectionFreeForm/ImageLabelBox.tsx
+++ b/src/client/views/collections/collectionFreeForm/ImageLabelBox.tsx
@@ -158,10 +158,9 @@ export class ImageLabelBox extends ViewBoxBaseComponent<FieldViewProps>() {
this._currentLabel = e.target.value;
});
- classifyImagesInBox = async (selectedImages? : Doc[], prompt? : string) => {
+ classifyImagesInBox = async () => {
this.startLoading();
- alert('Classifying images...');
- selectedImages ??= this._selectedImages;
+ const selectedImages = this._selectedImages;
// Converts the images into a Base64 format, afterwhich the information is sent to GPT to label them.
@@ -170,7 +169,7 @@ export class ImageLabelBox extends ViewBoxBaseComponent<FieldViewProps>() {
const url = ImageCastWithSuffix(doc[Doc.LayoutDataKey(doc)], '_o') ?? '';
return imageUrlToBase64(url).then(hrefBase64 =>
!hrefBase64 ? undefined :
- gptImageLabel(hrefBase64, prompt ?? 'Give three labels to describe this image.').then(labels =>
+ gptImageLabel(hrefBase64, 'Give three labels to describe this image.').then(labels =>
({ doc, labels }))) ; // prettier-ignore
}
});
diff --git a/src/client/views/collections/collectionFreeForm/MarqueeView.tsx b/src/client/views/collections/collectionFreeForm/MarqueeView.tsx
index 7a456c46f..128606675 100644
--- a/src/client/views/collections/collectionFreeForm/MarqueeView.tsx
+++ b/src/client/views/collections/collectionFreeForm/MarqueeView.tsx
@@ -527,17 +527,11 @@ export class MarqueeView extends ObservableReactComponent<SubCollectionViewProps
MarqueeOptionsMenu.Instance.fadeOut(true);
});
- getAiPresetsDescriptors(): DocumentDescriptor[] {
- const selected = this.marqueeSelect(false);
- return selected.map(doc => ({
+ getAiPresetsDescriptors = (): DocumentDescriptor[] =>
+ this.marqueeSelect(false).map(doc => ({
type: typeof doc.$type === 'string' ? doc.$type : 'UNKNOWN',
- tags: (() => {
- const s = new Set<string>();
- StrListCast(doc.$tags_chat ?? new List<string>()).forEach(t => s.add(t));
- return Array.from(s);
- })(),
+ tags: Array.from(new Set(StrListCast(doc.$tags_chat))),
}));
- }
generateScrapbook = action(async () => {
const selectedDocs = this.marqueeSelect(false);
@@ -582,14 +576,12 @@ export class MarqueeView extends ObservableReactComponent<SubCollectionViewProps
});
// 3) Now grab that new scrapbook’s flat placeholders
- const flatPl = DocListCast(scrapbook[Doc.LayoutDataKey(scrapbook)]) as Doc[];
- const unwrap = (items: Doc[]): Doc[] => items.flatMap(d => (d.$type === DocumentType.COL ? unwrap(DocListCast(d[Doc.LayoutDataKey(d)])) : [d]));
- const allPlaceholders = unwrap(flatPl);
+ const allPlaceholders = DocUtils.unwrapPlaceholders(scrapbookPlaceholders);
// 4) Slot each selectedDocs[i] into the first matching placeholder
selectedDocs.forEach(realDoc => slotRealDocIntoPlaceholders(realDoc, allPlaceholders));
- const selected = this.marqueeSelect(false).map(d => {
+ const selected = selectedDocs.map(d => {
this._props.removeDocument?.(d);
d.x = NumCast(d.x) - this.Bounds.left;
d.y = NumCast(d.y) - this.Bounds.top;
@@ -597,7 +589,6 @@ export class MarqueeView extends ObservableReactComponent<SubCollectionViewProps
});
this._props.addDocument?.(scrapbook);
- selectedDocs.forEach(doc => this._props.removeDocument?.(doc));
const portal = Docs.Create.FreeformDocument(selected, { title: 'summarized documents', x: this.Bounds.left + 200, y: this.Bounds.top, isGroup: true, backgroundColor: 'transparent' });
DocUtils.MakeLink(scrapbook, portal, { link_relationship: 'summary of:summarized by' });