Tweak new note marker, formatting

This commit is contained in:
Pieter Vander Vennet 2022-01-14 02:40:55 +01:00
parent 7903a916e2
commit 85af8a20b0
4 changed files with 74 additions and 27 deletions

View file

@ -192,7 +192,6 @@ export class TagUtils {
} }
const f = (value: string | undefined) => { const f = (value: string | undefined) => {
console.log("Comparing ",value,operator,val)
if(value === undefined){ if(value === undefined){
return false; return false;
} }

View file

@ -26,6 +26,7 @@ import * as home_location_json from "../assets/layers/home_location/home_locatio
import NewNoteUi from "./Popup/NewNoteUi"; import NewNoteUi from "./Popup/NewNoteUi";
import Combine from "./Base/Combine"; import Combine from "./Base/Combine";
import AddNewMarker from "./BigComponents/AddNewMarker"; import AddNewMarker from "./BigComponents/AddNewMarker";
import FilteredLayer from "../Models/FilteredLayer";
/** /**
@ -50,7 +51,7 @@ export default class DefaultGUI {
this.SetupMap() this.SetupMap()
if(state.layoutToUse.customCss !== undefined && window.location.pathname.indexOf("index") >= 0){ if (state.layoutToUse.customCss !== undefined && window.location.pathname.indexOf("index") >= 0) {
Utils.LoadCustomCss(state.layoutToUse.customCss) Utils.LoadCustomCss(state.layoutToUse.customCss)
} }
} }
@ -58,31 +59,28 @@ export default class DefaultGUI {
public setupClickDialogOnMap(filterViewIsOpened: UIEventSource<boolean>, state: FeaturePipelineState) { public setupClickDialogOnMap(filterViewIsOpened: UIEventSource<boolean>, state: FeaturePipelineState) {
const hasPresets = state.layoutToUse.layers.some(layer => layer.presets.length > 0); const hasPresets = state.layoutToUse.layers.some(layer => layer.presets.length > 0);
const noteLayer= state.filteredLayers.data.filter(l => l.layerDef.id === "note")[0] const noteLayer: FilteredLayer = state.filteredLayers.data.filter(l => l.layerDef.id === "note")[0]
let addNewNoteDialog : () => BaseUIElement = undefined; let addNewNoteDialog: (isShown: UIEventSource<boolean>) => BaseUIElement = undefined;
if(noteLayer !== undefined){ const t = Translations.t.notes
addNewNoteDialog = () => new NewNoteUi(state.LastClickLocation, state) if (noteLayer !== undefined) {
addNewNoteDialog = (isShown) => new NewNoteUi(noteLayer, isShown, state)
} }
function setup() { function setup() {
if (!hasPresets && addNewNoteDialog === undefined) {
console.warn("Settuping ")
if(!hasPresets && addNewNoteDialog === undefined){
return; // nothing to do return; // nothing to do
} }
const newPointDialogIsShown = new UIEventSource<boolean>(false); const newPointDialogIsShown = new UIEventSource<boolean>(false);
const addNewPoint = new ScrollableFullScreen( const addNewPoint = new ScrollableFullScreen(
() => hasPresets ? Translations.t.general.add.title : Translations.t.notes.createNoteTitle, () => hasPresets ? Translations.t.general.add.title : Translations.t.notes.createNoteTitle,
() => { () => {
let addNew = undefined; let addNew = undefined;
if(hasPresets){ if (hasPresets) {
addNew = new SimpleAddUI(newPointDialogIsShown, filterViewIsOpened, state); addNew = new SimpleAddUI(newPointDialogIsShown, filterViewIsOpened, state);
} }
let addNote = undefined; let addNote = undefined;
if(noteLayer !== undefined){ if (noteLayer !== undefined) {
addNote = addNewNoteDialog() addNote = addNewNoteDialog(newPointDialogIsShown)
} }
return new Combine([addNew, addNote]).SetClass("flex flex-col font-lg text-lg") return new Combine([addNew, addNote]).SetClass("flex flex-col font-lg text-lg")
}, },
@ -97,16 +95,27 @@ export default class DefaultGUI {
} }
}); });
let noteMarker = undefined;
if(!hasPresets && addNewNoteDialog !== undefined){
noteMarker = new Combine(
[Svg.note_svg().SetClass("absolute bottom-0").SetStyle("height: 40px"),
Svg.addSmall_svg().SetClass("absolute w-6 animate-pulse")
.SetStyle("right: 10px; bottom: -8px;")
])
.SetClass("block relative h-full")
.SetStyle("left: calc( 50% - 15px )") // This is a bit hacky, yes I know!
}
new StrayClickHandler( new StrayClickHandler(
state, state,
addNewPoint, addNewPoint,
hasPresets ? new AddNewMarker(state.filteredLayers) : new Combine([Svg.note_svg().SetStyle("height: 40px"), Svg.addSmall_svg().SetClass("absolute bottom-0 right-0 w-6 animate-pulse")]).SetClass("block relative") hasPresets ? new AddNewMarker(state.filteredLayers) : noteMarker
); );
} }
if(noteLayer !== undefined){ if (noteLayer !== undefined) {
setup() setup()
}else{ } else {
state.featureSwitchAddNew.addCallbackAndRunD(addNewAllowed => { state.featureSwitchAddNew.addCallbackAndRunD(addNewAllowed => {
if (addNewAllowed) { if (addNewAllowed) {
setup() setup()

View file

@ -10,14 +10,20 @@ import {LocalStorageSource} from "../../Logic/Web/LocalStorageSource";
import Toggle from "../Input/Toggle"; import Toggle from "../Input/Toggle";
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig"; import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig";
import FeaturePipeline from "../../Logic/FeatureSource/FeaturePipeline"; import FeaturePipeline from "../../Logic/FeatureSource/FeaturePipeline";
import FilteredLayer from "../../Models/FilteredLayer";
export default class NewNoteUi extends Toggle { export default class NewNoteUi extends Toggle {
constructor(lastClickLocation: UIEventSource<{ lat: number, lon: number }>, constructor(noteLayer: FilteredLayer,
state: { osmConnection: OsmConnection, layoutToUse: LayoutConfig, featurePipeline: FeaturePipeline }) { isShown: UIEventSource<boolean>,
state: {
LastClickLocation: UIEventSource<{ lat: number, lon: number }>,
osmConnection: OsmConnection, layoutToUse: LayoutConfig, featurePipeline: FeaturePipeline
}) {
const t = Translations.t.notes; const t = Translations.t.notes;
const isCreated = new UIEventSource(false); const isCreated = new UIEventSource(false);
state.LastClickLocation.addCallbackAndRun(_ => isCreated.setData(false)) // Reset 'isCreated' on every click
const text = ValidatedTextField.InputForType("text", { const text = ValidatedTextField.InputForType("text", {
value: LocalStorageSource.Get("note-text") value: LocalStorageSource.Get("note-text")
}) })
@ -30,7 +36,7 @@ export default class NewNoteUi extends Toggle {
return; return;
} }
txt += "\n\n #MapComplete #" + state?.layoutToUse?.id txt += "\n\n #MapComplete #" + state?.layoutToUse?.id
const loc = lastClickLocation.data; const loc = state.LastClickLocation.data;
state?.osmConnection?.openNote(loc.lat, loc.lon, txt) state?.osmConnection?.openNote(loc.lat, loc.lon, txt)
text.GetValue().setData("") text.GetValue().setData("")
isCreated.setData(true) isCreated.setData(true)
@ -43,7 +49,7 @@ export default class NewNoteUi extends Toggle {
]).SetClass("flex flex-col border-2 border-black rounded-xl p-4"); ]).SetClass("flex flex-col border-2 border-black rounded-xl p-4");
super( const newNoteUi = new Toggle(
new Toggle(t.isCreated.SetClass("thanks"), new Toggle(t.isCreated.SetClass("thanks"),
createNoteDialog, createNoteDialog,
isCreated isCreated
@ -51,6 +57,35 @@ export default class NewNoteUi extends Toggle {
undefined, undefined,
new UIEventSource<boolean>(true) new UIEventSource<boolean>(true)
) )
super(
new Toggle(
new Combine(
[
t.noteLayerHasFilters.SetClass("alert"),
new SubtleButton(Svg.filter_svg(), t.disableAllNoteFilters).onClick(() => {
const filters = noteLayer.appliedFilters.data;
for (const key of Array.from(filters.keys())) {
filters.set(key, undefined)
}
noteLayer.appliedFilters.ping()
isShown.setData(false);
})
]
).SetClass("flex flex-col"),
newNoteUi,
noteLayer.appliedFilters.map(filters => Array.from(filters.values()).some(v => v !== undefined))
),
new Combine([
t.noteLayerNotEnabled.SetClass("alert"),
new SubtleButton(Svg.layers_svg(), t.noteLayerDoEnable).onClick(() => {
noteLayer.isDisplayed.setData(true);
isShown.setData(false);
})
]).SetClass("flex flex-col"),
noteLayer.isDisplayed
);
} }

View file

@ -448,6 +448,10 @@
"createNoteIntro": "Is something wrong or missing on the map? Create a note here. These will be checked by volunteers", "createNoteIntro": "Is something wrong or missing on the map? Create a note here. These will be checked by volunteers",
"warnAnonymous": "You are not logged in. We won't be able to contact you to resolve your issue.", "warnAnonymous": "You are not logged in. We won't be able to contact you to resolve your issue.",
"notesLayerMustBeEnabled": "The 'notes'-layer is disabled. Enable it to add a note", "notesLayerMustBeEnabled": "The 'notes'-layer is disabled. Enable it to add a note",
"isCreated": "Your note has been created!" "isCreated": "Your note has been created!",
"noteLayerNotEnabled": "The layer showing notes is not enabled. This layer must be enabled to add a new note",
"noteLayerHasFilters": "Some notes might be hidden by a filter",
"disableAllNoteFilters": "Disable all filters",
"noteLayerDoEnable": "Enable the layer showing notes"
} }
} }