fix(shared): Handle YAML imports
This commit is contained in:
parent
bc8d1787bb
commit
38c7b7d9e9
1 changed files with 6 additions and 2 deletions
|
@ -11,6 +11,7 @@ import { FileInput } from 'shared/components/inputs.mjs'
|
||||||
import { Yaml } from 'shared/components/yaml.mjs'
|
import { Yaml } from 'shared/components/yaml.mjs'
|
||||||
import { Popout } from 'shared/components/popout/index.mjs'
|
import { Popout } from 'shared/components/popout/index.mjs'
|
||||||
import { linkClasses } from 'shared/components/link.mjs'
|
import { linkClasses } from 'shared/components/link.mjs'
|
||||||
|
import yaml from 'yaml'
|
||||||
|
|
||||||
export const ns = ['account', 'status']
|
export const ns = ['account', 'status']
|
||||||
|
|
||||||
|
@ -39,23 +40,26 @@ export const Importer = () => {
|
||||||
* Treat each set
|
* Treat each set
|
||||||
*/
|
*/
|
||||||
for (const set of data) {
|
for (const set of data) {
|
||||||
if (set.measurements) {
|
if (set.measurements || set.measies) {
|
||||||
const name = set.name || 'J. Doe'
|
const name = set.name || 'J. Doe'
|
||||||
setLoadingStatus([true, `Importing ${name}`])
|
setLoadingStatus([true, `Importing ${name}`])
|
||||||
const result = await backend.createSet({
|
const result = await backend.createSet({
|
||||||
name: set.name || 'J. Doe',
|
name: set.name || 'J. Doe',
|
||||||
units: set.units || 'metric',
|
units: set.units || 'metric',
|
||||||
notes: set.notes || '',
|
notes: set.notes || '',
|
||||||
measies: set.measurements,
|
measies: set.measurements || set.measies,
|
||||||
userId: account.id,
|
userId: account.id,
|
||||||
})
|
})
|
||||||
if (result.success) setLoadingStatus([true, `Imported ${name}`, true, true])
|
if (result.success) setLoadingStatus([true, `Imported ${name}`, true, true])
|
||||||
else setLoadingStatus([true, `Import of ${name} failed`, true, false])
|
else setLoadingStatus([true, `Import of ${name} failed`, true, false])
|
||||||
|
} else {
|
||||||
|
setLoadingStatus([true, `Invalid format`, true, false])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err)
|
setError(err)
|
||||||
console.log(err)
|
console.log(err)
|
||||||
|
setLoadingStatus([true, `Import of ${name} failed`, true, false])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue