demarches-normaliennes/app/javascript/controllers/geo_area_controller.tsx

32 lines
781 B
TypeScript
Raw Normal View History

import { ApplicationController } from './application_controller';
export class GeoAreaController extends ApplicationController {
static values = {
id: Number
};
static targets = ['description'];
declare readonly idValue: number;
declare readonly descriptionTarget: HTMLInputElement;
onFocus() {
this.globalDispatch('map:feature:focus', { id: this.idValue });
}
onClick(event: MouseEvent) {
event.preventDefault();
this.globalDispatch('map:feature:focus', { id: this.idValue });
}
onInput() {
this.debounce(this.updateDescription, 200);
}
private updateDescription(): void {
this.globalDispatch('map:feature:update', {
id: this.idValue,
properties: { description: this.descriptionTarget.value.trim() }
});
}
}