Skip to content

Commit d8d3192

Browse files
committed
chore: restrict area replacing
1 parent 623b824 commit d8d3192

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/lib/region/form.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,7 @@ const editRegion = form.params<{ region: Region; displayName: boolean }>(
213213
noI18n`Заменить зону`,
214214
selectArea({
215215
title: noI18n`Заменить зону`,
216-
onSelect: area => {
217-
// Area changed, need to update chunk query storages too
218-
Region.chunkQuery.remove(region)
219-
region.area = area
220-
region.save()
221-
Region.chunkQuery.add(region)
222-
223-
return self
224-
},
216+
onSelect: area => (region.replaceArea(area), self),
225217
}),
226218
)
227219

src/lib/region/kinds/region.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,19 @@ export class Region {
211211
* @param o.key - The key of the region. This is used to identify the region.
212212
*/
213213
constructor(
214-
public area: Area,
214+
readonly area: Area,
215215
options: RegionCreationOptions,
216216
readonly id: string,
217217
) {}
218218

219+
public replaceArea(newArea: Area) {
220+
// Area changed, need to update chunk query storages too
221+
Region.chunkQuery.remove(this)
222+
;(this as { area: Area }).area = newArea
223+
this.save()
224+
Region.chunkQuery.add(this)
225+
}
226+
219227
/** Function that gets called on region creation after saving (once) */
220228
protected onCreate() {
221229
// Hook

0 commit comments

Comments
 (0)