fixed search page
This commit is contained in:
@@ -7,6 +7,7 @@ export default function FeedContent({
|
||||
error,
|
||||
filteredAds,
|
||||
activeNav,
|
||||
searchPrompt,
|
||||
liked,
|
||||
likeCountAdj,
|
||||
onLike,
|
||||
@@ -38,6 +39,16 @@ export default function FeedContent({
|
||||
);
|
||||
}
|
||||
|
||||
if (searchPrompt) {
|
||||
return (
|
||||
<div className="f-center">
|
||||
<div className="f-center-icon">🔍</div>
|
||||
<div className="f-center-title">{t('feed.searchPromptTitle')}</div>
|
||||
<div className="f-center-sub">{t('feed.searchPromptSub')}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!filteredAds.length) {
|
||||
const emptyMsg = activeNav === "myads"
|
||||
? { title: t('feed.emptyMyAdsTitle'), sub: t('feed.emptyMyAdsSub') }
|
||||
|
||||
@@ -8,7 +8,7 @@ const PAGE_SIZE = 20;
|
||||
*/
|
||||
export function useFeedPosts() {
|
||||
const [ads, setAds] = useState([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
const [page, setPage] = useState(0);
|
||||
const [hasMore, setHasMore] = useState(true);
|
||||
|
||||
@@ -127,6 +127,8 @@
|
||||
"emptyMyAdsSub": "Create your first one — click the button above",
|
||||
"emptyAllTitle": "No ads yet",
|
||||
"emptyAllSub": "Be the first — post an ad<br />about a loss or find",
|
||||
"searchPromptTitle": "Enter search parameters",
|
||||
"searchPromptSub": "Type a name or select a city to find an ad",
|
||||
"createPost": "Create ad",
|
||||
"login": "Log in",
|
||||
"searchPlaceholder": "Search by title or description...",
|
||||
|
||||
@@ -128,6 +128,8 @@
|
||||
"emptyMyAdsSub": "Создайте первое — нажмите кнопку выше",
|
||||
"emptyAllTitle": "Объявлений пока нет",
|
||||
"emptyAllSub": "Будьте первым — разместите объявление<br />о потере или находке",
|
||||
"searchPromptTitle": "Введите параметры поиска",
|
||||
"searchPromptSub": "Введите название или выберите город, чтобы найти объявление",
|
||||
"createPost": "Разместить объявление",
|
||||
"login": "Войти",
|
||||
"searchPlaceholder": "Поиск по названию или описанию...",
|
||||
|
||||
@@ -51,6 +51,8 @@ export default function MainFeed() {
|
||||
|
||||
const isSearchView = new URLSearchParams(location.search).get("view") === "search";
|
||||
const hasActiveFilters = searchQuery.trim().length > 0 || selectedCities.length > 0;
|
||||
const hasSearchParams = searchQuery.trim().length > 0 || selectedCities.length > 0;
|
||||
const searchPrompt = isSearchView && !hasSearchParams;
|
||||
|
||||
const feed = useFeedPosts();
|
||||
const myPosts = useMyPosts(user?.id);
|
||||
@@ -113,15 +115,24 @@ export default function MainFeed() {
|
||||
}
|
||||
}, [location.state]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
// Первичная загрузка ленты (дебаунс поиска), только когда нет фильтра по городам
|
||||
// Загрузка основной ленты (не в режиме поиска)
|
||||
useEffect(() => {
|
||||
if (selectedCities.length > 0) return;
|
||||
if (!isSearchView && selectedCities.length === 0 && !searchQuery.trim()) {
|
||||
feed.loadFeed(0, "", false);
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [isSearchView]);
|
||||
|
||||
// Дебаунс поиска: только когда в search view и есть параметры
|
||||
useEffect(() => {
|
||||
if (!isSearchView) return;
|
||||
if (!hasSearchParams) return;
|
||||
const timer = setTimeout(() => {
|
||||
feed.loadFeed(0, searchQuery, false);
|
||||
}, 400);
|
||||
return () => clearTimeout(timer);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [searchQuery, selectedCities]);
|
||||
}, [searchQuery, selectedCities, isSearchView]);
|
||||
|
||||
// Когда переключаемся на «Мои объявления» — подгружаем с бэкенда
|
||||
useEffect(() => {
|
||||
@@ -239,6 +250,7 @@ export default function MainFeed() {
|
||||
error={listError}
|
||||
filteredAds={filteredAds}
|
||||
activeNav={activeNav}
|
||||
searchPrompt={searchPrompt}
|
||||
liked={liked}
|
||||
likeCountAdj={likeCountAdj}
|
||||
onLike={actions.toggleLike}
|
||||
|
||||
Reference in New Issue
Block a user