diff --git a/src/pages/Route/LinekedStations.tsx b/src/pages/Route/LinekedStations.tsx index 03da037..edb0926 100644 --- a/src/pages/Route/LinekedStations.tsx +++ b/src/pages/Route/LinekedStations.tsx @@ -24,6 +24,7 @@ import { Tab, Box, } from "@mui/material"; +import { observer } from "mobx-react-lite"; import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; import DragIndicatorIcon from "@mui/icons-material/DragIndicator"; import { @@ -33,7 +34,12 @@ import { DropResult, } from "@hello-pangea/dnd"; -import { authInstance, languageStore, routeStore } from "@shared"; +import { + authInstance, + languageStore, + routeStore, + selectedCityStore, +} from "@shared"; import { EditStationModal } from "../../widgets/modals/EditStationModal"; // Helper function to insert an item at a specific position (1-based index) @@ -73,7 +79,6 @@ type LinkedItemsProps = { disableCreation?: boolean; updatedLinkedItems?: T[]; refresh?: number; - cityId?: number; routeDirection?: boolean; }; @@ -112,7 +117,7 @@ export const LinkedItems = < ); }; -export const LinkedItemsContents = < +const LinkedItemsContentsInner = < T extends { id: number; name: string; [key: string]: any } >({ parentId, @@ -124,7 +129,6 @@ export const LinkedItemsContents = < disableCreation = false, updatedLinkedItems, refresh, - cityId, routeDirection, }: LinkedItemsProps) => { const { language } = languageStore; @@ -153,17 +157,20 @@ export const LinkedItemsContents = < // Фильтруем станции по направлению маршрута return item.direction === routeDirection; }) + .filter((item) => { + // Фильтруем по городу из навбара + const selectedCityId = selectedCityStore.selectedCityId; + if (selectedCityId && "city_id" in item) { + return item.city_id === selectedCityId; + } + return true; + }) .sort((a, b) => a.name.localeCompare(b.name)); // Фильтрация по поиску для массового режима const filteredAvailableItems = availableItems.filter((item) => { - if (!cityId || item.city_id == cityId) { - if (!searchQuery.trim()) return true; - return String(item.name) - .toLowerCase() - .includes(searchQuery.toLowerCase()); - } - return false; + if (!searchQuery.trim()) return true; + return String(item.name).toLowerCase().includes(searchQuery.toLowerCase()); }); useEffect(() => { @@ -460,9 +467,7 @@ export const LinkedItemsContents = < onChange={(_, newValue) => setSelectedItemId(newValue?.id || null) } - options={availableItems.filter( - (item) => !cityId || item.city_id == cityId - )} + options={availableItems} getOptionLabel={(item) => String(item.name)} renderInput={(params) => ( ); }; + +export const LinkedItemsContents = observer( + LinkedItemsContentsInner +) as typeof LinkedItemsContentsInner; diff --git a/src/pages/Station/LinkedSights.tsx b/src/pages/Station/LinkedSights.tsx index 74b79f2..584eeda 100644 --- a/src/pages/Station/LinkedSights.tsx +++ b/src/pages/Station/LinkedSights.tsx @@ -17,9 +17,10 @@ import { Paper, TableBody, } from "@mui/material"; +import { observer } from "mobx-react-lite"; import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; -import { authInstance, languageStore } from "@shared"; +import { authInstance, languageStore, selectedCityStore } from "@shared"; type Field = { label: string; @@ -73,7 +74,7 @@ export const LinkedSights = < ); }; -export const LinkedSightsContents = < +const LinkedSightsContentsInner = < T extends { id: number; name: string; [key: string]: any } >({ parentId, @@ -100,6 +101,14 @@ export const LinkedSightsContents = < const availableItems = allItems .filter((item) => !linkedItems.some((linked) => linked.id === item.id)) + .filter((item) => { + // Фильтруем по городу из навбара + const selectedCityId = selectedCityStore.selectedCityId; + if (selectedCityId && "city_id" in item) { + return item.city_id === selectedCityId; + } + return true; + }) .sort((a, b) => a.name.localeCompare(b.name)); useEffect(() => { @@ -313,3 +322,7 @@ export const LinkedSightsContents = < ); }; + +export const LinkedSightsContents = observer( + LinkedSightsContentsInner +) as typeof LinkedSightsContentsInner; diff --git a/src/pages/Station/StationEditPage/index.tsx b/src/pages/Station/StationEditPage/index.tsx index 7acec9b..03ba50e 100644 --- a/src/pages/Station/StationEditPage/index.tsx +++ b/src/pages/Station/StationEditPage/index.tsx @@ -68,7 +68,10 @@ export const StationEditPage = observer(() => { const handleEdit = async () => { const isCityMissing = !editStationData.common.city_id; // Проверяем названия на всех языках - const isNameMissing = !editStationData.ru.name || !editStationData.en.name || !editStationData.zh.name; + const isNameMissing = + !editStationData.ru.name || + !editStationData.en.name || + !editStationData.zh.name; if (isCityMissing || isNameMissing) { setIsSaveWarningOpen(true); @@ -106,6 +109,7 @@ export const StationEditPage = observer(() => { return ( +