mirror of
https://github.com/zadam/trilium.git
synced 2026-01-06 06:34:25 +01:00
refactor(geomap): simplify changing state
This commit is contained in:
parent
be4ee4c173
commit
dc7dd51913
@ -96,7 +96,7 @@ enum State {
|
|||||||
export default class GeoMapTypeWidget extends TypeWidget {
|
export default class GeoMapTypeWidget extends TypeWidget {
|
||||||
|
|
||||||
private geoMapWidget: GeoMapWidget;
|
private geoMapWidget: GeoMapWidget;
|
||||||
private state: State;
|
private _state: State;
|
||||||
private L!: Leaflet;
|
private L!: Leaflet;
|
||||||
private currentMarkerData: MarkerData;
|
private currentMarkerData: MarkerData;
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ export default class GeoMapTypeWidget extends TypeWidget {
|
|||||||
|
|
||||||
this.geoMapWidget = new GeoMapWidget("type", (L: Leaflet) => this.#onMapInitialized(L));
|
this.geoMapWidget = new GeoMapWidget("type", (L: Leaflet) => this.#onMapInitialized(L));
|
||||||
this.currentMarkerData = {};
|
this.currentMarkerData = {};
|
||||||
this.state = State.Normal;
|
this._state = State.Normal;
|
||||||
|
|
||||||
this.child(this.geoMapWidget);
|
this.child(this.geoMapWidget);
|
||||||
}
|
}
|
||||||
@ -202,12 +202,13 @@ export default class GeoMapTypeWidget extends TypeWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#adjustCursor() {
|
#changeState(newState: State) {
|
||||||
this.geoMapWidget.$container.toggleClass("placing-note", this.state === State.NewNote);
|
this._state = newState;
|
||||||
|
this.geoMapWidget.$container.toggleClass("placing-note", newState === State.NewNote);
|
||||||
}
|
}
|
||||||
|
|
||||||
async #onMapClicked(e: LeafletMouseEvent) {
|
async #onMapClicked(e: LeafletMouseEvent) {
|
||||||
if (this.state !== State.NewNote) {
|
if (this._state !== State.NewNote) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,8 +224,7 @@ export default class GeoMapTypeWidget extends TypeWidget {
|
|||||||
this.moveMarker(note.noteId, e.latlng);
|
this.moveMarker(note.noteId, e.latlng);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.state = State.Normal;
|
this.#changeState(State.Normal);
|
||||||
this.#adjustCursor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async moveMarker(noteId: string, latLng: LatLng) {
|
async moveMarker(noteId: string, latLng: LatLng) {
|
||||||
@ -256,12 +256,10 @@ export default class GeoMapTypeWidget extends TypeWidget {
|
|||||||
|
|
||||||
toastService.showMessage(t("relation_map.click_on_canvas_to_place_new_note"));
|
toastService.showMessage(t("relation_map.click_on_canvas_to_place_new_note"));
|
||||||
|
|
||||||
this.state = State.NewNote;
|
this.#changeState(State.NewNote);
|
||||||
this.#adjustCursor();
|
|
||||||
|
|
||||||
const globalKeyListener: (this: Window, ev: KeyboardEvent) => any = (e) => {
|
const globalKeyListener: (this: Window, ev: KeyboardEvent) => any = (e) => {
|
||||||
this.state = State.Normal;
|
this.#changeState(State.Normal);
|
||||||
this.#adjustCursor();
|
|
||||||
|
|
||||||
window.removeEventListener("keydown", globalKeyListener);
|
window.removeEventListener("keydown", globalKeyListener);
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user