No slides will be displayed in Ionic 2 once the workout is completed

Here is the result of the JSONOBJ:https://i.sstatic.net/8vyQd.png

In my home.html file, I have ion-card containing a method called navigate(), which is structured as follows:

    navigate(event, exercise, exercise2, exercise3, exercise4){    
      this.navCtrl.push(exerciseSlides, {
                clickedExercise: exercise,
                secondExercise: exercise2,
                thirdExercise: exercise3,
                fourthExercise: exercise4
      });
  }

Below are two examples of the cards:

 <ion-card *ngIf="oefening1" (click)="navigate($event, oefening1, oefening2, oefening3, oefening4)" class="{{ oefening1 }}" margin-vertical>
    <img src="assets/img/{{ oefening1 }}.jpg"/>
    <div *ngIf="exercise1IsDone || allExercisesDone" (click)="$event.stopPropagation()" class="overlay">
      <ion-icon name="checkmark-circle" class="checkmark"></ion-icon>
    </div>

    <ion-card-content>
      <ion-card-title>{{ oefening1 }}</ion-card-title>
      <p>Sets: {{ set1 }}</p>
      <p>Repetitions: {{ rep1 }}</p>
    </ion-card-content>
  </ion-card>

  <ion-card *ngIf="oefening2" (click)="navigate($event, oefening2, oefening1, oefening3, oefening4)" class="{{ oefening2 }}" margin-vertical>
    <img src="assets/img/{{ oefening2 }}.jpg"/>    
    <div *ngIf="exercise2IsDone || allExercisesDone" (click)="$event.stopPropagation()" class="overlay">
      <ion-icon name="checkmark-circle" class="checkmark"></ion-icon>
    </div>
    <ion-card-content>
      <ion-card-title>{{ oefening2 }}</ion-card-title>
      <p>Sets: {{ set2 }}</p>
      <p>Repetitions: {{ rep2 }}</p>
    </ion-card-content>
  </ion-card>

The structure of my exerciseSlides.html page is as follows:

<ion-content>
  <ion-slides #exercisesSlider>
        <ion-slide *ngFor="let ex of allExercises; let i = index" id="{{ ex.exercise }}">
            <ion-grid>
                <ion-row>
                    <ion-col col-12>
                        <div (click)="playVid(ex.exercise)" padding-bottom>
                            <img [src]="ex.path" />
                        </div>
                        <div text-center>
                            <button *ngIf="i > 0" ion-button round (click)="previousExercise()">Previous</button>
                            <button *ngIf="i < 4" ion-button round (click)="nextExercise(i, ex.exercise, ex.done)">Complete</button>

                            {{ ex.done }}
                        </div>
                    </ion-col>
                </ion-row>
            </ion-grid>
        </ion-slide>
    </ion-slides>
</ion-content>

The content of my exerciseSlides.ts file looks like this:

export class exerciseSlides {
  @ViewChild('exercisesSlider') slides: Slides;
  public disabledBtn: boolean;
  public allExercises: any[] = [];
  public date: any = moment().format('L');

   constructor( public navCtrl: NavController, private streamingMedia: StreamingMedia, public params: NavParams, public modalCtrl: ModalController) {
       
       // The rest of the code for initializing exercises and paths

        this.disabledBtn = false;
    }

    // More methods included here...

}

How can I update the value of this.allExercises[i].done to true and implement an *ngIf condition to check if an exercise is done in order to hide completed slides?

The allExercises.done property always defaults to false due to the constructor setup. How can I ensure that once an exercise is marked as done, it remains true in the array, allowing the app to skip over completed slides and focus on pending ones?

Answer №1

Here are some steps you can take:

To start, update your database to include a done field for each exercise.

If you have a large number of exercises, consider selecting only 4 where done: false.

It's valuable to have offline data accessible to users at all times. For an app that primarily fetches videos, localForage/localStorage may not be necessary unless there is a feature allowing users to view completed exercises.

Avoid saving arrays as they can be cumbersome and challenging to manipulate. Utilize objects instead.

In the nextExercise function, follow these steps:

// Make sure to save the user's exercise progress in the database using the exercise ID for easier tracking.
// If the user reinstalls the app, their progress can be downloaded.
saveYourExerciseMethod().then(() =>{
    this.slides.lockSwipes(false);
    this.slides.slideNext();
    this.slides.lockSwipes(true);

    // Save the completion status of the current exercise using an object
     localForage.setItem(this.allExercises[i].exercise, { exercise: this.allExercises[i].exercise, done: true]);

    let modal = this.modalCtrl.create(ModalPage);
    modal.present();

    if(i == 3){
        this.navCtrl.push(HomePage);
        localForage.setItem('didAllExercises', {completed: true, date: this.date});
    }
});

Based on my understanding of your code and application, these suggestions should help. Unfortunately, I'm unable to provide more specific code without additional information.

I hope this guidance proves useful to you.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Add up values from a reducer using two distinct actions

I have implemented ngrx-store in my project and created a reducer that handles two different actions. Each action contains the number of task count as payload. Now, I want to sum up the numbers from both actions when they are emitted. When I dispatch thes ...

