Include sets, minutes and seconds in importing/exporting sets
This commit is contained in:
parent
14d71fec8b
commit
32776a5217
|
@ -11,7 +11,8 @@ import {addPlans, deletePlans, getAllPlans} from './plan.service';
|
||||||
import {addSets, deleteSets, getAllSets} from './set.service';
|
import {addSets, deleteSets, getAllSets} from './set.service';
|
||||||
import {write} from './write';
|
import {write} from './write';
|
||||||
|
|
||||||
const setFields = 'id,name,reps,weight,created,unit,hidden';
|
const setFields =
|
||||||
|
'id,name,reps,weight,created,unit,hidden,sets,minutes,seconds';
|
||||||
const planFields = 'id,days,workouts';
|
const planFields = 'id,days,workouts';
|
||||||
|
|
||||||
export default function DrawerMenu({name}: {name: keyof DrawerParamList}) {
|
export default function DrawerMenu({name}: {name: keyof DrawerParamList}) {
|
||||||
|
@ -26,7 +27,7 @@ export default function DrawerMenu({name}: {name: keyof DrawerParamList}) {
|
||||||
.concat(
|
.concat(
|
||||||
sets.map(
|
sets.map(
|
||||||
set =>
|
set =>
|
||||||
`${set.id},${set.name},${set.reps},${set.weight},${set.created},${set.unit},${set.hidden}`,
|
`${set.id},${set.name},${set.reps},${set.weight},${set.created},${set.unit},${set.hidden},${set.sets},${set.minutes},${set.seconds}`,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.join('\n');
|
.join('\n');
|
||||||
|
@ -54,16 +55,30 @@ export default function DrawerMenu({name}: {name: keyof DrawerParamList}) {
|
||||||
const file = await FileSystem.readFile(result.uri);
|
const file = await FileSystem.readFile(result.uri);
|
||||||
console.log(`${DrawerMenu.name}.${uploadSets.name}:`, file.length);
|
console.log(`${DrawerMenu.name}.${uploadSets.name}:`, file.length);
|
||||||
const lines = file.split('\n');
|
const lines = file.split('\n');
|
||||||
if (lines[0] != setFields) return toast('Invalid csv.', 3000);
|
console.log(lines[0]);
|
||||||
|
if (!setFields.includes(lines[0])) return toast('Invalid csv.', 3000);
|
||||||
const values = lines
|
const values = lines
|
||||||
.slice(1)
|
.slice(1)
|
||||||
.filter(line => line)
|
.filter(line => line)
|
||||||
.map(set => {
|
.map(set => {
|
||||||
const cells = set.split(',');
|
const [
|
||||||
return `('${cells[1]}',${cells[2]},${cells[3]},'${cells[4]}','${cells[5]}',${cells[6]})`;
|
,
|
||||||
|
setName,
|
||||||
|
reps,
|
||||||
|
weight,
|
||||||
|
created,
|
||||||
|
unit,
|
||||||
|
hidden,
|
||||||
|
sets,
|
||||||
|
minutes,
|
||||||
|
seconds,
|
||||||
|
] = set.split(',');
|
||||||
|
return `('${setName}',${reps},${weight},'${created}','${unit}',${hidden},${
|
||||||
|
sets ?? 3
|
||||||
|
},${minutes ?? 3},${seconds ?? 30})`;
|
||||||
})
|
})
|
||||||
.join(',');
|
.join(',');
|
||||||
await addSets(values);
|
await addSets(setFields.split(',').slice(1).join(','), values);
|
||||||
toast('Data imported.', 3000);
|
toast('Data imported.', 3000);
|
||||||
reset({index: 0, routes: [{name}]});
|
reset({index: 0, routes: [{name}]});
|
||||||
}, [reset, name, toast]);
|
}, [reset, name, toast]);
|
||||||
|
@ -79,8 +94,10 @@ export default function DrawerMenu({name}: {name: keyof DrawerParamList}) {
|
||||||
.slice(1)
|
.slice(1)
|
||||||
.filter(line => line)
|
.filter(line => line)
|
||||||
.map(set => {
|
.map(set => {
|
||||||
const cells = set.split('","').map(cell => cell.replace(/"/g, ''));
|
const [, days, workouts] = set
|
||||||
return `('${cells[1]}','${cells[2]}')`;
|
.split('","')
|
||||||
|
.map(cell => cell.replace(/"/g, ''));
|
||||||
|
return `('${days}','${workouts}')`;
|
||||||
})
|
})
|
||||||
.join(',');
|
.join(',');
|
||||||
await addPlans(values);
|
await addPlans(values);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user