import { Box, Tab, Tabs } from "@mui/material"; import { InformationTab, LeaveAgree, RightWidgetTab } from "@widgets"; import { LeftWidgetTab } from "@widgets"; import { useEffect, useState } from "react"; import { observer } from "mobx-react-lite"; import { articlesStore, authStore, cityStore, editSightStore, LoadingSpinner, selectedCityStore, } from "@shared"; import { useBlocker, useParams } from "react-router-dom"; function a11yProps(index: number) { return { id: `sight-tab-${index}`, "aria-controls": `sight-tabpanel-${index}`, }; } export const EditSightPage = observer(() => { const [value, setValue] = useState(0); const [isLoadingData, setIsLoadingData] = useState(true); const { sight, getSightInfo, needLeaveAgree, getRightArticles } = editSightStore; const { getArticles } = articlesStore; useEffect(() => { selectedCityStore.setIsLocked(true); return () => selectedCityStore.setIsLocked(false); }, []); const { id } = useParams(); const { getCities } = cityStore; let blocker = useBlocker( ({ currentLocation, nextLocation }) => needLeaveAgree && currentLocation.pathname !== nextLocation.pathname ); const handleChange = (_: React.SyntheticEvent, newValue: number) => { setValue(newValue); }; useEffect(() => { const fetchData = async () => { if (id) { setIsLoadingData(true); try { if (!authStore.me) { await authStore.getMeAction().catch(() => undefined); } if (authStore.canRead("cities")) { await getCities("ru"); } else { await authStore.fetchMeCities().catch(() => undefined); } await getSightInfo(+id, "ru"); await getSightInfo(+id, "en"); await getSightInfo(+id, "zh"); await getArticles("ru"); await getArticles("en"); await getArticles("zh"); // Загружаем данные правого виджета перед завершением загрузки await getRightArticles(+id); } finally { setIsLoadingData(false); } } else { setIsLoadingData(false); } }; fetchData(); }, [id]); return ( {isLoadingData ? ( ) : ( sight.common.id !== 0 && (
) )} {blocker.state === "blocked" ? : null}
); });