rep: handle missing storage

master
Rob Pilling 2023-06-18 22:18:42 +01:00
parent 517ff7c405
commit 1c76e03751
1 changed files with 21 additions and 11 deletions

View File

@ -1,25 +1,35 @@
{ {
const L = require("Layout"); const L = require("Layout");
type Rep = { type StoreRep = {
/// duration in ms
dur: number, dur: number,
/// label of this rep
label: string, label: string,
};
type Rep = StoreRep & {
/// cumulative duration (ms)
accDur: number, accDur: number,
}; };
const reps: Rep[] = (require("Storage") const storeReps = require("Storage")
.readJSON("rep.json") as Rep[] | undefined /* TODO */) .readJSON("rep.json") as Rep[] | undefined;
.map(((r: Rep, i: number, a: Rep[]): Rep => {
if(storeReps == null){
E.showAlert("No reps in storage\nLoad them on with the app loader")
.then(() => load());
throw new Error("no storage");
}
const reps = storeReps.map((r: StoreRep, i: number, a: Rep[]): Rep => {
const r2 = r as Rep; const r2 = r as Rep;
r2.dur = r2.dur * 60 * 1000;
r2.accDur = i > 0 r2.accDur = i > 0
? a[i-1]!.accDur + r.dur ? a[i-1]!.accDur + r.dur
: r.dur; : r.dur;
return r2;
return r as Rep; });
}) as any);
const fontSzMain = 54; const fontSzMain = 54;
const fontScaleRep = 2; const fontScaleRep = 2;