I'm having trouble getting my nav-tab to function properly in Bootstrap 4 when used with Angular 4. Can

I have been attempting to utilize Bootstrap 4 tabs with Angular 4 with the expectation that it would resemble and function similar to this example enter link description here However, my page is displaying like this. https://i.sstatic.net/dymNH.png Here ...

How can I dynamically reference two template HTML files (one for mobile and one for desktop) within a single component in Angular 6?

Here is the approach I have taken. Organizational structure mobile-view.component.html <p> This content is for mobile view </p> desktop-view.component.html <p> This content is for desktop view </p> mobile.component.ts import ...

Is there a way to ensure that in angular 2+, when clicking on a button with the same route as the current page, the page will reload?

Why would I even consider complaining about this? You’re already here, aren’t you? I have a couple of reasons why a reload needs to happen, but for now I’ll just mention one. 1) When my user clicks on a link, they may not realize it's the same ...

Configuring the CKEditor edit functionality in Angular 2

If you're looking to configure your CKEditor in Angular2, you can refer to the documentation provided by CKEditor here. Here is an example of how I am using it in my HTML: <ckeditor [(ngModel)]="ckeditorContent" [config]="{toolbar : 'Bas ...

In AngularJS, variables can undergo automatic value changes without any external connections

Within my AngularJS controllers, I have initialized two variables: _this.currentData=new Array(); _this.masterCurrentData=new Array(); Later on, I created a temporary array of objects called tmpDataSort and populated it separately using loops. var tmpDa ...

The term 'protractor' is not identified as a valid internal or external command, executable program, or batch file

I have successfully set up Protractor to run from a batch file with the command "protractor conf.js" and the script is functioning correctly. Protractor has been installed globally and all necessary environment settings have been configured. However, when ...

How exactly does the 'this' type in TypeScript determine its own type inferences?

When working with TypeScript, I wanted to use the this keyword to type certain properties of my class. However, I encountered a problem that I couldn't figure out how to solve. What I was trying to achieve is something like this: export class Animal{ ...

What are the steps to create observable data from asynchronous sources?

Recent adopter of observables. I am utilizing ssh2 to retrieve a directory listing from my server. However, I am struggling to convert the data into an observable format since most online examples involve using http instead of an external module. Any sugg ...

Guide on how to run functions in Angular 2+ directly from the console?

My application is designed to operate within a chromium browser using chromiumfx. With chromiumfx, you can seamlessly run any JavaScript functions as if you were working in a console environment. Here's a snippet of my code: import { Component } f ...

A guide on integrating the URI.js library into an Angular2+ application

I'm currently exploring ways to integrate a third-party library called urijs into my Angular 2+ application. Below, you can see the relevant files involved in this process. // package.json { ... "dependencies": { ... "urijs": "^1.18.10", ...

What is the best way to include documentation for custom components using jsDoc?

Within my Vuejs inline template components, we typically register the component in a javascript file and define its template in html. An example of such a component is shown below: Vue.component('compare-benefits', { data() { // By return ...

Dynamic Angular Menu

Is there a cleaner, more dynamic way to implement a mat menu with individual click values and disable properties for each button? I want to avoid repeating code like in the example below. Looking for a more dynamic solution. #code <mat-menu #createDeal ...

Utilize ASP.NET Boilerplate Core and Angular on Microsoft Azure for seamless deployment

I am looking to deploy ASP.NET Boilerplate Core & Angular on Microsoft Azure. The current version of ASP.NET Boilerplate consists of two solutions (one for the backend and one for the frontend), so I need to deploy them on two separate AppServices along wi ...

Using TypeScript: Functions incorporating properties

Recently, I made an interesting discovery in JavaScript: function foo() { console.log("FOO"); } foo.bar = "FOOBAR"; foo(); // logs "FOO" console.log(foo.bar); // "FOOBAR" This got me thinking: How would I repres ...

What is the best way to ensure TypeScript recognizes a variable as a specific type throughout the code?

Due to compatibility issues with Internet Explorer, I find myself needing to create a custom Error that must be validated using the constructor. customError instanceof CustomError; // false customError.constructor === CustomError; // true But how can I m ...

Different Ways to Modify Data with the Change Event in Angular 8

How can I dynamically change data using the (change) event? I'm attempting to alter the gallery items based on a matching value. By default, I want to display all gallery items. public items = [{ value: 'All', name: 'All Item ...

Generate a configuration file that allows for the reading and storage of modifications

Is there a way to create a configuration file (JSON) on the local file system using JavaScript where I can write and modify data without losing it when the application is restarted? Any suggestions or solutions for this problem? Thank you for your assista ...

Asynchronous function in TypeScript is restricting the return type to only one promise type

Using node version 14.7.0, npm version 6.14.7, and typescript version 3.7.3. I have a function that interacts with a postgres database and retrieves either the first row it finds or all results based on a parameter. It looks something like this: async fet ...

Reactive form within a form

I am working on an angular application that involves a nested reactive form. I would appreciate it if you could review my method of nesting the form by passing the parent form reference in the child component and let me know if this approach is appropria ...