Skip to content

Commit fa88271

Browse files
committed
Fixed with instrument list import/export
1 parent ba3d6b6 commit fa88271

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/store/modules/instrument-module.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,20 +194,21 @@ export default {
194194
reject(getters.getCopy('ERROR_FILE_LOAD'));
195195
};
196196

197-
reader.onload = readerEvent => {
197+
reader.onload = async readerEvent => {
198198
const fileData = readerEvent.target.result;
199199
const instruments = JSON.parse(window.atob(fileData));
200200

201201
// check if we're dealing with valid instruments
202202

203203
if (Array.isArray(instruments)) {
204204
let amountImported = 0;
205-
instruments.forEach(async instrument => {
205+
for (let i = 0; i < instruments.length; ++i) {
206+
const instrument = instruments[i];
206207
if (InstrumentValidator.isValid(instrument)) {
207208
await dispatch('saveInstrument', instrument);
208209
++amountImported;
209210
}
210-
});
211+
}
211212
resolve(amountImported);
212213
} else {
213214
resolve(getters.getCopy('ERROR_INSTRUMENT_IMPORT'));
@@ -218,13 +219,19 @@ export default {
218219
});
219220
});
220221
},
221-
exportInstruments({ state }) {
222-
return new Promise((resolve, reject) => {
222+
exportInstruments({ state, getters, dispatch }) {
223+
return new Promise(async (resolve, reject) => {
223224
if (Array.isArray(state.instruments ) && state.instruments.length > 0) {
225+
// retrieve all instrument data
226+
const instruments = [];
227+
for (let i = 0; i < state.instruments.length; ++i) {
228+
const ins = state.instruments[i];
229+
const instrument = await dispatch('loadInstrument', getters.getInstrumentByPresetName(ins.presetName));
230+
instruments.push(instrument);
231+
}
224232

225233
// encode instrument data
226-
227-
const data = window.btoa(JSON.stringify(state.instruments));
234+
const data = window.btoa(JSON.stringify(instruments));
228235

229236
// download file to disk
230237

0 commit comments

Comments
 (0)