incyclist-services 1.7.103 → 1.7.104

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -48,6 +48,7 @@ const ActiveImportCard_1 = require("./cards/ActiveImportCard");
48
48
  const WorkoutCard_1 = require("./cards/WorkoutCard");
49
49
  const cards_1 = require("./cards");
50
50
  const db_1 = require("./loaders/db");
51
+ const api_2 = require("./loaders/api");
51
52
  const decorators_1 = require("../../base/decorators");
52
53
  const calendar_1 = require("../calendar");
53
54
  const ScheduledWorkoutCard_1 = require("./cards/ScheduledWorkoutCard");
@@ -84,6 +85,7 @@ let WorkoutListService = (() => {
84
85
  preloadObserver;
85
86
  items;
86
87
  db;
88
+ api;
87
89
  screenProps;
88
90
  language;
89
91
  selectedWorkout;
@@ -102,6 +104,7 @@ let WorkoutListService = (() => {
102
104
  this.language = 'en';
103
105
  this.myWorkouts.add(new cards_1.WorkoutImportCard());
104
106
  this.myWorkouts.add(new cards_1.WorkoutCreateCard());
107
+ this.api = new api_2.WorkoutsApiLoader();
105
108
  this.registerUserChangeHandler();
106
109
  this.onUpdate = this.onScheduledWorkoutsUpdated.bind(this);
107
110
  this.getWorkoutCalendar().on('updated', this.onUpdate);
@@ -504,6 +507,11 @@ let WorkoutListService = (() => {
504
507
  });
505
508
  }
506
509
  async loadWorkouts() {
510
+ await this.loadWorkoutsFromRepo();
511
+ await this.loadWorkoutsFromApi();
512
+ this.logEvent({ message: 'loadWorkoutsFromApi done' });
513
+ }
514
+ async loadWorkoutsFromRepo() {
507
515
  return new Promise((done, reject) => {
508
516
  try {
509
517
  const observer = this.getRepo().load();
@@ -519,6 +527,17 @@ let WorkoutListService = (() => {
519
527
  }
520
528
  });
521
529
  }
530
+ async loadWorkoutsFromApi() {
531
+ return new Promise((done) => {
532
+ this.logEvent({ message: 'loadWorkoutsFromApi start' });
533
+ const observer = this.api.load();
534
+ const add = this.addItem.bind(this);
535
+ const update = this.updateItem.bind(this);
536
+ observer.on('workout.added', add);
537
+ observer.on('workout.updated', update);
538
+ observer.on('done', done);
539
+ });
540
+ }
522
541
  addItem(item) {
523
542
  const list = this.selectList(item);
524
543
  let card;
@@ -45,6 +45,7 @@ import { ActiveImportCard } from "./cards/ActiveImportCard";
45
45
  import { WorkoutCard } from "./cards/WorkoutCard";
46
46
  import { WorkoutImportCard, WorkoutCreateCard } from './cards';
47
47
  import { WorkoutsDbLoader } from "./loaders/db";
48
+ import { WorkoutsApiLoader } from "./loaders/api";
48
49
  import { Injectable } from "../../base/decorators";
49
50
  import { useWorkoutCalendar } from "../calendar";
50
51
  import { ScheduledWorkoutCard } from "./cards/ScheduledWorkoutCard";
@@ -81,6 +82,7 @@ let WorkoutListService = (() => {
81
82
  preloadObserver;
82
83
  items;
83
84
  db;
85
+ api;
84
86
  screenProps;
85
87
  language;
86
88
  selectedWorkout;
@@ -99,6 +101,7 @@ let WorkoutListService = (() => {
99
101
  this.language = 'en';
100
102
  this.myWorkouts.add(new WorkoutImportCard());
101
103
  this.myWorkouts.add(new WorkoutCreateCard());
104
+ this.api = new WorkoutsApiLoader();
102
105
  this.registerUserChangeHandler();
103
106
  this.onUpdate = this.onScheduledWorkoutsUpdated.bind(this);
104
107
  this.getWorkoutCalendar().on('updated', this.onUpdate);
@@ -501,6 +504,11 @@ let WorkoutListService = (() => {
501
504
  });
502
505
  }
503
506
  async loadWorkouts() {
507
+ await this.loadWorkoutsFromRepo();
508
+ await this.loadWorkoutsFromApi();
509
+ this.logEvent({ message: 'loadWorkoutsFromApi done' });
510
+ }
511
+ async loadWorkoutsFromRepo() {
504
512
  return new Promise((done, reject) => {
505
513
  try {
506
514
  const observer = this.getRepo().load();
@@ -516,6 +524,17 @@ let WorkoutListService = (() => {
516
524
  }
517
525
  });
518
526
  }
527
+ async loadWorkoutsFromApi() {
528
+ return new Promise((done) => {
529
+ this.logEvent({ message: 'loadWorkoutsFromApi start' });
530
+ const observer = this.api.load();
531
+ const add = this.addItem.bind(this);
532
+ const update = this.updateItem.bind(this);
533
+ observer.on('workout.added', add);
534
+ observer.on('workout.updated', update);
535
+ observer.on('done', done);
536
+ });
537
+ }
519
538
  addItem(item) {
520
539
  const list = this.selectList(item);
521
540
  let card;
@@ -8,6 +8,7 @@ import { ActiveImportCard } from "./cards/ActiveImportCard";
8
8
  import { WorkoutCard } from "./cards/WorkoutCard";
9
9
  import { WorkoutSettings } from "./cards/types";
10
10
  import { WorkoutsDbLoader } from "./loaders/db";
11
+ import { WorkoutsApiLoader } from "./loaders/api";
11
12
  import { WP, WorkoutSettingsDisplayProps } from "./types";
12
13
  import { ScheduledWorkout, WorkoutCalendarEntry } from "../calendar";
13
14
  export declare class WorkoutListService extends IncyclistService implements IListService<WP> {
@@ -18,6 +19,7 @@ export declare class WorkoutListService extends IncyclistService implements ILis
18
19
  protected preloadObserver: PromiseObserver<void>;
19
20
  protected items: Array<WP>;
20
21
  protected db: WorkoutsDbLoader;
22
+ protected api: WorkoutsApiLoader;
21
23
  protected screenProps: any;
22
24
  protected language: string;
23
25
  protected selectedWorkout: Workout;
@@ -65,6 +67,8 @@ export declare class WorkoutListService extends IncyclistService implements ILis
65
67
  protected resetLists(): void;
66
68
  protected resetCards(): void;
67
69
  protected loadWorkouts(): Promise<void>;
70
+ protected loadWorkoutsFromRepo(): Promise<void>;
71
+ protected loadWorkoutsFromApi(): Promise<void>;
68
72
  protected addItem(item: WP): Card<WP>;
69
73
  protected updateItem(item: WP): Promise<void>;
70
74
  protected selectList(item: WP): CardList<WP>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.7.103",
3
+ "version": "1.7.104",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.27"
6
6
  },