fixed desktop version
This commit is contained in:
@@ -18,6 +18,8 @@ import CityQuickFilterLegacy from "../components/feed/CityQuickFilter";
|
||||
import FeedContent from "../components/feed/FeedContent";
|
||||
import PullToRefresh from "../components/feed/PullToRefresh";
|
||||
import MapView from "../components/MapView";
|
||||
import DesktopFeedHeaderLegacy from "../components/desktop/DesktopFeedHeader";
|
||||
import DesktopMapViewLegacy from "../components/desktop/DesktopMapView";
|
||||
import PostDetailModal from "../components/PostDetailModal";
|
||||
import { useAuthContext } from "../context/AuthContext";
|
||||
import { useCities } from "../hooks/useCities";
|
||||
@@ -42,6 +44,8 @@ import type { ComponentType } from "react";
|
||||
const CityFilter = CityFilterLegacy as unknown as ComponentType<any>;
|
||||
const CityQuickFilter = CityQuickFilterLegacy as unknown as ComponentType<any>;
|
||||
const CreateUpdatePost = CreateUpdatePostLegacy as unknown as ComponentType<any>;
|
||||
const DesktopFeedHeader = DesktopFeedHeaderLegacy as unknown as ComponentType<any>;
|
||||
const DesktopMapView = DesktopMapViewLegacy as unknown as ComponentType<any>;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
type AnyAds = any[];
|
||||
@@ -198,6 +202,21 @@ export default function MainFeed() {
|
||||
}
|
||||
}, [location.state]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
// Десктопная навигация с других страниц (чаты, отзывы): раздел ленты
|
||||
// или сразу форма создания объявления.
|
||||
useEffect(() => {
|
||||
const state = location.state as { desktopNav?: string; desktopAction?: string } | null;
|
||||
if (!state?.desktopNav && !state?.desktopAction) return;
|
||||
if (state.desktopNav && ["home", "items", "pets", "myads"].includes(state.desktopNav)) {
|
||||
setActiveNav(state.desktopNav);
|
||||
}
|
||||
if (state.desktopAction === "create") {
|
||||
if (isAuthenticated) modals.open("create");
|
||||
else modals.open("auth");
|
||||
}
|
||||
navigate(`${location.pathname}${location.search}`, { replace: true, state: null });
|
||||
}, [location.state]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
// При загрузке приложения подтягиваем свежие данные профиля (аватар и т.д.)
|
||||
// с бэка, чтобы нижняя навигация и профиль отражали изменения с других
|
||||
// устройств, а не устаревший кэш контекста. Дергаем один раз на пользователя.
|
||||
@@ -226,6 +245,9 @@ export default function MainFeed() {
|
||||
// вкладки (вещи/питомцы) и фильтра «потеря/находка» — их применяет сервер.
|
||||
useEffect(() => {
|
||||
if (activeNav === "myads" || activeNav === "map") return;
|
||||
// На десктопе поиск и фильтры живут прямо в ленте — загрузкой занимается
|
||||
// отдельный эффект ниже (desktopLoadKeyRef), здесь запрос не дублируем.
|
||||
if (isDesktop && !isSearchView) return;
|
||||
if (!isSearchView && selectedCities.length === 0 && !searchQuery.trim()) {
|
||||
feed.loadFeed(0, "", false, feedFilters);
|
||||
}
|
||||
@@ -244,6 +266,28 @@ export default function MainFeed() {
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [searchQuery, feedFiltersKey, isSearchView]);
|
||||
|
||||
// Десктоп: поиск и города всегда в шапке ленты (без отдельной вкладки
|
||||
// «Поиск»), поэтому текст/города/фильтры применяются сразу, текст — с
|
||||
// дебаунсом. Ключ последней загрузки не даёт перезапрашивать ленту при
|
||||
// возврате с карты, если фильтры не менялись.
|
||||
const desktopLoadKeyRef = useRef<string | null>(null);
|
||||
useEffect(() => {
|
||||
if (!isDesktop || isSearchView) {
|
||||
desktopLoadKeyRef.current = null;
|
||||
return;
|
||||
}
|
||||
if (activeNav === "myads" || activeNav === "map") return;
|
||||
const q = searchQuery.trim();
|
||||
const key = `${q}|${feedFiltersKey}`;
|
||||
if (key === desktopLoadKeyRef.current) return;
|
||||
const timer = setTimeout(() => {
|
||||
desktopLoadKeyRef.current = key;
|
||||
feed.loadFeed(0, q, false, feedFilters);
|
||||
}, q ? 400 : 0);
|
||||
return () => clearTimeout(timer);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [isDesktop, isSearchView, searchQuery, feedFiltersKey, activeNav]);
|
||||
|
||||
// Когда переключаемся на «Мои объявления» — подгружаем с бэкенда
|
||||
useEffect(() => {
|
||||
if (activeNav === "myads" && isAuthenticated && user?.id) {
|
||||
@@ -442,11 +486,27 @@ export default function MainFeed() {
|
||||
onReviewsClick={() => navigate("/reviews")}
|
||||
onCreatePost={handleCreatePost}
|
||||
onProfileClick={() => modals.open("profile")}
|
||||
onMapClick={handleMapClick}
|
||||
profileData={profileData}
|
||||
/>
|
||||
|
||||
<div className="f-main f-main-feed">
|
||||
{/* Шапка поиска: на мобильном сворачивается при скролле вниз (grid 1fr → 0fr) */}
|
||||
{isDesktop ? (!isMapView && (
|
||||
<DesktopFeedHeader
|
||||
activeNav={activeNav}
|
||||
typeFilter={typeFilter}
|
||||
onTypeFilterChange={setTypeFilter}
|
||||
searchQuery={searchQuery}
|
||||
onSearchChange={setSearchQuery}
|
||||
cities={cities}
|
||||
selectedCities={selectedCities}
|
||||
onCitiesChange={setSelectedCities}
|
||||
count={filteredAds.length}
|
||||
loading={listLoading}
|
||||
onMapClick={handleMapClick}
|
||||
/>
|
||||
)) : (
|
||||
/* Шапка поиска: на мобильном сворачивается при скролле вниз (grid 1fr → 0fr) */
|
||||
<div className={`f-search-head${searchHeadHidden ? " is-hidden" : ""}`}>
|
||||
<div className="f-search-head-inner">
|
||||
{isSearchView && (
|
||||
@@ -471,9 +531,17 @@ export default function MainFeed() {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="f-wrap">
|
||||
{isMapView ? (
|
||||
{isMapView && isDesktop ? (
|
||||
<DesktopMapView
|
||||
focusPostId={focusPostId}
|
||||
focusLat={focusLat}
|
||||
focusLng={focusLng}
|
||||
onPostClick={handleMapPostClick}
|
||||
/>
|
||||
) : isMapView ? (
|
||||
<MapView
|
||||
focusPostId={focusPostId}
|
||||
focusLat={focusLat}
|
||||
@@ -498,6 +566,26 @@ export default function MainFeed() {
|
||||
onRefresh={refreshCurrentList}
|
||||
disabled={isMapView || isSearchView || !["home", "items", "pets", "myads"].includes(activeNav)}
|
||||
/>
|
||||
{isDesktop ? (
|
||||
<div className="fd-grid">
|
||||
<FeedContent
|
||||
loading={listLoading}
|
||||
citySearchActive={selectedCities.length > 0}
|
||||
error={listError}
|
||||
filteredAds={filteredAds}
|
||||
activeNav={activeNav}
|
||||
searchPrompt={searchPrompt}
|
||||
showAds={showAds}
|
||||
onEdit={handleEdit}
|
||||
onDelete={actions.handleDelete}
|
||||
onMarkFound={actions.handleMarkFound}
|
||||
onReopen={actions.handleReopen}
|
||||
onLocationClick={handleLocationClick}
|
||||
onAuthRequired={() => modals.open("auth")}
|
||||
t={t}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<FeedContent
|
||||
loading={listLoading}
|
||||
citySearchActive={selectedCities.length > 0}
|
||||
@@ -514,6 +602,7 @@ export default function MainFeed() {
|
||||
onAuthRequired={() => modals.open("auth")}
|
||||
t={t}
|
||||
/>
|
||||
)}
|
||||
{infiniteFeed && !feed.loading && (
|
||||
<div ref={sentinelRef} style={{ height: "1px" }} />
|
||||
)}
|
||||
@@ -544,6 +633,11 @@ export default function MainFeed() {
|
||||
setSelectedCities([]);
|
||||
if (isMapView || isSearchView) navigate("/feed");
|
||||
}}
|
||||
onCreatePost={handleCreatePost}
|
||||
onMapClick={handleMapClick}
|
||||
onPostClick={(postId: number) => modals.open("postDetail", { postId })}
|
||||
onRulesClick={() => modals.open("rules")}
|
||||
onReviewsClick={() => navigate("/reviews")}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user