feat: Update
This commit is contained in:
@@ -41,6 +41,8 @@ const MapDataContext = createContext<{
|
||||
latitude: number,
|
||||
longitude: number
|
||||
) => void;
|
||||
setIconSize: (size: number) => void;
|
||||
setFontSize: (size: number) => void;
|
||||
saveChanges: () => void;
|
||||
}>({
|
||||
originalRouteData: undefined,
|
||||
@@ -61,6 +63,8 @@ const MapDataContext = createContext<{
|
||||
setStationOffset: () => {},
|
||||
setStationAlign: () => {},
|
||||
setSightCoordinates: () => {},
|
||||
setIconSize: () => {},
|
||||
setFontSize: () => {},
|
||||
saveChanges: () => {},
|
||||
});
|
||||
|
||||
@@ -164,9 +168,57 @@ export const MapDataProvider = observer(
|
||||
});
|
||||
}
|
||||
|
||||
function setMapCenter(x: number, y: number) {
|
||||
function setIconSize(size: number) {
|
||||
const clamped = Math.max(50, Math.min(300, size));
|
||||
setRouteChanges((prev) => {
|
||||
return { ...prev, center_latitude: x, center_longitude: y };
|
||||
if (prev.icon_size === clamped) {
|
||||
return prev;
|
||||
}
|
||||
return { ...prev, icon_size: clamped };
|
||||
});
|
||||
}
|
||||
|
||||
function setFontSize(size: number) {
|
||||
const clamped = Math.max(50, Math.min(300, size));
|
||||
setRouteChanges((prev) => {
|
||||
if (prev.font_size === clamped) {
|
||||
return prev;
|
||||
}
|
||||
return { ...prev, font_size: clamped };
|
||||
});
|
||||
}
|
||||
|
||||
function setMapCenter(latitude: number, longitude: number) {
|
||||
const epsilon = 1e-6;
|
||||
|
||||
setRouteChanges((prev) => {
|
||||
const prevLat = prev.center_latitude;
|
||||
const prevLon = prev.center_longitude;
|
||||
|
||||
if (
|
||||
prevLat !== undefined &&
|
||||
prevLon !== undefined &&
|
||||
Math.abs(prevLat - latitude) < epsilon &&
|
||||
Math.abs(prevLon - longitude) < epsilon
|
||||
) {
|
||||
return prev;
|
||||
}
|
||||
|
||||
return {
|
||||
...prev,
|
||||
center_latitude: latitude,
|
||||
center_longitude: longitude,
|
||||
};
|
||||
});
|
||||
|
||||
setRouteData((routePrev) => {
|
||||
if (!routePrev) return routePrev;
|
||||
|
||||
return {
|
||||
...routePrev,
|
||||
center_latitude: latitude,
|
||||
center_longitude: longitude,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -179,12 +231,42 @@ export const MapDataProvider = observer(
|
||||
async function saveStationChanges() {
|
||||
for (const station of stationChanges) {
|
||||
await authInstance.patch(`/route/${routeId}/station`, station);
|
||||
|
||||
setStationData((prev) => {
|
||||
const updated = { ...prev };
|
||||
Object.keys(updated).forEach((lang) => {
|
||||
updated[lang] = updated[lang].map((s) =>
|
||||
s.id === station.station_id
|
||||
? {
|
||||
...s,
|
||||
offset_x: station.offset_x,
|
||||
offset_y: station.offset_y,
|
||||
}
|
||||
: s
|
||||
);
|
||||
});
|
||||
return updated;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function saveSightChanges() {
|
||||
for (const sight of sightChanges) {
|
||||
await authInstance.patch(`/route/${routeId}/sight`, sight);
|
||||
|
||||
setSightData((prev) =>
|
||||
prev
|
||||
? prev.map((s) =>
|
||||
s.id === sight.sight_id
|
||||
? {
|
||||
...s,
|
||||
latitude: sight.latitude,
|
||||
longitude: sight.longitude,
|
||||
}
|
||||
: s
|
||||
)
|
||||
: prev
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,6 +402,14 @@ export const MapDataProvider = observer(
|
||||
latitude: number,
|
||||
longitude: number
|
||||
) {
|
||||
setSightData((prev) =>
|
||||
prev
|
||||
? prev.map((sight) =>
|
||||
sight.id === sightId ? { ...sight, latitude, longitude } : sight
|
||||
)
|
||||
: prev
|
||||
);
|
||||
|
||||
setSightChanges((prev) => {
|
||||
const existingIndex = prev.findIndex(
|
||||
(sight) => sight.sight_id === sightId
|
||||
@@ -375,6 +465,8 @@ export const MapDataProvider = observer(
|
||||
setStationOffset,
|
||||
setStationAlign,
|
||||
setSightCoordinates,
|
||||
setIconSize,
|
||||
setFontSize,
|
||||
}),
|
||||
[
|
||||
originalRouteData,
|
||||
@@ -387,6 +479,8 @@ export const MapDataProvider = observer(
|
||||
isStationLoading,
|
||||
isSightLoading,
|
||||
selectedSight,
|
||||
setIconSize,
|
||||
setFontSize,
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user