diff options
-rw-r--r-- | src/client/views/collections/CollectionCarouselView.tsx | 114 |
1 files changed, 24 insertions, 90 deletions
diff --git a/src/client/views/collections/CollectionCarouselView.tsx b/src/client/views/collections/CollectionCarouselView.tsx index 979f7ea2a..9cf7765dd 100644 --- a/src/client/views/collections/CollectionCarouselView.tsx +++ b/src/client/views/collections/CollectionCarouselView.tsx @@ -91,68 +91,27 @@ export class CollectionCarouselView extends CollectionSubView() { return match(this.carouselItems?.[NumCast(this.layoutDoc._carousel_index)].layout); }; - if (this.layoutDoc.practiceMode === practiceMode.PRACTICE && this.layoutDoc.filterOp !== cardMode.STAR) { - if (!moveToCardWithField((doc: Doc) => doc[this.practiceField] !== practiceVal.CORRECT)) { - //this.layoutDoc.filterOp = undefined; // if all of the cards are correct, show all cards and exit practice mode - this._practiceMessage = 'Finished! Return to All - BUTTONS??.'; - this.carouselItems.forEach(item => { - // reset all the practice values - item.layout[this.practiceField] = undefined; - }); - // this.layoutDoc._carousel_index = -1; - } - } else if (this.layoutDoc.practiceMode !== practiceMode.PRACTICE && this.layoutDoc.filterOp === cardMode.STAR) { - if (!moveToCardWithField((doc: Doc) => !!doc[this.starField])) { - //this.layoutDoc.filterOp = undefined; // if there aren't any starred, show all cards - this._filterMessage = 'No starred items. Unselect this view to see all flashcards and star them.'; - } - } else if (this.layoutDoc.practiceMode === practiceMode.PRACTICE && this.layoutDoc.filterOp === cardMode.STAR) { - if (!moveToCardWithField((doc: Doc) => doc[this.practiceField] !== practiceVal.CORRECT && doc[this.starField] === true)) { - this._practiceMessage = 'New message.'; - } - } else { - moveToCardWithField(returnTrue); + switch (this.layoutDoc.practiceMode && this.layoutDoc.filterOp) { + case practiceMode.PRACTICE && cardMode.ALL: + if (!moveToCardWithField((doc: Doc) => doc[this.practiceField] !== practiceVal.CORRECT)) { + this._practiceMessage = 'Finished! Unselect practice mode to view all flashcards.'; + this.carouselItems.forEach(item => { item.layout[this.practiceField] = undefined}); //prettier-ignore + } + break; + case !practiceMode.PRACTICE && cardMode.STAR: + if (!moveToCardWithField((doc: Doc) => !!doc[this.starField])) { + this._filterMessage = 'No starred items. Unselect this view to see all flashcards and star them.'; + } + break; + case practiceMode.PRACTICE && cardMode.STAR: + if (!moveToCardWithField((doc: Doc) => doc[this.practiceField] !== practiceVal.CORRECT && doc[this.starField] === true)) { + this._filterMessage = 'No flashcards to show! Unselect star mode to view all flashcards.'; + this._practiceMessage = 'Unselect practice mode to view all flashcards.'; + } + break; + default: + moveToCardWithField(returnTrue); } - - // if (this.layoutDoc.practiceMode === practiceMode.PRACTICE && this.layoutDoc.filterOp === cardMode.STAR) { - // if (!moveToCardWithField((doc: Doc) => doc[this.practiceField] !== practiceVal.CORRECT) && !moveToCardWithField((doc: Doc) => doc[this.starField] === true)) { - // this._practiceMessage = 'New message.'; - // } else moveToCardWithField(returnTrue); - // return; - // } - // switch (StrCast(this.layoutDoc.practiceMode)) { - // // case practiceMode.QUIZ: // go to a flashcard that is starred, skip the ones that aren't - // // if (!moveToCardWithField((doc: Doc) => !!doc[this.starField])) { - // // // this.layoutDoc._carousel_index - // // //this.layoutDoc.filterOp = undefined; // if there aren't any starred, show all cards - // // this._message = 'No starred items. Unselect this view to see all flashcards and star them.' - // // } - // // break; - // case practiceMode.PRACTICE: // go to a new index that is missed, skip the ones that are correct - // if (!moveToCardWithField((doc: Doc) => doc[this.practiceField] !== practiceVal.CORRECT)) { - // //this.layoutDoc.filterOp = undefined; // if all of the cards are correct, show all cards and exit practice mode - // this._practiceMessage = 'Finished! Return to All - BUTTONS??.' - // this.carouselItems.forEach(item => { // reset all the practice values - // item.layout[this.practiceField] = undefined; - // }); - // // this.layoutDoc._carousel_index = -1; - // } - // break; - // default: moveToCardWithField(returnTrue); - - // } // prettier-ignore - - // switch (StrCast(this.layoutDoc.filterOp)) { - // case cardMode.STAR: // go to a flashcard that is starred, skip the ones that aren't - // if (!moveToCardWithField((doc: Doc) => !!doc[this.starField])) { - // //this.layoutDoc.filterOp = undefined; // if there aren't any starred, show all cards - // this._filterMessage = 'No starred items. Unselect this view to see all flashcards and star them.'; - // } - // break; - // default: - // break; - // // if (this.layoutDoc.practiceMode === practiceMode.PRACTICE) moveToCardWithField(returnTrue); - // } }; /** @@ -200,6 +159,7 @@ export class CollectionCarouselView extends CollectionSubView() { onContentDoubleClick = () => ScriptCast(this.layoutDoc.onChildDoubleClick); onContentClick = () => ScriptCast(this.layoutDoc.onChildClick); captionWidth = () => this._props.PanelWidth() - 2 * this.marginX; + setPracticeMode = (mode: practiceMode) => { this.layoutDoc.practiceMode = mode; this.carouselItems?.map(doc => (doc.layout[this.practiceField] = undefined)); @@ -210,44 +170,19 @@ export class CollectionCarouselView extends CollectionSubView() { case practiceMode.NORMAL: this.setPracticeMessage(undefined); break; - default: - break; } }; + setFilterMode = (mode: cardMode) => { this.layoutDoc.filterOp = mode; switch (mode) { case cardMode.STAR: this.move(1); break; - default: - this.setFilterMessage(undefined); + default: this.setFilterMessage(undefined); // prettier-ignore } - - // if (mode === practiceMode.QUIZ) { - // this.carouselItems?.map(doc => (doc.layout[this.sideField] = undefined)); - // this.layoutDoc.practiceMode = mode; - // } - // if (mode === practiceMode.PRACTICE) this.layoutDoc.practiceMode = mode; - // if (mode === practiceMode.NORMAL) { - // this.layoutDoc.practiceMode = mode; - // if (this.layoutDoc.filterOp === cardMode.STAR) this.setMessage('No starred items. Unselect this filter to star cards.'); - // } - // this.carouselItems?.map(doc => (doc.layout[this.practiceField] = undefined)); }; - // specificMenu = (): void => { - // const cm = ContextMenu.Instance; - - // const revealOptions = cm.findByDescription('Filter Flashcards'); - // const revealItems: ContextMenuProps[] = revealOptions && 'subitems' in revealOptions ? revealOptions.subitems : []; - // revealItems.push({description: 'All', event: () => {this.setFilterMode(cardMode.ALL);}, icon: 'layer-group',}); // prettier-ignore - // revealItems.push({description: 'Star', event: () => {this.setFilterMode(cardMode.STAR);}, icon: 'star',}); // prettier-ignore - // revealItems.push({description: 'Practice Mode', event: () => {this.setFilterMode(cardMode.PRACTICE);}, icon: 'check',}); // prettier-ignore - // cm.addItem({description: 'Quiz Cards', event: () => {this.setFilterMode(cardMode.QUIZ);}, icon: 'pencil',}); // prettier-ignore - // !revealOptions && cm.addItem({ description: 'Filter Flashcards', addDivider: false, noexpand: true, subitems: revealItems, icon: 'layer-group' }); - // //cm.addItem({description: 'Quiz Cards', event: () => {this.layoutDoc.filterOp = cardMode.QUIZ; this.clearContent()}); - // }; @computed get content() { const index = NumCast(this.layoutDoc._carousel_index); const curDoc = this.carouselItems?.[index]; @@ -353,7 +288,6 @@ export class CollectionCarouselView extends CollectionSubView() { <div className="collectionCarouselView-outer" ref={this.createDashEventsTarget} - // onContextMenu={this.specificMenu} style={{ background: this._props.styleProvider?.(this.layoutDoc, this._props, StyleProp.BackgroundColor), color: this._props.styleProvider?.(this.layoutDoc, this._props, StyleProp.Color), @@ -367,9 +301,9 @@ export class CollectionCarouselView extends CollectionSubView() { {this._practiceMessage} </p> )} - {/* {(this.carouselItems?.filter(doc => doc.layout[this.practiceField] !== practiceVal.CORRECT)).length == 0 ? null : this.content} */} {!this.carouselItems?.[NumCast(this.layoutDoc._carousel_index)] && this.layoutDoc.practiceMode === practiceMode.PRACTICE ? <p className="message">Add flashcards </p> : null} <p + className="missed-message" style={{ color: 'red', fontWeight: 'bold', |