Add default strings if none are given

This commit is contained in:
Pieter Vander Vennet 2022-10-28 04:38:10 +02:00
parent 8d304f9a56
commit de137055d3

View file

@ -15,6 +15,15 @@ import {Translation} from "../i18n/Translation";
export default class UploadTraceToOsmUI extends Toggle { export default class UploadTraceToOsmUI extends Toggle {
private static createDefault(s: string, defaultValue: string){
if(defaultValue.length < 1){
throw "Default value should have some characters"
}
if(s === undefined || s === null || s === ""){
return defaultValue
}
return s
}
constructor( constructor(
trace: (title: string) => string, trace: (title: string) => string,
@ -76,10 +85,12 @@ export default class UploadTraceToOsmUI extends Toggle {
clicked.setData(false) clicked.setData(false)
}).SetClass(""), }).SetClass(""),
new SubtleButton(Svg.upload_svg(), t.confirm).OnClickWithLoading(t.uploading, async () => { new SubtleButton(Svg.upload_svg(), t.confirm).OnClickWithLoading(t.uploading, async () => {
const titleStr = UploadTraceToOsmUI.createDefault(title.GetValue().data, "Track with mapcomplete")
const descriptionStr = UploadTraceToOsmUI.createDefault(description.GetValue().data, "Track created with MapComplete with theme "+state?.layoutToUse?.id)
await state?.osmConnection?.uploadGpxTrack(trace(title.GetValue().data), { await state?.osmConnection?.uploadGpxTrack(trace(title.GetValue().data), {
visibility: dropdown.GetValue().data, visibility: dropdown.GetValue().data,
description: description.GetValue().data, description: descriptionStr,
filename: title.GetValue().data+".gpx", filename: titleStr +".gpx",
labels: ["MapComplete", state?.layoutToUse?.id] labels: ["MapComplete", state?.layoutToUse?.id]
}) })