aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMelissa Zhang <mzhang19096@gmail.com>2020-05-23 23:57:10 -0700
committerMelissa Zhang <mzhang19096@gmail.com>2020-05-23 23:57:10 -0700
commitf398609a9819e5bb370063d5106b8484093393c9 (patch)
tree7f5d02b3858a58bc1c7a2e43c2cdca9f09eb472e /src
parent831de1c2853c427d2918e1cda6a296ae6d30c700 (diff)
reorganized & condensed render function
Diffstat (limited to 'src')
-rw-r--r--src/client/views/collections/CollectionCarousel3DView.tsx87
1 files changed, 37 insertions, 50 deletions
diff --git a/src/client/views/collections/CollectionCarousel3DView.tsx b/src/client/views/collections/CollectionCarousel3DView.tsx
index 0e704a1a0..f95645a6c 100644
--- a/src/client/views/collections/CollectionCarousel3DView.tsx
+++ b/src/client/views/collections/CollectionCarousel3DView.tsx
@@ -43,62 +43,49 @@ export class CollectionCarousel3DView extends CollectionSubView(Carousel3DDocume
sidePanelWidth = () => this.props.PanelWidth() * 0.25;
sidePanelHeight = () => this.props.PanelHeight() * 0.5;
@computed get content() {
- const index = NumCast(this.layoutDoc._itemIndex);
- const prevIndex = (index - 1 + this.childLayoutPairs.length) % this.childLayoutPairs.length;
- const nextIndex = (index + 1 + this.childLayoutPairs.length) % this.childLayoutPairs.length;
- return !(this.childLayoutPairs?.[index]?.layout instanceof Doc) ? (null) :
+ const centerIndex = NumCast(this.layoutDoc._itemIndex);
+ const prevIndex = (centerIndex - 1 + this.childLayoutPairs.length) % this.childLayoutPairs.length;
+ const nextIndex = (centerIndex + 1 + this.childLayoutPairs.length) % this.childLayoutPairs.length;
+
+ const displayDoc = (index: number, onClickAction: ScriptField | undefined, width: () => number, height: () => number) => {
+ return <ContentFittingDocumentView {...this.props}
+ onDoubleClick={ScriptCast(this.layoutDoc.onChildDoubleClick)}
+ onClick={onClickAction}
+ renderDepth={this.props.renderDepth + 1}
+ LayoutTemplate={this.props.ChildLayoutTemplate}
+ LayoutTemplateString={this.props.ChildLayoutString}
+ Document={this.childLayoutPairs[index].layout}
+ DataDoc={this.childLayoutPairs[index].data}
+ PanelWidth={width}
+ PanelHeight={height}
+ ScreenToLocalTransform={this.props.ScreenToLocalTransform}
+ bringToFront={returnFalse}
+ parentActive={this.props.active}
+ />;
+ };
+
+ const showCaptionScript = ScriptField.MakeScript(
+ "child._showCaption = 'caption'",
+ { child: Doc.name },
+ { child: this.childLayoutPairs[centerIndex].layout }
+ );
+
+ const changeIndexScript = ScriptField.MakeScript(
+ "collectionLayoutDoc._itemIndex = collectionLayoutDoc[fieldKey].indexOf(self)",
+ { fieldKey: String.name, collectionLayoutDoc: Doc.name },
+ { fieldKey: this.props.fieldKey, collectionLayoutDoc: this.layoutDoc }
+ );
+
+ return !(this.childLayoutPairs?.[centerIndex]?.layout instanceof Doc) ? (null) :
<>
<div className="collectionCarouselView-center">
- <ContentFittingDocumentView {...this.props}
- onDoubleClick={ScriptCast(this.layoutDoc.onChildDoubleClick)}
- onClick={ScriptField.MakeScript(
- "child._showCaption = 'caption'",
- { child: Doc.name },
- { child: this.childLayoutPairs[index].layout }
- )}
- renderDepth={this.props.renderDepth + 1}
- LayoutTemplate={this.props.ChildLayoutTemplate}
- LayoutTemplateString={this.props.ChildLayoutString}
- Document={this.childLayoutPairs[index].layout}
- DataDoc={this.childLayoutPairs[index].data}
- PanelWidth={this.mainPanelWidth}
- PanelHeight={this.mainPanelHeight}
- ScreenToLocalTransform={this.props.ScreenToLocalTransform}
- bringToFront={returnFalse}
- parentActive={this.props.active}
- />
+ {displayDoc(centerIndex, showCaptionScript, this.mainPanelWidth, this.mainPanelHeight)}
</div>
<div className="collectionCarouselView-prev">
- <ContentFittingDocumentView {...this.props}
- onDoubleClick={ScriptCast(this.layoutDoc.onChildDoubleClick)}
- onClick={this.changeIndexScript}
- renderDepth={this.props.renderDepth + 1}
- LayoutTemplate={this.props.ChildLayoutTemplate}
- LayoutTemplateString={this.props.ChildLayoutString}
- Document={this.childLayoutPairs[prevIndex].layout}
- DataDoc={this.childLayoutPairs[prevIndex].data}
- PanelWidth={this.sidePanelWidth}
- PanelHeight={this.sidePanelHeight}
- ScreenToLocalTransform={this.props.ScreenToLocalTransform}
- bringToFront={returnFalse}
- parentActive={this.props.active}
- />
+ {displayDoc(prevIndex, changeIndexScript, this.sidePanelWidth, this.sidePanelHeight)}
</div>
<div className="collectionCarouselView-next">
- <ContentFittingDocumentView {...this.props}
- onDoubleClick={ScriptCast(this.layoutDoc.onChildDoubleClick)}
- onClick={this.changeIndexScript}
- renderDepth={this.props.renderDepth + 1}
- LayoutTemplate={this.props.ChildLayoutTemplate}
- LayoutTemplateString={this.props.ChildLayoutString}
- Document={this.childLayoutPairs[nextIndex].layout}
- DataDoc={this.childLayoutPairs[nextIndex].data}
- PanelWidth={this.sidePanelWidth}
- PanelHeight={this.sidePanelHeight}
- ScreenToLocalTransform={this.props.ScreenToLocalTransform}
- bringToFront={returnFalse}
- parentActive={this.props.active}
- />
+ {displayDoc(nextIndex, changeIndexScript, this.sidePanelWidth, this.sidePanelHeight)}
</div>
</>;
}