diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 8867836..8586684 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,6 +1,6 @@ import { Fragment, type ChangeEvent as ReactChangeEvent, type ClipboardEvent as ReactClipboardEvent, type Dispatch, type DragEvent as ReactDragEvent, type FormEvent as ReactFormEvent, type KeyboardEvent as ReactKeyboardEvent, type MouseEvent as ReactMouseEvent, type PointerEvent as ReactPointerEvent, type ReactNode, type SetStateAction, type WheelEvent as ReactWheelEvent, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'; import './styles.css'; -import { Link, NavLink, Navigate, Outlet, Route, Routes, useLocation, useNavigate, useParams, useSearchParams } from 'react-router-dom'; +import { Link, NavLink, Route, Routes, useLocation, useNavigate, useNavigationType, useParams, useSearchParams } from 'react-router-dom'; import { ROUTES, listingPath, mapPath, negotiationPath, adminTabPath, ADMIN_PATH_TO_TAB, type AdminTabKey } from './routes'; import { ProtectedRoute } from './ProtectedRoute'; import { apiFetch, useAuth } from './auth'; @@ -2619,6 +2619,7 @@ function App() { const { user, logout } = useAuth(); const navigate = useNavigate(); const location = useLocation(); + const navigationType = useNavigationType(); const [favoriteListingsState, setFavoriteListingsState] = useState(favoriteListings); const [favoritesPreferredTab, setFavoritesPreferredTab] = useState('buy'); const [listingPriceAlertSubscriptionsState, setListingPriceAlertSubscriptionsState] = useState([]); @@ -3365,6 +3366,14 @@ function App() { }; }, [user, monitoredListingIdList, monitoredListingIdsSignature, listingPriceAlertIdList, listingPriceAlertIdsSignature]); + // Wejscie na nowa trase zaczynamy od gory strony. Przy cofaniu (POP) zostawiamy + // pozycje przegladarce, zeby powrot do listy ofert wracal w to samo miejsce. + useEffect(() => { + if (navigationType !== 'POP') { + window.scrollTo({ top: 0, behavior: 'auto' }); + } + }, [location.pathname, navigationType]); + return (
0} onOpenNotification={handleOpenNotification} /> @@ -6897,7 +6906,9 @@ function AccountComparisonPage({ onOpenListing }: { onOpenListing: (id: number) useEffect(() => { if (selectedIds.length === 0) { - setSelectedDetails({}); + // Zachowujemy referencje pustego obiektu - podstawienie nowego {} zmienialoby + // zaleznosc selectedDetails i efekt wpadalby w nieskonczona petle renderow. + setSelectedDetails((current) => (Object.keys(current).length === 0 ? current : {})); return; }