forked from MapComplete/MapComplete
More refactoring and fixes
This commit is contained in:
parent
1bc7d9118a
commit
9877abec17
14 changed files with 375 additions and 151 deletions
|
@ -1,4 +1,4 @@
|
|||
import {Store, UIEventSource} from "../../Logic/UIEventSource";
|
||||
import {ImmutableStore, Store} from "../../Logic/UIEventSource";
|
||||
import Translations from "../i18n/Translations";
|
||||
import {OsmConnection} from "../../Logic/Osm/OsmConnection";
|
||||
import Toggle from "../Input/Toggle";
|
||||
|
@ -29,7 +29,7 @@ export class SaveButton extends Toggle {
|
|||
super(
|
||||
save,
|
||||
pleaseLogin,
|
||||
osmConnection?.isLoggedIn ?? new UIEventSource<any>(false)
|
||||
osmConnection?.isLoggedIn ?? new ImmutableStore(false)
|
||||
)
|
||||
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ export default class TagRenderingQuestion extends Combine {
|
|||
|
||||
constructor(tags: UIEventSource<any>,
|
||||
configuration: TagRenderingConfig,
|
||||
state,
|
||||
state?: FeaturePipelineState,
|
||||
options?: {
|
||||
units?: Unit[],
|
||||
afterSave?: () => void,
|
||||
|
@ -50,7 +50,6 @@ export default class TagRenderingQuestion extends Combine {
|
|||
}
|
||||
) {
|
||||
|
||||
|
||||
const applicableMappingsSrc =
|
||||
Stores.ListStabilized(tags.map(tags => {
|
||||
const applicableMappings: { if: TagsFilter, icon?: string, then: TypedTranslation<object>, ifnot?: TagsFilter, addExtraTags: Tag[] }[] = []
|
||||
|
@ -82,12 +81,11 @@ export default class TagRenderingQuestion extends Combine {
|
|||
|
||||
const feedback = new UIEventSource<Translation>(undefined)
|
||||
const inputElement: ReadonlyInputElement<TagsFilter> =
|
||||
new VariableInputElement(applicableMappingsSrc.map(applicableMappings =>
|
||||
TagRenderingQuestion.GenerateInputElement(state, configuration, applicableMappings, applicableUnit, tags, feedback)
|
||||
new VariableInputElement(applicableMappingsSrc.map(applicableMappings => {
|
||||
return TagRenderingQuestion.GenerateInputElement(state, configuration, applicableMappings, applicableUnit, tags, feedback)
|
||||
}
|
||||
))
|
||||
|
||||
|
||||
|
||||
const save = () => {
|
||||
const selection = inputElement.GetValue().data;
|
||||
if (selection) {
|
||||
|
@ -132,7 +130,7 @@ export default class TagRenderingQuestion extends Combine {
|
|||
saveButton]).SetClass("flex justify-end flex-wrap-reverse")
|
||||
|
||||
]).SetClass("flex mt-2 justify-between"),
|
||||
new Toggle(Translations.t.general.testing.SetClass("alert"), undefined, state.featureSwitchIsTesting)
|
||||
new Toggle(Translations.t.general.testing.SetClass("alert"), undefined, state?.featureSwitchIsTesting)
|
||||
])
|
||||
|
||||
|
||||
|
@ -141,17 +139,16 @@ export default class TagRenderingQuestion extends Combine {
|
|||
|
||||
|
||||
private static GenerateInputElement(
|
||||
state,
|
||||
state: FeaturePipelineState,
|
||||
configuration: TagRenderingConfig,
|
||||
applicableMappings: { if: TagsFilter, then: TypedTranslation<object>, icon?: string, ifnot?: TagsFilter, addExtraTags: Tag[] }[],
|
||||
applicableUnit: Unit,
|
||||
tagsSource: UIEventSource<any>,
|
||||
feedback: UIEventSource<Translation>
|
||||
): InputElement<TagsFilter> {
|
||||
): ReadonlyInputElement<TagsFilter> {
|
||||
|
||||
// FreeForm input will be undefined if not present; will already contain a special input element if applicable
|
||||
const ff = TagRenderingQuestion.GenerateFreeform(state, configuration, applicableUnit, tagsSource, feedback);
|
||||
|
||||
|
||||
const hasImages = applicableMappings.findIndex(mapping => mapping.icon !== undefined) >= 0
|
||||
let inputEls: InputElement<TagsFilter>[];
|
||||
|
@ -370,7 +367,7 @@ export default class TagRenderingQuestion extends Combine {
|
|||
return new Combine([new Img(mapping.icon).SetClass("mapping-icon-"+(mapping.iconClass ?? "small")), text]).SetClass("flex")
|
||||
}
|
||||
|
||||
private static GenerateFreeform(state, configuration: TagRenderingConfig, applicableUnit: Unit, tags: UIEventSource<any>, feedback: UIEventSource<Translation>)
|
||||
private static GenerateFreeform(state: FeaturePipelineState, configuration: TagRenderingConfig, applicableUnit: Unit, tags: UIEventSource<any>, feedback: UIEventSource<Translation>)
|
||||
: InputElement<TagsFilter> {
|
||||
const freeform = configuration.freeform;
|
||||
if (freeform === undefined) {
|
||||
|
@ -414,12 +411,12 @@ export default class TagRenderingQuestion extends Combine {
|
|||
}
|
||||
|
||||
const tagsData = tags.data;
|
||||
const feature = state.allElements.ContainingFeatures.get(tagsData.id)
|
||||
const center = GeoOperations.centerpointCoordinates(feature)
|
||||
const feature = state?.allElements?.ContainingFeatures?.get(tagsData.id)
|
||||
const center = feature != undefined ? GeoOperations.centerpointCoordinates(feature) : [0,0]
|
||||
const input: InputElement<string> = ValidatedTextField.ForType(configuration.freeform.type).ConstructInputElement({
|
||||
country: () => tagsData._country,
|
||||
location: [center[1], center[0]],
|
||||
mapBackgroundLayer: state.backgroundLayer,
|
||||
mapBackgroundLayer: state?.backgroundLayer,
|
||||
unit: applicableUnit,
|
||||
args: configuration.freeform.helperArgs,
|
||||
feature,
|
||||
|
@ -427,10 +424,12 @@ export default class TagRenderingQuestion extends Combine {
|
|||
feedback
|
||||
});
|
||||
|
||||
// Init with correct value
|
||||
input.GetValue().setData(tagsData[freeform.key] ?? freeform.default);
|
||||
|
||||
input.GetValue().addCallbackD(v => {
|
||||
if(v.length >= 255){
|
||||
// Add a length check
|
||||
input.GetValue().addCallbackD((v : string | undefined) => {
|
||||
if(v?.length >= 255){
|
||||
feedback.setData(Translations.t.validation.tooLong.Subs({count: v.length}))
|
||||
}
|
||||
})
|
||||
|
@ -441,11 +440,9 @@ export default class TagRenderingQuestion extends Combine {
|
|||
);
|
||||
|
||||
if (freeform.inline) {
|
||||
|
||||
inputTagsFilter.SetClass("w-48-imp")
|
||||
inputTagsFilter = new InputElementWrapper(inputTagsFilter, configuration.render, freeform.key, tags, state)
|
||||
inputTagsFilter.SetClass("block")
|
||||
|
||||
}
|
||||
|
||||
return inputTagsFilter;
|
||||
|
@ -470,7 +467,8 @@ export default class TagRenderingQuestion extends Combine {
|
|||
return new FixedUiElement(tagsStr).SetClass("subtle");
|
||||
}
|
||||
return tagsFilter.asHumanString(true, true, tags.data);
|
||||
}
|
||||
},
|
||||
[state?.osmConnection?.userDetails]
|
||||
)
|
||||
).SetClass("block break-all")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue