From c378cd57b3ee3aa516cba817fe3e59345271d3f2 Mon Sep 17 00:00:00 2001 From: bobzel Date: Mon, 20 May 2024 14:25:08 -0400 Subject: carouselfview cleanup --- .../views/collections/CollectionCarouselView.tsx | 48 +++++++++++----------- 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/client/views/collections/CollectionCarouselView.tsx b/src/client/views/collections/CollectionCarouselView.tsx index 95425a217..c3ba04aa8 100644 --- a/src/client/views/collections/CollectionCarouselView.tsx +++ b/src/client/views/collections/CollectionCarouselView.tsx @@ -48,18 +48,18 @@ export class CollectionCarouselView extends CollectionSubView() { */ advance = (e: React.MouseEvent) => { e.stopPropagation(); - this.layoutDoc._carousel_index = (NumCast(this.layoutDoc._carousel_index) + 1) % this.childLayoutPairs.length; + this.layoutDoc._carousel_index = (NumCast(this.layoutDoc._carousel_index) + 1) % this.carouselItems.length; let startInd = this.layoutDoc._carousel_index; // if the star filter is selected if (this.layoutDoc.filterOp === 'star') { // go to a flashcard that is starred, skip the ones that aren't - while (!this.childLayoutPairs?.[NumCast(startInd)].layout[`${this.fieldKey}_star`] && (startInd + 1) % this.childLayoutPairs.length !== this.layoutDoc._carousel_index) { - startInd = (startInd + 1) % this.childLayoutPairs.length; + while (!this.carouselItems?.[NumCast(startInd)].layout[`${this.fieldKey}_star`] && (startInd + 1) % this.carouselItems.length !== this.layoutDoc._carousel_index) { + startInd = (startInd + 1) % this.carouselItems.length; } this.layoutDoc._carousel_index = startInd; // if there aren't any starred, show all cards - if (!this.childLayoutPairs?.[NumCast(startInd)].layout[`${this.fieldKey}_star`]) { + if (!this.carouselItems?.[NumCast(startInd)].layout[`${this.fieldKey}_star`]) { this.layoutDoc.filterOp = 'all'; } } @@ -67,18 +67,18 @@ export class CollectionCarouselView extends CollectionSubView() { // if the practice filter is selected if (this.layoutDoc.filterOp === 'practice') { // go to a new index that is missed, skip the ones that are correct - while (this.childLayoutPairs?.[NumCast(startInd)].layout[`${this.fieldKey}_missed`] === 'correct' && (startInd + 1) % this.childLayoutPairs.length !== this.layoutDoc._carousel_index) { - startInd = (startInd + 1) % this.childLayoutPairs.length; + while (this.carouselItems?.[NumCast(startInd)].layout[`${this.fieldKey}_missed`] === 'correct' && (startInd + 1) % this.carouselItems.length !== this.layoutDoc._carousel_index) { + startInd = (startInd + 1) % this.carouselItems.length; } this.layoutDoc._carousel_index = startInd; // if the user has gone through all of the cards and gotten them all correct, show all cards and exit practice mode - if (this.childLayoutPairs?.[NumCast(startInd)].layout[`${this.fieldKey}_missed`] === 'correct') { + if (this.carouselItems?.[NumCast(startInd)].layout[`${this.fieldKey}_missed`] === 'correct') { this.layoutDoc.filterOp = 'all'; // set all the cards to missed - for (let i = 0; i < this.childLayoutPairs.length; i++) { - const curDoc = this.childLayoutPairs?.[NumCast(i)]; + for (let i = 0; i < this.carouselItems.length; i++) { + const curDoc = this.carouselItems?.[NumCast(i)]; curDoc.layout[`${this.fieldKey}_missed`] = undefined; } } @@ -91,19 +91,19 @@ export class CollectionCarouselView extends CollectionSubView() { */ goback = (e: React.MouseEvent) => { e.stopPropagation(); - this.layoutDoc._carousel_index = (NumCast(this.layoutDoc._carousel_index) - 1 + this.childLayoutPairs.length) % this.childLayoutPairs.length; + this.layoutDoc._carousel_index = (NumCast(this.layoutDoc._carousel_index) - 1 + this.carouselItems.length) % this.carouselItems.length; let startInd = this.layoutDoc._carousel_index; // if the star filter is selected if (this.layoutDoc.filterOp === 'star') { // go to a new index that is starred, skip the ones that aren't - while (!this.childLayoutPairs?.[NumCast(startInd)].layout[`${this.fieldKey}_star`] && (startInd - 1 + this.childLayoutPairs.length) % this.childLayoutPairs.length !== this.layoutDoc._carousel_index) { - startInd = (startInd - 1 + this.childLayoutPairs.length) % this.childLayoutPairs.length; + while (!this.carouselItems?.[NumCast(startInd)].layout[`${this.fieldKey}_star`] && (startInd - 1 + this.carouselItems.length) % this.carouselItems.length !== this.layoutDoc._carousel_index) { + startInd = (startInd - 1 + this.carouselItems.length) % this.carouselItems.length; } this.layoutDoc._carousel_index = startInd; // if there aren't any starred, show all cards - if (!this.childLayoutPairs?.[NumCast(startInd)].layout[`${this.fieldKey}_star`]) { + if (!this.carouselItems?.[NumCast(startInd)].layout[`${this.fieldKey}_star`]) { this.layoutDoc.filterOp = 'all'; } } @@ -111,18 +111,18 @@ export class CollectionCarouselView extends CollectionSubView() { // if the practice filter is selected if (this.layoutDoc.filterOp === 'practice') { // go to a new index that is missed, skip the ones that are correct - while (this.childLayoutPairs?.[NumCast(startInd)].layout[`${this.fieldKey}_missed`] === 'correct' && (startInd - 1 + this.childLayoutPairs.length) % this.childLayoutPairs.length !== this.layoutDoc._carousel_index) { - startInd = (startInd - 1 + this.childLayoutPairs.length) % this.childLayoutPairs.length; + while (this.carouselItems?.[NumCast(startInd)].layout[`${this.fieldKey}_missed`] === 'correct' && (startInd - 1 + this.carouselItems.length) % this.carouselItems.length !== this.layoutDoc._carousel_index) { + startInd = (startInd - 1 + this.carouselItems.length) % this.carouselItems.length; } this.layoutDoc._carousel_index = startInd; // See all flashcards when finish going through practice mode and set all of the flashcards back to - if (this.childLayoutPairs?.[NumCast(startInd)].layout[`${this.fieldKey}_missed`] === 'correct') { + if (this.carouselItems?.[NumCast(startInd)].layout[`${this.fieldKey}_missed`] === 'correct') { this.layoutDoc.filterOp = 'all'; - for (let i = 0; i < this.childLayoutPairs.length; i++) { - const curDoc = this.childLayoutPairs?.[NumCast(i)]; + for (let i = 0; i < this.carouselItems.length; i++) { + const curDoc = this.carouselItems?.[NumCast(i)]; curDoc.layout[`${this.fieldKey}_missed`] = undefined; } } @@ -134,7 +134,7 @@ export class CollectionCarouselView extends CollectionSubView() { */ star = (e: React.MouseEvent) => { e.stopPropagation(); - const curDoc = this.childLayoutPairs?.[NumCast(this.layoutDoc._carousel_index)]; + const curDoc = this.carouselItems?.[NumCast(this.layoutDoc._carousel_index)]; if (!curDoc) return; if (curDoc.layout[`${this.fieldKey}_star`] === undefined) curDoc.layout[`${this.fieldKey}_star`] = true; else curDoc.layout[`${this.fieldKey}_star`] = !curDoc.layout[`${this.fieldKey}_star`]; @@ -145,7 +145,7 @@ export class CollectionCarouselView extends CollectionSubView() { */ missed = (e: React.MouseEvent, val: string) => { e.stopPropagation(); - const curDoc = this.childLayoutPairs?.[NumCast(this.layoutDoc._carousel_index)]; + const curDoc = this.carouselItems?.[NumCast(this.layoutDoc._carousel_index)]; curDoc.layout[`${this.fieldKey}_missed`] = val; this.advance(e); }; @@ -207,7 +207,7 @@ export class CollectionCarouselView extends CollectionSubView() { ); } @computed get buttons() { - if (!this.childLayoutPairs?.[NumCast(this.layoutDoc._carousel_index)]) return null; + if (!this.carouselItems?.[NumCast(this.layoutDoc._carousel_index)]) return null; return ( <>
@@ -217,7 +217,7 @@ export class CollectionCarouselView extends CollectionSubView() {
- +
this.missed(e, 'missed')} style={{ visibility: this.layoutDoc.filterOp === 'practice' ? 'visible' : 'hidden' }}> @@ -242,7 +242,7 @@ export class CollectionCarouselView extends CollectionSubView() { {/* Displays a message to the user to add more flashcards if they are in practice mode and no flashcards are there. */}

Recently missed!

-- cgit v1.2.3-70-g09d2