From de137055d3ab58d7a24f551f1edc9bfc56341a83 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Fri, 28 Oct 2022 04:38:10 +0200 Subject: [PATCH] Add default strings if none are given --- UI/BigComponents/UploadTraceToOsmUI.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/UI/BigComponents/UploadTraceToOsmUI.ts b/UI/BigComponents/UploadTraceToOsmUI.ts index 5dae8b786..1fb7c5f40 100644 --- a/UI/BigComponents/UploadTraceToOsmUI.ts +++ b/UI/BigComponents/UploadTraceToOsmUI.ts @@ -15,6 +15,15 @@ import {Translation} from "../i18n/Translation"; 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( trace: (title: string) => string, @@ -76,10 +85,12 @@ export default class UploadTraceToOsmUI extends Toggle { clicked.setData(false) }).SetClass(""), 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), { visibility: dropdown.GetValue().data, - description: description.GetValue().data, - filename: title.GetValue().data+".gpx", + description: descriptionStr, + filename: titleStr +".gpx", labels: ["MapComplete", state?.layoutToUse?.id] }) @@ -104,4 +115,4 @@ export default class UploadTraceToOsmUI extends Toggle { clicked ), uploadFinished) } -} \ No newline at end of file +}