incyclist-services 1.9.28 → 1.9.29

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.
@@ -34,14 +34,17 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
34
34
  done = true;
35
35
  };
36
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.WorkoutListPageService = void 0;
37
+ exports.WorkoutListPageService = exports.IMPORT_FILE_EXTENSIONS = void 0;
38
38
  const pages_1 = require("../../../base/pages");
39
39
  const decorators_1 = require("../../../base/decorators");
40
+ const observer_1 = require("../../../base/types/observer");
40
41
  const settings_1 = require("../../../settings");
41
42
  const calendar_1 = require("../../calendar");
42
43
  const service_1 = require("../../list/service");
43
44
  const devices_1 = require("../../../devices");
44
45
  const routes_1 = require("../../../routes");
46
+ const DEFAULT_IMPORT_GROUP = 'My Workouts';
47
+ exports.IMPORT_FILE_EXTENSIONS = ['zwo', 'json'];
45
48
  let WorkoutListPageService = (() => {
46
49
  let _classSuper = pages_1.IncyclistPageService;
47
50
  let _instanceExtraInitializers = [];
@@ -66,6 +69,11 @@ let WorkoutListPageService = (() => {
66
69
  if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
67
70
  }
68
71
  detailWorkoutId = (__runInitializers(this, _instanceExtraInitializers), null);
72
+ importPhase;
73
+ importingFileName;
74
+ importResult;
75
+ importError;
76
+ importGeneration = 0;
69
77
  listObserver;
70
78
  listUpdateHandler = this.emitPageUpdate.bind(this);
71
79
  calendarUpdateHandler = this.emitPageUpdate.bind(this);
@@ -215,6 +223,103 @@ let WorkoutListPageService = (() => {
215
223
  return false;
216
224
  }
217
225
  }
226
+ getImportDisplayProps() {
227
+ try {
228
+ const phase = this.importPhase ?? 'landing';
229
+ const knownGroups = this.getKnownGroups();
230
+ const props = { phase, knownGroups };
231
+ if (phase === 'importing')
232
+ props.importing = { fileName: this.importingFileName };
233
+ if (phase === 'result')
234
+ props.result = this.importResult;
235
+ if (phase === 'error')
236
+ props.error = this.importError;
237
+ return props;
238
+ }
239
+ catch (err) {
240
+ this.logError(err, 'getImportDisplayProps');
241
+ return { phase: 'landing', knownGroups: [] };
242
+ }
243
+ }
244
+ onImportOpen() {
245
+ try {
246
+ this.importPhase = 'landing';
247
+ delete this.importError;
248
+ delete this.importResult;
249
+ this.emitImportUpdate();
250
+ }
251
+ catch (err) {
252
+ this.logError(err, 'onImportOpen');
253
+ }
254
+ }
255
+ onImportFile(file) {
256
+ const observer = new observer_1.Observer();
257
+ const generation = this.importGeneration = Date.now();
258
+ try {
259
+ this.importPhase = 'importing';
260
+ this.importingFileName = file?.name;
261
+ this.emitImportUpdate();
262
+ this.logEvent({ message: 'workout import attempted', file: file?.name });
263
+ this.getWorkoutList().import(file, { showImportCards: false })
264
+ .then(([card]) => {
265
+ const group = this.getLastUsedImportGroup();
266
+ observer.emit('success');
267
+ this.logEvent({ message: 'workout import succeeded', file: file?.name, workoutName: card.getTitle(), group });
268
+ if (generation !== this.importGeneration)
269
+ return;
270
+ if (group !== DEFAULT_IMPORT_GROUP)
271
+ card.move(group);
272
+ this.importPhase = 'result';
273
+ this.importResult = {
274
+ id: card.getId(),
275
+ workoutName: card.getTitle(),
276
+ group,
277
+ workout: card.getData?.(),
278
+ ftp: card.openSettings?.()?.settings?.ftp
279
+ };
280
+ this.emitImportUpdate();
281
+ })
282
+ .catch((err) => {
283
+ observer.emit('error', err);
284
+ this.logEvent({ message: 'workout import failed', file: file?.name, error: err?.message });
285
+ if (generation !== this.importGeneration)
286
+ return;
287
+ this.importPhase = 'error';
288
+ this.importError = err?.message;
289
+ this.emitImportUpdate();
290
+ });
291
+ }
292
+ catch (err) {
293
+ this.logError(err, 'onImportFile');
294
+ }
295
+ return observer;
296
+ }
297
+ onImportSetGroup(id, group) {
298
+ try {
299
+ const card = this.findWorkoutCard(id);
300
+ card?.move(group);
301
+ this.persistLastUsedImportGroup(group);
302
+ if (this.importResult)
303
+ this.importResult = { ...this.importResult, group };
304
+ this.emitImportUpdate();
305
+ }
306
+ catch (err) {
307
+ this.logError(err, 'onImportSetGroup');
308
+ }
309
+ }
310
+ onImportClose() {
311
+ try {
312
+ this.importGeneration = Date.now();
313
+ delete this.importPhase;
314
+ delete this.importingFileName;
315
+ delete this.importResult;
316
+ delete this.importError;
317
+ this.emitImportUpdate();
318
+ }
319
+ catch (err) {
320
+ this.logError(err, 'onImportClose');
321
+ }
322
+ }
218
323
  onStart(id, opts) {
219
324
  try {
220
325
  const card = this.findWorkoutCard(id, { includeScheduled: true });
@@ -283,6 +388,29 @@ let WorkoutListPageService = (() => {
283
388
  }
284
389
  return undefined;
285
390
  }
391
+ getKnownGroups() {
392
+ const lists = this.getWorkoutList().getLists(false) ?? [];
393
+ return lists.filter(l => l.getId() !== 'scheduled').map(l => l.getTitle());
394
+ }
395
+ getLastUsedImportGroup() {
396
+ return this.getUserSettings().get('preferences.workouts.lastImportGroup', DEFAULT_IMPORT_GROUP);
397
+ }
398
+ persistLastUsedImportGroup(group) {
399
+ try {
400
+ this.getUserSettings().set('preferences.workouts.lastImportGroup', group);
401
+ }
402
+ catch (err) {
403
+ this.logError(err, 'persistLastUsedImportGroup');
404
+ }
405
+ }
406
+ emitImportUpdate() {
407
+ try {
408
+ this.getPageObserver()?.emit('import-update');
409
+ }
410
+ catch (err) {
411
+ this.logError(err, 'emitImportUpdate');
412
+ }
413
+ }
286
414
  getScheduledTodayWorkoutId() {
287
415
  try {
288
416
  const today = this.getWorkoutCalendar().getScheduledToday();
@@ -44,6 +44,9 @@ const SURFACE = 'workout-details';
44
44
  const DISPLAY_TYPE_KEY = 'preferences.workoutListDisplayType';
45
45
  const DEFAULT_DISPLAY_TYPE = 'tiles';
46
46
  const SCHEDULED_ID = 'scheduled';
47
+ const HIDDEN_CARD_TYPES = new Set(['WorkoutImport', 'ActiveWorkoutImport']);
48
+ const MSG_MULTIPLE_FILES = 'Only one workout file at a time';
49
+ const MSG_UNSUPPORTED_TYPE = 'Unsupported file type - please choose a ZWO or JSON file';
47
50
  let DesktopWorkoutListPageService = (() => {
48
51
  let _classDecorators = [types_1.Singleton];
49
52
  let _classDescriptor;
@@ -147,7 +150,7 @@ let DesktopWorkoutListPageService = (() => {
147
150
  return null;
148
151
  }
149
152
  }
150
- onCardOK(id, settings) {
153
+ onCardOK(id) {
151
154
  try {
152
155
  const card = this.findSnapshotCard(id);
153
156
  if (!card) {
@@ -155,9 +158,6 @@ let DesktopWorkoutListPageService = (() => {
155
158
  return;
156
159
  }
157
160
  switch (card.getCardType()) {
158
- case 'WorkoutImport':
159
- this.importFiles(settings);
160
- break;
161
161
  case 'WorkoutCreate':
162
162
  this.onCreateCardOK(card);
163
163
  break;
@@ -191,9 +191,6 @@ let DesktopWorkoutListPageService = (() => {
191
191
  }
192
192
  async onDelete(id) {
193
193
  try {
194
- const card = this.findSnapshotCard(id);
195
- if (card?.getCardType() === 'ActiveWorkoutImport')
196
- return await this.deleteImportCard(card);
197
194
  const surface = this.detailWorkoutId === id ? 'details' : 'card';
198
195
  const success = await super.onDelete(id);
199
196
  this.logEvent({ message: 'workout deleted', workoutId: id, success, surface });
@@ -204,17 +201,32 @@ let DesktopWorkoutListPageService = (() => {
204
201
  return false;
205
202
  }
206
203
  }
207
- onRetry(id) {
204
+ onImportFiles(files, source) {
208
205
  try {
209
- const card = this.findSnapshotCard(id);
210
- if (card?.getCardType() !== 'ActiveWorkoutImport') {
211
- this.logError(new Error(`import card not found: ${id}`), 'onRetry');
206
+ const list = Array.isArray(files) ? files : [files];
207
+ const fileCount = list.length;
208
+ this.logEvent({ message: 'workout import requested', source, fileCount });
209
+ if (fileCount === 0) {
210
+ this.logEvent({ message: 'workout import rejected', reason: 'no-file', fileCount });
211
+ return;
212
+ }
213
+ delete this.importResult;
214
+ delete this.importError;
215
+ if (fileCount > 1) {
216
+ this.rejectImport(MSG_MULTIPLE_FILES, { reason: 'multiple-files', fileCount });
212
217
  return;
213
218
  }
214
- card.retry();
219
+ const ext = this.getImportExtension(list[0]);
220
+ if (!service_1.IMPORT_FILE_EXTENSIONS.includes(ext)) {
221
+ this.rejectImport(MSG_UNSUPPORTED_TYPE, { reason: 'unsupported-type', fileCount, ext });
222
+ return;
223
+ }
224
+ const observer = this.onImportFile(list[0]);
225
+ observer.on('success', () => { });
226
+ observer.on('error', () => { });
215
227
  }
216
228
  catch (err) {
217
- this.logError(err, 'onRetry');
229
+ this.logError(err, 'onImportFiles');
218
230
  }
219
231
  }
220
232
  onSetStepChangeAudioSignal(enabled) {
@@ -289,7 +301,7 @@ let DesktopWorkoutListPageService = (() => {
289
301
  this.logError(new Error(`list not found: ${listId}`), 'onCarouselInitialized');
290
302
  return;
291
303
  }
292
- this.getWorkoutList().onCarouselInitialized(list, item, itemsInSlide);
304
+ this.getWorkoutList().onCarouselInitialized(list, this.toDomainIndex(list, item), itemsInSlide);
293
305
  }
294
306
  catch (err) {
295
307
  this.logError(err, 'onCarouselInitialized');
@@ -302,7 +314,7 @@ let DesktopWorkoutListPageService = (() => {
302
314
  this.logError(new Error(`list not found: ${listId}`), 'onCarouselUpdated');
303
315
  return;
304
316
  }
305
- this.getWorkoutList().onCarouselUpdated(list, item, itemsInSlide);
317
+ this.getWorkoutList().onCarouselUpdated(list, this.toDomainIndex(list, item), itemsInSlide);
306
318
  }
307
319
  catch (err) {
308
320
  this.logError(err, 'onCarouselUpdated');
@@ -390,16 +402,42 @@ let DesktopWorkoutListPageService = (() => {
390
402
  return { id, title: list.getTitle(), observer: this.getListObserver(id), cards: this.mapCards(list, todayId) };
391
403
  }
392
404
  mapCards(list, todayId) {
393
- return (list.getCards() ?? []).map(c => this.mapCard(c, todayId));
405
+ return (list.getCards() ?? []).filter(c => !this.isHiddenCard(c)).map(c => this.mapCard(c, todayId));
406
+ }
407
+ isHiddenCard(card) {
408
+ return HIDDEN_CARD_TYPES.has(card.getCardType());
409
+ }
410
+ toDomainIndex(list, item) {
411
+ const cards = list.getCards() ?? [];
412
+ let visibleIdx = 0;
413
+ for (let idx = 0; idx < cards.length; idx++) {
414
+ if (this.isHiddenCard(cards[idx]))
415
+ continue;
416
+ if (visibleIdx === item)
417
+ return idx;
418
+ visibleIdx++;
419
+ }
420
+ return cards.length + (item - visibleIdx);
421
+ }
422
+ getImportExtension(info) {
423
+ const direct = info?.ext ?? info?.file?.ext;
424
+ const name = info?.name ?? info?.file?.name;
425
+ const ext = direct ?? (name?.includes('.') ? name.slice(name.lastIndexOf('.')) : '');
426
+ return ext.replace(/^\./, '').toLowerCase();
427
+ }
428
+ rejectImport(message, details) {
429
+ this.importGeneration = Date.now();
430
+ this.importPhase = 'error';
431
+ this.importError = message;
432
+ this.emitImportUpdate();
433
+ this.logEvent({ message: 'workout import rejected', ...details });
394
434
  }
395
435
  mapCard(card, todayId) {
396
436
  const id = card.getId();
397
437
  const cardType = card.getCardType();
398
438
  const { observer, selected, ...rest } = card.getDisplayProperties() ?? {};
399
439
  let props = rest;
400
- if (cardType === 'ActiveWorkoutImport')
401
- props = { ...rest, canDelete: !!rest.error };
402
- else if (cardType === 'ScheduledWorkout')
440
+ if (cardType === 'ScheduledWorkout')
403
441
  props = { ...rest, isToday: id === todayId };
404
442
  return { id, cardType, props, observer };
405
443
  }
@@ -411,12 +449,6 @@ let DesktopWorkoutListPageService = (() => {
411
449
  }
412
450
  return undefined;
413
451
  }
414
- importFiles(files) {
415
- if (!files)
416
- return;
417
- this.getWorkoutList().import(files, { showImportCards: true })
418
- .catch(err => { this.logError(err, 'onCardOK'); });
419
- }
420
452
  onCreateCardOK(card) {
421
453
  const { firstTime } = card.getDisplayProperties();
422
454
  if (firstTime) {
@@ -432,11 +464,6 @@ let DesktopWorkoutListPageService = (() => {
432
464
  if (link)
433
465
  this.getUIBinding().openBrowserWindow(link);
434
466
  }
435
- async deleteImportCard(card) {
436
- const deleted = await card.delete().wait();
437
- this.emitPageUpdate();
438
- return !!deleted;
439
- }
440
467
  };
441
468
  return DesktopWorkoutListPageService = _classThis;
442
469
  })();
@@ -36,9 +36,7 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
36
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
37
  exports.MobileWorkoutListPageService = void 0;
38
38
  const types_1 = require("../../../base/types");
39
- const observer_1 = require("../../../base/types/observer");
40
39
  const service_1 = require("../base/service");
41
- const DEFAULT_IMPORT_GROUP = 'My Workouts';
42
40
  const UPCOMING_COLLAPSED_COUNT = 3;
43
41
  let MobileWorkoutListPageService = (() => {
44
42
  let _classDecorators = [types_1.Singleton];
@@ -56,11 +54,6 @@ let MobileWorkoutListPageService = (() => {
56
54
  __runInitializers(_classThis, _classExtraInitializers);
57
55
  }
58
56
  groupFilter = null;
59
- importPhase;
60
- importingFileName;
61
- importResult;
62
- importError;
63
- importGeneration = 0;
64
57
  getRideTarget(ready) {
65
58
  return ready ? '/rideDeviceOK' : '/pairingStart';
66
59
  }
@@ -81,24 +74,6 @@ let MobileWorkoutListPageService = (() => {
81
74
  return {};
82
75
  }
83
76
  }
84
- getImportDisplayProps() {
85
- try {
86
- const phase = this.importPhase ?? 'landing';
87
- const knownGroups = this.getKnownGroups();
88
- const props = { phase, knownGroups };
89
- if (phase === 'importing')
90
- props.importing = { fileName: this.importingFileName };
91
- if (phase === 'result')
92
- props.result = this.importResult;
93
- if (phase === 'error')
94
- props.error = this.importError;
95
- return props;
96
- }
97
- catch (err) {
98
- this.logError(err, 'getImportDisplayProps');
99
- return { phase: 'landing', knownGroups: [] };
100
- }
101
- }
102
77
  onSelectGroup(group) {
103
78
  try {
104
79
  this.groupFilter = group;
@@ -108,79 +83,6 @@ let MobileWorkoutListPageService = (() => {
108
83
  this.logError(err, 'onSelectGroup');
109
84
  }
110
85
  }
111
- onImportOpen() {
112
- try {
113
- this.importPhase = 'landing';
114
- delete this.importError;
115
- delete this.importResult;
116
- this.emitImportUpdate();
117
- }
118
- catch (err) {
119
- this.logError(err, 'onImportOpen');
120
- }
121
- }
122
- onImportFile(file) {
123
- const observer = new observer_1.Observer();
124
- const generation = this.importGeneration = Date.now();
125
- try {
126
- this.importPhase = 'importing';
127
- this.importingFileName = file?.name;
128
- this.emitImportUpdate();
129
- this.logEvent({ message: 'workout import attempted', file: file?.name });
130
- this.getWorkoutList().import(file, { showImportCards: false })
131
- .then(([card]) => {
132
- const group = this.getLastUsedImportGroup();
133
- observer.emit('success');
134
- this.logEvent({ message: 'workout import succeeded', file: file?.name, workoutName: card.getTitle(), group });
135
- if (generation !== this.importGeneration)
136
- return;
137
- if (group !== DEFAULT_IMPORT_GROUP)
138
- card.move(group);
139
- this.importPhase = 'result';
140
- this.importResult = { id: card.getId(), workoutName: card.getTitle(), group };
141
- this.emitImportUpdate();
142
- })
143
- .catch((err) => {
144
- observer.emit('error', err);
145
- this.logEvent({ message: 'workout import failed', file: file?.name, error: err?.message });
146
- if (generation !== this.importGeneration)
147
- return;
148
- this.importPhase = 'error';
149
- this.importError = err?.message;
150
- this.emitImportUpdate();
151
- });
152
- }
153
- catch (err) {
154
- this.logError(err, 'onImportFile');
155
- }
156
- return observer;
157
- }
158
- onImportSetGroup(id, group) {
159
- try {
160
- const card = this.findWorkoutCard(id);
161
- card?.move(group);
162
- this.persistLastUsedImportGroup(group);
163
- if (this.importResult)
164
- this.importResult = { ...this.importResult, group };
165
- this.emitImportUpdate();
166
- }
167
- catch (err) {
168
- this.logError(err, 'onImportSetGroup');
169
- }
170
- }
171
- onImportClose() {
172
- try {
173
- this.importGeneration = Date.now();
174
- delete this.importPhase;
175
- delete this.importingFileName;
176
- delete this.importResult;
177
- delete this.importError;
178
- this.emitImportUpdate();
179
- }
180
- catch (err) {
181
- this.logError(err, 'onImportClose');
182
- }
183
- }
184
86
  getUpcomingTrainingProps() {
185
87
  const calendar = this.getWorkoutCalendar();
186
88
  const scheduled = calendar.getScheduledWorkouts();
@@ -203,10 +105,6 @@ let MobileWorkoutListPageService = (() => {
203
105
  const available = this.getKnownGroups();
204
106
  return { available, selected: this.groupFilter };
205
107
  }
206
- getKnownGroups() {
207
- const lists = this.getWorkoutList().getLists(false) ?? [];
208
- return lists.filter(l => l.getId() !== 'scheduled').map(l => l.getTitle());
209
- }
210
108
  getAllWorkoutItems() {
211
109
  const lists = this.getWorkoutList().getLists(false) ?? [];
212
110
  const items = [];
@@ -231,25 +129,6 @@ let MobileWorkoutListPageService = (() => {
231
129
  });
232
130
  return items;
233
131
  }
234
- getLastUsedImportGroup() {
235
- return this.getUserSettings().get('preferences.workouts.lastImportGroup', DEFAULT_IMPORT_GROUP);
236
- }
237
- persistLastUsedImportGroup(group) {
238
- try {
239
- this.getUserSettings().set('preferences.workouts.lastImportGroup', group);
240
- }
241
- catch (err) {
242
- this.logError(err, 'persistLastUsedImportGroup');
243
- }
244
- }
245
- emitImportUpdate() {
246
- try {
247
- this.getPageObserver()?.emit('import-update');
248
- }
249
- catch (err) {
250
- this.logError(err, 'emitImportUpdate');
251
- }
252
- }
253
132
  };
254
133
  return MobileWorkoutListPageService = _classThis;
255
134
  })();
@@ -34,11 +34,14 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
34
34
  };
35
35
  import { IncyclistPageService } from "../../../base/pages";
36
36
  import { Injectable } from "../../../base/decorators";
37
+ import { Observer } from "../../../base/types/observer";
37
38
  import { useUserSettings } from "../../../settings";
38
39
  import { useWorkoutCalendar } from "../../calendar";
39
40
  import { useWorkoutList } from "../../list/service";
40
41
  import { useDevicePairing } from "../../../devices";
41
42
  import { useRouteList } from "../../../routes";
43
+ const DEFAULT_IMPORT_GROUP = 'My Workouts';
44
+ export const IMPORT_FILE_EXTENSIONS = ['zwo', 'json'];
42
45
  let WorkoutListPageService = (() => {
43
46
  let _classSuper = IncyclistPageService;
44
47
  let _instanceExtraInitializers = [];
@@ -63,6 +66,11 @@ let WorkoutListPageService = (() => {
63
66
  if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
64
67
  }
65
68
  detailWorkoutId = (__runInitializers(this, _instanceExtraInitializers), null);
69
+ importPhase;
70
+ importingFileName;
71
+ importResult;
72
+ importError;
73
+ importGeneration = 0;
66
74
  listObserver;
67
75
  listUpdateHandler = this.emitPageUpdate.bind(this);
68
76
  calendarUpdateHandler = this.emitPageUpdate.bind(this);
@@ -212,6 +220,103 @@ let WorkoutListPageService = (() => {
212
220
  return false;
213
221
  }
214
222
  }
223
+ getImportDisplayProps() {
224
+ try {
225
+ const phase = this.importPhase ?? 'landing';
226
+ const knownGroups = this.getKnownGroups();
227
+ const props = { phase, knownGroups };
228
+ if (phase === 'importing')
229
+ props.importing = { fileName: this.importingFileName };
230
+ if (phase === 'result')
231
+ props.result = this.importResult;
232
+ if (phase === 'error')
233
+ props.error = this.importError;
234
+ return props;
235
+ }
236
+ catch (err) {
237
+ this.logError(err, 'getImportDisplayProps');
238
+ return { phase: 'landing', knownGroups: [] };
239
+ }
240
+ }
241
+ onImportOpen() {
242
+ try {
243
+ this.importPhase = 'landing';
244
+ delete this.importError;
245
+ delete this.importResult;
246
+ this.emitImportUpdate();
247
+ }
248
+ catch (err) {
249
+ this.logError(err, 'onImportOpen');
250
+ }
251
+ }
252
+ onImportFile(file) {
253
+ const observer = new Observer();
254
+ const generation = this.importGeneration = Date.now();
255
+ try {
256
+ this.importPhase = 'importing';
257
+ this.importingFileName = file?.name;
258
+ this.emitImportUpdate();
259
+ this.logEvent({ message: 'workout import attempted', file: file?.name });
260
+ this.getWorkoutList().import(file, { showImportCards: false })
261
+ .then(([card]) => {
262
+ const group = this.getLastUsedImportGroup();
263
+ observer.emit('success');
264
+ this.logEvent({ message: 'workout import succeeded', file: file?.name, workoutName: card.getTitle(), group });
265
+ if (generation !== this.importGeneration)
266
+ return;
267
+ if (group !== DEFAULT_IMPORT_GROUP)
268
+ card.move(group);
269
+ this.importPhase = 'result';
270
+ this.importResult = {
271
+ id: card.getId(),
272
+ workoutName: card.getTitle(),
273
+ group,
274
+ workout: card.getData?.(),
275
+ ftp: card.openSettings?.()?.settings?.ftp
276
+ };
277
+ this.emitImportUpdate();
278
+ })
279
+ .catch((err) => {
280
+ observer.emit('error', err);
281
+ this.logEvent({ message: 'workout import failed', file: file?.name, error: err?.message });
282
+ if (generation !== this.importGeneration)
283
+ return;
284
+ this.importPhase = 'error';
285
+ this.importError = err?.message;
286
+ this.emitImportUpdate();
287
+ });
288
+ }
289
+ catch (err) {
290
+ this.logError(err, 'onImportFile');
291
+ }
292
+ return observer;
293
+ }
294
+ onImportSetGroup(id, group) {
295
+ try {
296
+ const card = this.findWorkoutCard(id);
297
+ card?.move(group);
298
+ this.persistLastUsedImportGroup(group);
299
+ if (this.importResult)
300
+ this.importResult = { ...this.importResult, group };
301
+ this.emitImportUpdate();
302
+ }
303
+ catch (err) {
304
+ this.logError(err, 'onImportSetGroup');
305
+ }
306
+ }
307
+ onImportClose() {
308
+ try {
309
+ this.importGeneration = Date.now();
310
+ delete this.importPhase;
311
+ delete this.importingFileName;
312
+ delete this.importResult;
313
+ delete this.importError;
314
+ this.emitImportUpdate();
315
+ }
316
+ catch (err) {
317
+ this.logError(err, 'onImportClose');
318
+ }
319
+ }
215
320
  onStart(id, opts) {
216
321
  try {
217
322
  const card = this.findWorkoutCard(id, { includeScheduled: true });
@@ -280,6 +385,29 @@ let WorkoutListPageService = (() => {
280
385
  }
281
386
  return undefined;
282
387
  }
388
+ getKnownGroups() {
389
+ const lists = this.getWorkoutList().getLists(false) ?? [];
390
+ return lists.filter(l => l.getId() !== 'scheduled').map(l => l.getTitle());
391
+ }
392
+ getLastUsedImportGroup() {
393
+ return this.getUserSettings().get('preferences.workouts.lastImportGroup', DEFAULT_IMPORT_GROUP);
394
+ }
395
+ persistLastUsedImportGroup(group) {
396
+ try {
397
+ this.getUserSettings().set('preferences.workouts.lastImportGroup', group);
398
+ }
399
+ catch (err) {
400
+ this.logError(err, 'persistLastUsedImportGroup');
401
+ }
402
+ }
403
+ emitImportUpdate() {
404
+ try {
405
+ this.getPageObserver()?.emit('import-update');
406
+ }
407
+ catch (err) {
408
+ this.logError(err, 'emitImportUpdate');
409
+ }
410
+ }
283
411
  getScheduledTodayWorkoutId() {
284
412
  try {
285
413
  const today = this.getWorkoutCalendar().getScheduledToday();
@@ -34,13 +34,16 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
34
34
  };
35
35
  import { Singleton } from "../../../base/types";
36
36
  import { Observer } from "../../../base/types/observer";
37
- import { WorkoutListPageService } from "../base/service";
37
+ import { IMPORT_FILE_EXTENSIONS, WorkoutListPageService } from "../base/service";
38
38
  const STEP_CHANGE_AUDIO_KEY = 'preferences.workouts.stepChangeAudioSignal';
39
39
  const CREATE_OVERLAY = 'Create Workout Info';
40
40
  const SURFACE = 'workout-details';
41
41
  const DISPLAY_TYPE_KEY = 'preferences.workoutListDisplayType';
42
42
  const DEFAULT_DISPLAY_TYPE = 'tiles';
43
43
  const SCHEDULED_ID = 'scheduled';
44
+ const HIDDEN_CARD_TYPES = new Set(['WorkoutImport', 'ActiveWorkoutImport']);
45
+ const MSG_MULTIPLE_FILES = 'Only one workout file at a time';
46
+ const MSG_UNSUPPORTED_TYPE = 'Unsupported file type - please choose a ZWO or JSON file';
44
47
  let DesktopWorkoutListPageService = (() => {
45
48
  let _classDecorators = [Singleton];
46
49
  let _classDescriptor;
@@ -144,7 +147,7 @@ let DesktopWorkoutListPageService = (() => {
144
147
  return null;
145
148
  }
146
149
  }
147
- onCardOK(id, settings) {
150
+ onCardOK(id) {
148
151
  try {
149
152
  const card = this.findSnapshotCard(id);
150
153
  if (!card) {
@@ -152,9 +155,6 @@ let DesktopWorkoutListPageService = (() => {
152
155
  return;
153
156
  }
154
157
  switch (card.getCardType()) {
155
- case 'WorkoutImport':
156
- this.importFiles(settings);
157
- break;
158
158
  case 'WorkoutCreate':
159
159
  this.onCreateCardOK(card);
160
160
  break;
@@ -188,9 +188,6 @@ let DesktopWorkoutListPageService = (() => {
188
188
  }
189
189
  async onDelete(id) {
190
190
  try {
191
- const card = this.findSnapshotCard(id);
192
- if (card?.getCardType() === 'ActiveWorkoutImport')
193
- return await this.deleteImportCard(card);
194
191
  const surface = this.detailWorkoutId === id ? 'details' : 'card';
195
192
  const success = await super.onDelete(id);
196
193
  this.logEvent({ message: 'workout deleted', workoutId: id, success, surface });
@@ -201,17 +198,32 @@ let DesktopWorkoutListPageService = (() => {
201
198
  return false;
202
199
  }
203
200
  }
204
- onRetry(id) {
201
+ onImportFiles(files, source) {
205
202
  try {
206
- const card = this.findSnapshotCard(id);
207
- if (card?.getCardType() !== 'ActiveWorkoutImport') {
208
- this.logError(new Error(`import card not found: ${id}`), 'onRetry');
203
+ const list = Array.isArray(files) ? files : [files];
204
+ const fileCount = list.length;
205
+ this.logEvent({ message: 'workout import requested', source, fileCount });
206
+ if (fileCount === 0) {
207
+ this.logEvent({ message: 'workout import rejected', reason: 'no-file', fileCount });
208
+ return;
209
+ }
210
+ delete this.importResult;
211
+ delete this.importError;
212
+ if (fileCount > 1) {
213
+ this.rejectImport(MSG_MULTIPLE_FILES, { reason: 'multiple-files', fileCount });
209
214
  return;
210
215
  }
211
- card.retry();
216
+ const ext = this.getImportExtension(list[0]);
217
+ if (!IMPORT_FILE_EXTENSIONS.includes(ext)) {
218
+ this.rejectImport(MSG_UNSUPPORTED_TYPE, { reason: 'unsupported-type', fileCount, ext });
219
+ return;
220
+ }
221
+ const observer = this.onImportFile(list[0]);
222
+ observer.on('success', () => { });
223
+ observer.on('error', () => { });
212
224
  }
213
225
  catch (err) {
214
- this.logError(err, 'onRetry');
226
+ this.logError(err, 'onImportFiles');
215
227
  }
216
228
  }
217
229
  onSetStepChangeAudioSignal(enabled) {
@@ -286,7 +298,7 @@ let DesktopWorkoutListPageService = (() => {
286
298
  this.logError(new Error(`list not found: ${listId}`), 'onCarouselInitialized');
287
299
  return;
288
300
  }
289
- this.getWorkoutList().onCarouselInitialized(list, item, itemsInSlide);
301
+ this.getWorkoutList().onCarouselInitialized(list, this.toDomainIndex(list, item), itemsInSlide);
290
302
  }
291
303
  catch (err) {
292
304
  this.logError(err, 'onCarouselInitialized');
@@ -299,7 +311,7 @@ let DesktopWorkoutListPageService = (() => {
299
311
  this.logError(new Error(`list not found: ${listId}`), 'onCarouselUpdated');
300
312
  return;
301
313
  }
302
- this.getWorkoutList().onCarouselUpdated(list, item, itemsInSlide);
314
+ this.getWorkoutList().onCarouselUpdated(list, this.toDomainIndex(list, item), itemsInSlide);
303
315
  }
304
316
  catch (err) {
305
317
  this.logError(err, 'onCarouselUpdated');
@@ -387,16 +399,42 @@ let DesktopWorkoutListPageService = (() => {
387
399
  return { id, title: list.getTitle(), observer: this.getListObserver(id), cards: this.mapCards(list, todayId) };
388
400
  }
389
401
  mapCards(list, todayId) {
390
- return (list.getCards() ?? []).map(c => this.mapCard(c, todayId));
402
+ return (list.getCards() ?? []).filter(c => !this.isHiddenCard(c)).map(c => this.mapCard(c, todayId));
403
+ }
404
+ isHiddenCard(card) {
405
+ return HIDDEN_CARD_TYPES.has(card.getCardType());
406
+ }
407
+ toDomainIndex(list, item) {
408
+ const cards = list.getCards() ?? [];
409
+ let visibleIdx = 0;
410
+ for (let idx = 0; idx < cards.length; idx++) {
411
+ if (this.isHiddenCard(cards[idx]))
412
+ continue;
413
+ if (visibleIdx === item)
414
+ return idx;
415
+ visibleIdx++;
416
+ }
417
+ return cards.length + (item - visibleIdx);
418
+ }
419
+ getImportExtension(info) {
420
+ const direct = info?.ext ?? info?.file?.ext;
421
+ const name = info?.name ?? info?.file?.name;
422
+ const ext = direct ?? (name?.includes('.') ? name.slice(name.lastIndexOf('.')) : '');
423
+ return ext.replace(/^\./, '').toLowerCase();
424
+ }
425
+ rejectImport(message, details) {
426
+ this.importGeneration = Date.now();
427
+ this.importPhase = 'error';
428
+ this.importError = message;
429
+ this.emitImportUpdate();
430
+ this.logEvent({ message: 'workout import rejected', ...details });
391
431
  }
392
432
  mapCard(card, todayId) {
393
433
  const id = card.getId();
394
434
  const cardType = card.getCardType();
395
435
  const { observer, selected, ...rest } = card.getDisplayProperties() ?? {};
396
436
  let props = rest;
397
- if (cardType === 'ActiveWorkoutImport')
398
- props = { ...rest, canDelete: !!rest.error };
399
- else if (cardType === 'ScheduledWorkout')
437
+ if (cardType === 'ScheduledWorkout')
400
438
  props = { ...rest, isToday: id === todayId };
401
439
  return { id, cardType, props, observer };
402
440
  }
@@ -408,12 +446,6 @@ let DesktopWorkoutListPageService = (() => {
408
446
  }
409
447
  return undefined;
410
448
  }
411
- importFiles(files) {
412
- if (!files)
413
- return;
414
- this.getWorkoutList().import(files, { showImportCards: true })
415
- .catch(err => { this.logError(err, 'onCardOK'); });
416
- }
417
449
  onCreateCardOK(card) {
418
450
  const { firstTime } = card.getDisplayProperties();
419
451
  if (firstTime) {
@@ -429,11 +461,6 @@ let DesktopWorkoutListPageService = (() => {
429
461
  if (link)
430
462
  this.getUIBinding().openBrowserWindow(link);
431
463
  }
432
- async deleteImportCard(card) {
433
- const deleted = await card.delete().wait();
434
- this.emitPageUpdate();
435
- return !!deleted;
436
- }
437
464
  };
438
465
  return DesktopWorkoutListPageService = _classThis;
439
466
  })();
@@ -33,9 +33,7 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
33
33
  return useValue ? value : void 0;
34
34
  };
35
35
  import { Singleton } from "../../../base/types";
36
- import { Observer } from "../../../base/types/observer";
37
36
  import { WorkoutListPageService } from "../base/service";
38
- const DEFAULT_IMPORT_GROUP = 'My Workouts';
39
37
  const UPCOMING_COLLAPSED_COUNT = 3;
40
38
  let MobileWorkoutListPageService = (() => {
41
39
  let _classDecorators = [Singleton];
@@ -53,11 +51,6 @@ let MobileWorkoutListPageService = (() => {
53
51
  __runInitializers(_classThis, _classExtraInitializers);
54
52
  }
55
53
  groupFilter = null;
56
- importPhase;
57
- importingFileName;
58
- importResult;
59
- importError;
60
- importGeneration = 0;
61
54
  getRideTarget(ready) {
62
55
  return ready ? '/rideDeviceOK' : '/pairingStart';
63
56
  }
@@ -78,24 +71,6 @@ let MobileWorkoutListPageService = (() => {
78
71
  return {};
79
72
  }
80
73
  }
81
- getImportDisplayProps() {
82
- try {
83
- const phase = this.importPhase ?? 'landing';
84
- const knownGroups = this.getKnownGroups();
85
- const props = { phase, knownGroups };
86
- if (phase === 'importing')
87
- props.importing = { fileName: this.importingFileName };
88
- if (phase === 'result')
89
- props.result = this.importResult;
90
- if (phase === 'error')
91
- props.error = this.importError;
92
- return props;
93
- }
94
- catch (err) {
95
- this.logError(err, 'getImportDisplayProps');
96
- return { phase: 'landing', knownGroups: [] };
97
- }
98
- }
99
74
  onSelectGroup(group) {
100
75
  try {
101
76
  this.groupFilter = group;
@@ -105,79 +80,6 @@ let MobileWorkoutListPageService = (() => {
105
80
  this.logError(err, 'onSelectGroup');
106
81
  }
107
82
  }
108
- onImportOpen() {
109
- try {
110
- this.importPhase = 'landing';
111
- delete this.importError;
112
- delete this.importResult;
113
- this.emitImportUpdate();
114
- }
115
- catch (err) {
116
- this.logError(err, 'onImportOpen');
117
- }
118
- }
119
- onImportFile(file) {
120
- const observer = new Observer();
121
- const generation = this.importGeneration = Date.now();
122
- try {
123
- this.importPhase = 'importing';
124
- this.importingFileName = file?.name;
125
- this.emitImportUpdate();
126
- this.logEvent({ message: 'workout import attempted', file: file?.name });
127
- this.getWorkoutList().import(file, { showImportCards: false })
128
- .then(([card]) => {
129
- const group = this.getLastUsedImportGroup();
130
- observer.emit('success');
131
- this.logEvent({ message: 'workout import succeeded', file: file?.name, workoutName: card.getTitle(), group });
132
- if (generation !== this.importGeneration)
133
- return;
134
- if (group !== DEFAULT_IMPORT_GROUP)
135
- card.move(group);
136
- this.importPhase = 'result';
137
- this.importResult = { id: card.getId(), workoutName: card.getTitle(), group };
138
- this.emitImportUpdate();
139
- })
140
- .catch((err) => {
141
- observer.emit('error', err);
142
- this.logEvent({ message: 'workout import failed', file: file?.name, error: err?.message });
143
- if (generation !== this.importGeneration)
144
- return;
145
- this.importPhase = 'error';
146
- this.importError = err?.message;
147
- this.emitImportUpdate();
148
- });
149
- }
150
- catch (err) {
151
- this.logError(err, 'onImportFile');
152
- }
153
- return observer;
154
- }
155
- onImportSetGroup(id, group) {
156
- try {
157
- const card = this.findWorkoutCard(id);
158
- card?.move(group);
159
- this.persistLastUsedImportGroup(group);
160
- if (this.importResult)
161
- this.importResult = { ...this.importResult, group };
162
- this.emitImportUpdate();
163
- }
164
- catch (err) {
165
- this.logError(err, 'onImportSetGroup');
166
- }
167
- }
168
- onImportClose() {
169
- try {
170
- this.importGeneration = Date.now();
171
- delete this.importPhase;
172
- delete this.importingFileName;
173
- delete this.importResult;
174
- delete this.importError;
175
- this.emitImportUpdate();
176
- }
177
- catch (err) {
178
- this.logError(err, 'onImportClose');
179
- }
180
- }
181
83
  getUpcomingTrainingProps() {
182
84
  const calendar = this.getWorkoutCalendar();
183
85
  const scheduled = calendar.getScheduledWorkouts();
@@ -200,10 +102,6 @@ let MobileWorkoutListPageService = (() => {
200
102
  const available = this.getKnownGroups();
201
103
  return { available, selected: this.groupFilter };
202
104
  }
203
- getKnownGroups() {
204
- const lists = this.getWorkoutList().getLists(false) ?? [];
205
- return lists.filter(l => l.getId() !== 'scheduled').map(l => l.getTitle());
206
- }
207
105
  getAllWorkoutItems() {
208
106
  const lists = this.getWorkoutList().getLists(false) ?? [];
209
107
  const items = [];
@@ -228,25 +126,6 @@ let MobileWorkoutListPageService = (() => {
228
126
  });
229
127
  return items;
230
128
  }
231
- getLastUsedImportGroup() {
232
- return this.getUserSettings().get('preferences.workouts.lastImportGroup', DEFAULT_IMPORT_GROUP);
233
- }
234
- persistLastUsedImportGroup(group) {
235
- try {
236
- this.getUserSettings().set('preferences.workouts.lastImportGroup', group);
237
- }
238
- catch (err) {
239
- this.logError(err, 'persistLastUsedImportGroup');
240
- }
241
- }
242
- emitImportUpdate() {
243
- try {
244
- this.getPageObserver()?.emit('import-update');
245
- }
246
- catch (err) {
247
- this.logError(err, 'emitImportUpdate');
248
- }
249
- }
250
129
  };
251
130
  return MobileWorkoutListPageService = _classThis;
252
131
  })();
@@ -1,10 +1,16 @@
1
1
  import { IncyclistPageService } from "../../../base/pages";
2
- import { IObserver } from "../../../types";
2
+ import { FileInfo, IObserver } from "../../../types";
3
3
  import { WorkoutCard } from "../../list/cards/WorkoutCard";
4
4
  import { WorkoutListService } from "../../list/service";
5
- import { AttachedRouteProps, WorkoutDetailsProps } from "./types";
5
+ import { AttachedRouteProps, WorkoutDetailsProps, WorkoutImportDisplayProps } from "./types";
6
+ export declare const IMPORT_FILE_EXTENSIONS: string[];
6
7
  export declare abstract class WorkoutListPageService extends IncyclistPageService {
7
8
  protected detailWorkoutId: string | null;
9
+ protected importPhase: 'landing' | 'importing' | 'result' | 'error' | undefined;
10
+ protected importingFileName: string;
11
+ protected importResult: WorkoutImportDisplayProps['result'];
12
+ protected importError: string;
13
+ protected importGeneration: number;
8
14
  protected listObserver: IObserver;
9
15
  protected listUpdateHandler: any;
10
16
  protected calendarUpdateHandler: any;
@@ -21,6 +27,11 @@ export declare abstract class WorkoutListPageService extends IncyclistPageServic
21
27
  onSetErgMode(enabled: boolean): void;
22
28
  onChangeGroup(id: string, group: string): void;
23
29
  onDelete(id: string): Promise<boolean>;
30
+ getImportDisplayProps(): WorkoutImportDisplayProps;
31
+ onImportOpen(): void;
32
+ onImportFile(file: FileInfo): IObserver;
33
+ onImportSetGroup(id: string, group: string): void;
34
+ onImportClose(): void;
24
35
  onStart(id: string, opts: {
25
36
  noRoute: boolean;
26
37
  }): void;
@@ -30,6 +41,10 @@ export declare abstract class WorkoutListPageService extends IncyclistPageServic
30
41
  protected findWorkoutCard(id: string, opts?: {
31
42
  includeScheduled?: boolean;
32
43
  }): WorkoutCard | undefined;
44
+ protected getKnownGroups(): string[];
45
+ protected getLastUsedImportGroup(): string;
46
+ protected persistLastUsedImportGroup(group: string): void;
47
+ protected emitImportUpdate(): void;
33
48
  protected getScheduledTodayWorkoutId(): string | null;
34
49
  protected formatDuration(duration: number): string;
35
50
  protected emitPageUpdate(): void;
@@ -1,3 +1,4 @@
1
+ import { FileInfo, IObserver } from "../../../types";
1
2
  import { Workout } from "../../base/model";
2
3
  export interface AttachedRouteProps {
3
4
  id: string;
@@ -35,3 +36,24 @@ export interface WorkoutDetailsCallbacks {
35
36
  onClearSelection: () => void;
36
37
  onClearRouteSelection: () => void;
37
38
  }
39
+ export interface WorkoutImportDisplayProps {
40
+ phase: 'landing' | 'importing' | 'result' | 'error';
41
+ knownGroups: string[];
42
+ importing?: {
43
+ fileName: string;
44
+ };
45
+ result?: {
46
+ id: string;
47
+ workoutName: string;
48
+ group: string;
49
+ workout?: Workout;
50
+ ftp?: number;
51
+ };
52
+ error?: string;
53
+ }
54
+ export interface WorkoutImportCallbacks {
55
+ onImportOpen: () => void;
56
+ onImportFile: (file: FileInfo) => IObserver;
57
+ onImportSetGroup: (id: string, group: string) => void;
58
+ onImportClose: () => void;
59
+ }
@@ -1,12 +1,11 @@
1
1
  import { Observer } from "../../../base/types/observer";
2
2
  import { Card, CardList } from "../../../base/cardlist";
3
- import { FileInfo } from "../../../api";
4
3
  import { IObserver } from "../../../types";
5
4
  import type { WorkoutCreateCard } from "../../list/cards/WorkoutCreateCard";
6
5
  import type { WP } from "../../list/types";
7
6
  import type { DisplayType } from "../../../routes/list/types";
8
7
  import { WorkoutListPageService } from "../base/service";
9
- import { DesktopCreateInfoProps, DesktopWorkoutCardProps, DesktopWorkoutDetailsProps, DesktopWorkoutListDisplayProps, DesktopWorkoutListProps, DesktopUpcomingProps } from "./types";
8
+ import { DesktopCreateInfoProps, DesktopWorkoutCardProps, DesktopWorkoutDetailsProps, DesktopWorkoutListDisplayProps, DesktopWorkoutListProps, DesktopUpcomingProps, WorkoutImportFile, WorkoutImportSource } from "./types";
10
9
  type DomainSubscription = {
11
10
  observer: IObserver;
12
11
  handler: (list: CardList<WP>) => void;
@@ -27,10 +26,10 @@ export declare class DesktopWorkoutListPageService extends WorkoutListPageServic
27
26
  onDisplayTypeSelected(type: DisplayType): void;
28
27
  getPageDisplayProperties(): DesktopWorkoutListDisplayProps;
29
28
  getWorkoutDetailsProps(id: string): DesktopWorkoutDetailsProps | null;
30
- onCardOK(id: string, settings?: FileInfo | FileInfo[]): void;
29
+ onCardOK(id: string): void;
31
30
  onCreateInfoClosed(markAsSeen: boolean): void;
32
31
  onDelete(id: string): Promise<boolean>;
33
- onRetry(id: string): void;
32
+ onImportFiles(files: WorkoutImportFile | WorkoutImportFile[], source: WorkoutImportSource): void;
34
33
  onSetStepChangeAudioSignal(enabled: boolean): void;
35
34
  onStartFromDetails(id: string): void;
36
35
  onAddRoute(id: string): void;
@@ -51,11 +50,17 @@ export declare class DesktopWorkoutListPageService extends WorkoutListPageServic
51
50
  protected getListObserver(id: string): Observer;
52
51
  protected mapList(list: CardList<WP>, todayId: string | null): DesktopWorkoutListProps;
53
52
  protected mapCards(list: CardList<WP>, todayId: string | null): DesktopWorkoutCardProps[];
53
+ protected isHiddenCard(card: Card<WP>): boolean;
54
+ protected toDomainIndex(list: CardList<WP>, item: number): number;
55
+ protected getImportExtension(info: WorkoutImportFile): string;
56
+ protected rejectImport(message: string, details: {
57
+ reason: string;
58
+ fileCount: number;
59
+ ext?: string;
60
+ }): void;
54
61
  protected mapCard(card: Card<WP>, todayId: string | null): DesktopWorkoutCardProps;
55
62
  protected findSnapshotCard(id: string): Card<WP> | undefined;
56
- protected importFiles(files?: FileInfo | FileInfo[]): void;
57
63
  protected onCreateCardOK(card: WorkoutCreateCard): void;
58
64
  protected openCreateLink(card?: WorkoutCreateCard): void;
59
- protected deleteImportCard(card: Card<WP>): Promise<boolean>;
60
65
  }
61
66
  export {};
@@ -1,5 +1,5 @@
1
- import type { IObserver } from "../../../types";
2
- import type { ActiveImportProps, ScheduledWorkoutCardDisplayProperties, WorkoutCardDisplayProperties, WorkoutCardType, WorkoutCreateProps, WorkoutImportProps } from "../../list/cards/types";
1
+ import type { FileInfo, IObserver } from "../../../types";
2
+ import type { ScheduledWorkoutCardDisplayProperties, WorkoutCardDisplayProperties, WorkoutCardType, WorkoutCreateProps } from "../../list/cards/types";
3
3
  import type { DisplayType } from "../../../routes/list/types";
4
4
  import type { WorkoutDetailsProps } from "../base/types";
5
5
  export type DesktopWorkoutListDisplayProps = {
@@ -25,14 +25,11 @@ export type DesktopWorkoutCardProps = {
25
25
  props: DesktopWorkoutCardContent;
26
26
  observer?: IObserver;
27
27
  };
28
- export type DesktopActiveImportCardContent = Omit<ActiveImportProps, 'observer'> & {
29
- canDelete: boolean;
30
- };
31
28
  export type DesktopWorkoutCardContentBase = Omit<WorkoutCardDisplayProperties, 'observer' | 'selected'>;
32
29
  export type DesktopScheduledCardContent = Omit<ScheduledWorkoutCardDisplayProperties, 'observer' | 'selected'> & {
33
30
  isToday: boolean;
34
31
  };
35
- export type DesktopWorkoutCardContent = WorkoutImportProps | WorkoutCreateProps | DesktopActiveImportCardContent | DesktopWorkoutCardContentBase | DesktopScheduledCardContent;
32
+ export type DesktopWorkoutCardContent = WorkoutCreateProps | DesktopWorkoutCardContentBase | DesktopScheduledCardContent;
36
33
  export type DesktopCreateInfoProps = {
37
34
  markAsSeenDefault: boolean;
38
35
  };
@@ -40,3 +37,11 @@ export type DesktopWorkoutDetailsProps = WorkoutDetailsProps & {
40
37
  stepChangeAudioSignal: boolean;
41
38
  canAddRoute: boolean;
42
39
  };
40
+ export type WorkoutImportSource = 'page-drop' | 'dialog';
41
+ export type WorkoutImportFile = Partial<Omit<FileInfo, 'type'>> & {
42
+ type?: FileInfo['type'];
43
+ file?: {
44
+ name?: string;
45
+ ext?: string;
46
+ };
47
+ };
@@ -1,31 +1,11 @@
1
- import { IObserver } from "../../../types";
2
- import { FileInfo } from "../../../api";
3
1
  import { WorkoutListPageService } from "../base/service";
4
- import { GroupFilterProps, IWorkoutListPageService, UpcomingTrainingProps, WorkoutImportDisplayProps, WorkoutListItemProps, WorkoutListPageDisplayProps } from "./types";
2
+ import { GroupFilterProps, IWorkoutListPageService, UpcomingTrainingProps, WorkoutListItemProps, WorkoutListPageDisplayProps } from "./types";
5
3
  export declare class MobileWorkoutListPageService extends WorkoutListPageService implements IWorkoutListPageService {
6
4
  protected groupFilter: string | null;
7
- protected importPhase: 'landing' | 'importing' | 'result' | 'error' | undefined;
8
- protected importingFileName: string;
9
- protected importResult: {
10
- id: string;
11
- workoutName: string;
12
- group: string;
13
- };
14
- protected importError: string;
15
- protected importGeneration: number;
16
5
  protected getRideTarget(ready: boolean): string;
17
6
  getPageDisplayProps(): WorkoutListPageDisplayProps;
18
- getImportDisplayProps(): WorkoutImportDisplayProps;
19
7
  onSelectGroup(group: string | null): void;
20
- onImportOpen(): void;
21
- onImportFile(file: FileInfo): IObserver;
22
- onImportSetGroup(id: string, group: string): void;
23
- onImportClose(): void;
24
8
  protected getUpcomingTrainingProps(): UpcomingTrainingProps | null;
25
9
  protected getGroupFilterProps(): GroupFilterProps;
26
- protected getKnownGroups(): string[];
27
10
  protected getAllWorkoutItems(): WorkoutListItemProps[];
28
- protected getLastUsedImportGroup(): string;
29
- protected persistLastUsedImportGroup(group: string): void;
30
- protected emitImportUpdate(): void;
31
11
  }
@@ -1,6 +1,5 @@
1
- import { FileInfo, IObserver } from "../../../types";
2
1
  import { Workout } from "../../base/model";
3
- import { WorkoutDetailsCallbacks, WorkoutDetailsProps } from "../base/types";
2
+ import { WorkoutDetailsCallbacks, WorkoutDetailsProps, WorkoutImportCallbacks, WorkoutImportDisplayProps } from "../base/types";
4
3
  export type WorkoutListPageDisplayProps = WorkoutListContentProps;
5
4
  export interface WorkoutListContentProps {
6
5
  pageType: 'list';
@@ -39,25 +38,8 @@ export interface WorkoutListItemProps {
39
38
  canDelete: boolean;
40
39
  workout: Workout;
41
40
  }
42
- export interface WorkoutImportDisplayProps {
43
- phase: 'landing' | 'importing' | 'result' | 'error';
44
- knownGroups: string[];
45
- importing?: {
46
- fileName: string;
47
- };
48
- result?: {
49
- id: string;
50
- workoutName: string;
51
- group: string;
52
- };
53
- error?: string;
54
- }
55
- export interface WorkoutListPageCallbacks extends WorkoutDetailsCallbacks {
41
+ export interface WorkoutListPageCallbacks extends WorkoutDetailsCallbacks, WorkoutImportCallbacks {
56
42
  onSelectGroup: (group: string | null) => void;
57
- onImportOpen: () => void;
58
- onImportFile: (file: FileInfo) => IObserver;
59
- onImportSetGroup: (id: string, group: string) => void;
60
- onImportClose: () => void;
61
43
  }
62
44
  export interface IWorkoutListPageService extends WorkoutListPageCallbacks {
63
45
  getPageDisplayProps(): WorkoutListPageDisplayProps;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.9.28",
3
+ "version": "1.9.29",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.27"
6
6
  },