fix: Fix errors
This commit is contained in:
@@ -132,6 +132,7 @@ interface ApiStation {
|
||||
longitude: number;
|
||||
city_id: number;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
interface ApiSight {
|
||||
@@ -142,9 +143,16 @@ interface ApiSight {
|
||||
longitude: number;
|
||||
city_id: number;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export type SortType = "name_asc" | "name_desc" | "date_asc" | "date_desc";
|
||||
export type SortType =
|
||||
| "name_asc"
|
||||
| "name_desc"
|
||||
| "created_asc"
|
||||
| "created_desc"
|
||||
| "updated_asc"
|
||||
| "updated_desc";
|
||||
|
||||
class MapStore {
|
||||
constructor() {
|
||||
@@ -179,7 +187,7 @@ class MapStore {
|
||||
return sorted.sort((a, b) => a.name.localeCompare(b.name));
|
||||
case "name_desc":
|
||||
return sorted.sort((a, b) => b.name.localeCompare(a.name));
|
||||
case "date_asc":
|
||||
case "created_asc":
|
||||
return sorted.sort((a, b) => {
|
||||
if (
|
||||
"created_at" in a &&
|
||||
@@ -195,7 +203,7 @@ class MapStore {
|
||||
// Фоллбэк: сортировка по ID, если дата недоступна
|
||||
return a.id - b.id;
|
||||
});
|
||||
case "date_desc":
|
||||
case "created_desc":
|
||||
return sorted.sort((a, b) => {
|
||||
if (
|
||||
"created_at" in a &&
|
||||
@@ -211,6 +219,32 @@ class MapStore {
|
||||
// Фоллбэк: сортировка по ID, если дата недоступна
|
||||
return b.id - a.id;
|
||||
});
|
||||
case "updated_asc":
|
||||
return sorted.sort((a, b) => {
|
||||
const aUpdated =
|
||||
("updated_at" in a && a.updated_at) ||
|
||||
("created_at" in a && a.created_at);
|
||||
const bUpdated =
|
||||
("updated_at" in b && b.updated_at) ||
|
||||
("created_at" in b && b.created_at);
|
||||
if (typeof aUpdated === "string" && typeof bUpdated === "string") {
|
||||
return new Date(aUpdated).getTime() - new Date(bUpdated).getTime();
|
||||
}
|
||||
return a.id - b.id;
|
||||
});
|
||||
case "updated_desc":
|
||||
return sorted.sort((a, b) => {
|
||||
const aUpdated =
|
||||
("updated_at" in a && a.updated_at) ||
|
||||
("created_at" in a && a.created_at);
|
||||
const bUpdated =
|
||||
("updated_at" in b && b.updated_at) ||
|
||||
("created_at" in b && b.created_at);
|
||||
if (typeof aUpdated === "string" && typeof bUpdated === "string") {
|
||||
return new Date(bUpdated).getTime() - new Date(aUpdated).getTime();
|
||||
}
|
||||
return b.id - a.id;
|
||||
});
|
||||
default:
|
||||
return sorted;
|
||||
}
|
||||
@@ -626,6 +660,7 @@ class MapService {
|
||||
private selectedIds: Set<string | number> = new Set();
|
||||
private onSelectionChange: ((ids: Set<string | number>) => void) | null =
|
||||
null;
|
||||
private isCreating: boolean = false;
|
||||
|
||||
// Styles
|
||||
private defaultStyle: Style;
|
||||
@@ -1397,6 +1432,21 @@ class MapService {
|
||||
const feature = event.feature as Feature<Geometry>;
|
||||
const fType = this.currentDrawingFeatureType;
|
||||
if (!fType) return;
|
||||
|
||||
// Проверяем, не идет ли уже процесс создания
|
||||
if (this.isCreating) {
|
||||
toast.warning("Дождитесь завершения создания предыдущего объекта.");
|
||||
// Удаляем созданный объект из источника
|
||||
const sourceForDrawing =
|
||||
type === "Point" ? this.pointSource : this.lineSource;
|
||||
setTimeout(() => {
|
||||
if (sourceForDrawing.hasFeature(feature as any)) {
|
||||
sourceForDrawing.removeFeature(feature as any);
|
||||
}
|
||||
}, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
feature.set("featureType", fType);
|
||||
|
||||
let resourceName: string;
|
||||
@@ -1483,6 +1533,13 @@ class MapService {
|
||||
|
||||
public finishDrawing(): void {
|
||||
if (!this.currentInteraction) return;
|
||||
|
||||
// Блокируем завершение рисования, если идет процесс создания
|
||||
if (this.isCreating) {
|
||||
toast.warning("Дождитесь завершения создания предыдущего объекта.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
this.currentInteraction.finishDrawing();
|
||||
} catch (e) {
|
||||
@@ -1830,6 +1887,22 @@ class MapService {
|
||||
const featureType = feature.get("featureType") as FeatureType;
|
||||
if (!featureType || !this.map) return;
|
||||
|
||||
// Проверяем, не идет ли уже процесс создания
|
||||
if (this.isCreating) {
|
||||
toast.warning("Дождитесь завершения создания предыдущего объекта.");
|
||||
// Удаляем незавершенный объект с карты
|
||||
if (feature.getGeometry()?.getType() === "LineString") {
|
||||
if (this.lineSource.hasFeature(feature as Feature<LineString>))
|
||||
this.lineSource.removeFeature(feature as Feature<LineString>);
|
||||
} else {
|
||||
if (this.pointSource.hasFeature(feature as Feature<Point>))
|
||||
this.pointSource.removeFeature(feature as Feature<Point>);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
this.isCreating = true;
|
||||
|
||||
const geoJSONFormat = new GeoJSON({
|
||||
dataProjection: "EPSG:4326",
|
||||
featureProjection: this.map.getView().getProjection().getCode(),
|
||||
@@ -1890,6 +1963,8 @@ class MapService {
|
||||
if (this.pointSource.hasFeature(feature as Feature<Point>))
|
||||
this.pointSource.removeFeature(feature as Feature<Point>);
|
||||
}
|
||||
} finally {
|
||||
this.isCreating = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2153,7 +2228,7 @@ const MapSightbar: React.FC<MapSightbarProps> = observer(
|
||||
(a.get("name") as string) || ""
|
||||
)
|
||||
);
|
||||
case "date_asc":
|
||||
case "created_asc":
|
||||
return sorted.sort((a, b) => {
|
||||
const aDate = a.get("created_at")
|
||||
? new Date(a.get("created_at"))
|
||||
@@ -2163,7 +2238,7 @@ const MapSightbar: React.FC<MapSightbarProps> = observer(
|
||||
: new Date(0);
|
||||
return aDate.getTime() - bDate.getTime();
|
||||
});
|
||||
case "date_desc":
|
||||
case "created_desc":
|
||||
return sorted.sort((a, b) => {
|
||||
const aDate = a.get("created_at")
|
||||
? new Date(a.get("created_at"))
|
||||
@@ -2173,6 +2248,34 @@ const MapSightbar: React.FC<MapSightbarProps> = observer(
|
||||
: new Date(0);
|
||||
return bDate.getTime() - aDate.getTime();
|
||||
});
|
||||
case "updated_asc":
|
||||
return sorted.sort((a, b) => {
|
||||
const aDate = a.get("updated_at")
|
||||
? new Date(a.get("updated_at"))
|
||||
: a.get("created_at")
|
||||
? new Date(a.get("created_at"))
|
||||
: new Date(0);
|
||||
const bDate = b.get("updated_at")
|
||||
? new Date(b.get("updated_at"))
|
||||
: b.get("created_at")
|
||||
? new Date(b.get("created_at"))
|
||||
: new Date(0);
|
||||
return aDate.getTime() - bDate.getTime();
|
||||
});
|
||||
case "updated_desc":
|
||||
return sorted.sort((a, b) => {
|
||||
const aDate = a.get("updated_at")
|
||||
? new Date(a.get("updated_at"))
|
||||
: a.get("created_at")
|
||||
? new Date(a.get("created_at"))
|
||||
: new Date(0);
|
||||
const bDate = b.get("updated_at")
|
||||
? new Date(b.get("updated_at"))
|
||||
: b.get("created_at")
|
||||
? new Date(b.get("created_at"))
|
||||
: new Date(0);
|
||||
return bDate.getTime() - aDate.getTime();
|
||||
});
|
||||
default:
|
||||
return sorted;
|
||||
}
|
||||
@@ -2305,6 +2408,10 @@ const MapSightbar: React.FC<MapSightbarProps> = observer(
|
||||
>
|
||||
<option value="name_asc">Имя ↑</option>
|
||||
<option value="name_desc">Имя ↓</option>
|
||||
<option value="created_asc">Дата создания ↑</option>
|
||||
<option value="created_desc">Дата создания ↓</option>
|
||||
<option value="updated_asc">Дата обновления ↑</option>
|
||||
<option value="updated_desc">Дата обновления ↓</option>
|
||||
</select>
|
||||
</div>
|
||||
),
|
||||
@@ -2333,6 +2440,10 @@ const MapSightbar: React.FC<MapSightbarProps> = observer(
|
||||
>
|
||||
<option value="name_asc">Имя ↑</option>
|
||||
<option value="name_desc">Имя ↓</option>
|
||||
<option value="created_asc">Дата создания ↑</option>
|
||||
<option value="created_desc">Дата создания ↓</option>
|
||||
<option value="updated_asc">Дата обновления ↑</option>
|
||||
<option value="updated_desc">Дата обновления ↓</option>
|
||||
</select>
|
||||
</div>
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user