deleted full likes
This commit is contained in:
@@ -26,7 +26,6 @@ import { useCityFeed } from "../hooks/useCityFeed";
|
||||
import { useInfiniteScroll } from "../hooks/useInfiniteScroll";
|
||||
import { useModals } from "../hooks/useModals";
|
||||
import { useFeedActions } from "../hooks/useFeedActions";
|
||||
import { useFavorites } from "../hooks/useFavorites";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useProfile } from "../hooks/useProfile";
|
||||
import { useFullscreenAdTrigger } from "../hooks/useFullscreenAdTrigger";
|
||||
@@ -56,7 +55,7 @@ type AnyAds = any[];
|
||||
export default function MainFeed() {
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const { user, token, isAuthenticated, updateUser } = useAuthContext() as {
|
||||
const { user, isAuthenticated, updateUser } = useAuthContext() as {
|
||||
user: {
|
||||
id?: number;
|
||||
name?: string;
|
||||
@@ -67,13 +66,11 @@ export default function MainFeed() {
|
||||
phone?: string;
|
||||
avatar?: string;
|
||||
} | null;
|
||||
token: string | null;
|
||||
isAuthenticated: boolean;
|
||||
updateUser: (data: unknown) => void;
|
||||
};
|
||||
const { fetchProfile } = useProfile();
|
||||
const { cities } = useCities() as { cities: string[]; loading: boolean; error: string };
|
||||
const { loadFavorites, loadFavoritePosts, error: favoritesError } = useFavorites();
|
||||
const { t } = useTranslation();
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const modals = useModals() as any;
|
||||
@@ -83,11 +80,7 @@ export default function MainFeed() {
|
||||
const [typeFilter, setTypeFilter] = useState<"loss" | "found" | null>(null);
|
||||
const [selectedCities, setSelectedCities] = useState<string[]>([]);
|
||||
const [searchQuery, setSearchQuery] = useState("");
|
||||
const [liked, setLiked] = useState<Set<number>>(new Set());
|
||||
const [likeCountAdj, setLikeCountAdj] = useState<Record<string, number>>({});
|
||||
const [favoritePosts, setFavoritePosts] = useState<AnyAds>([]);
|
||||
const profileFetchedFor = useRef<number | null>(null);
|
||||
const [favoritesLoading, setFavoritesLoading] = useState(false);
|
||||
|
||||
const feedRef = useRef<HTMLDivElement>(null);
|
||||
// Состояние ленты перед переходом на карту — чтобы вернуть юзера на то же место
|
||||
@@ -138,18 +131,11 @@ export default function MainFeed() {
|
||||
if (activeNav === "myads") {
|
||||
return Promise.resolve(myPosts.loadMyPosts());
|
||||
}
|
||||
if (activeNav === "favorites") {
|
||||
setFavoritesLoading(true);
|
||||
return loadFavoritePosts().then((posts: AnyAds) => {
|
||||
setFavoritePosts(posts);
|
||||
setFavoritesLoading(false);
|
||||
});
|
||||
}
|
||||
if (selectedCities.length > 0) {
|
||||
return cityFeed.searchCities(selectedCities);
|
||||
}
|
||||
return feed.loadFeed();
|
||||
}, [activeNav, myPosts, selectedCities, cityFeed, feed, loadFavoritePosts]);
|
||||
}, [activeNav, myPosts, selectedCities, cityFeed, feed]);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const actions = useFeedActions({
|
||||
@@ -158,8 +144,6 @@ export default function MainFeed() {
|
||||
onAuthRequired: () => modals.open("auth"),
|
||||
isAuthenticated,
|
||||
t,
|
||||
setLiked,
|
||||
setLikeCountAdj,
|
||||
} as any);
|
||||
|
||||
// ── «Стеклянная шапка»: закреплена наверху, высоту зоны затухания маски
|
||||
@@ -185,22 +169,6 @@ export default function MainFeed() {
|
||||
|
||||
const fadeHeight = measuredFade;
|
||||
|
||||
// Загружаем лайки пользователя при авторизации
|
||||
useEffect(() => {
|
||||
if (isAuthenticated && token) {
|
||||
loadFavorites().then((favoriteIds: number[]) => {
|
||||
const s = new Set(favoriteIds);
|
||||
actions.syncLiked(s);
|
||||
setLiked(s);
|
||||
});
|
||||
} else {
|
||||
actions.syncLiked(new Set());
|
||||
setLiked(new Set());
|
||||
}
|
||||
setLikeCountAdj({});
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [isAuthenticated, token, loadFavorites]);
|
||||
|
||||
// Открываем модалку аутентификации если пришли с лендинга
|
||||
useEffect(() => {
|
||||
if (location.state?.openAuth) {
|
||||
@@ -260,20 +228,6 @@ export default function MainFeed() {
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [activeNav, isAuthenticated, user?.id]);
|
||||
|
||||
// Загрузка избранных постов при переходе во вкладку «Избранное»
|
||||
useEffect(() => {
|
||||
if (activeNav !== "favorites") return;
|
||||
if (!isAuthenticated || !token) return;
|
||||
let cancelled = false;
|
||||
setFavoritesLoading(true);
|
||||
loadFavoritePosts().then((posts: AnyAds) => {
|
||||
if (cancelled) return;
|
||||
setFavoritePosts(posts);
|
||||
setFavoritesLoading(false);
|
||||
});
|
||||
return () => { cancelled = true; };
|
||||
}, [activeNav, isAuthenticated, token, loadFavoritePosts]);
|
||||
|
||||
const sentinelRef = useInfiniteScroll(
|
||||
() => feed.loadFeed(feed.page + 1, searchQuery, true),
|
||||
activeNav === "home" && selectedCities.length === 0 && feed.hasMore && !feed.loading && !feed.loadingMore
|
||||
@@ -368,8 +322,6 @@ export default function MainFeed() {
|
||||
let result: AnyAds;
|
||||
if (activeNav === "myads") {
|
||||
result = myPosts.myAds;
|
||||
} else if (activeNav === "favorites") {
|
||||
result = favoritePosts;
|
||||
} else if (selectedCities.length > 0) {
|
||||
result = cityFeed.cityAds;
|
||||
} else {
|
||||
@@ -386,18 +338,14 @@ export default function MainFeed() {
|
||||
result = result.filter(ad => ad.type === typeFilter);
|
||||
}
|
||||
return result;
|
||||
}, [activeNav, myPosts.myAds, favoritePosts, cityFeed.cityAds, feed.ads, selectedCities, typeFilter]);
|
||||
}, [activeNav, myPosts.myAds, cityFeed.cityAds, feed.ads, selectedCities, typeFilter]);
|
||||
|
||||
const listLoading = activeNav === "myads"
|
||||
? myPosts.loading
|
||||
: activeNav === "favorites"
|
||||
? favoritesLoading
|
||||
: feed.loading;
|
||||
: feed.loading;
|
||||
const listError = activeNav === "myads"
|
||||
? myPosts.error
|
||||
: activeNav === "favorites"
|
||||
? favoritesError
|
||||
: feed.error;
|
||||
: feed.error;
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -465,7 +413,7 @@ export default function MainFeed() {
|
||||
<PullToRefresh
|
||||
containerRef={feedRef}
|
||||
onRefresh={refreshCurrentList}
|
||||
disabled={isMapView || isSearchView || (activeNav !== "home" && activeNav !== "myads" && activeNav !== "favorites")}
|
||||
disabled={isMapView || isSearchView || (activeNav !== "home" && activeNav !== "myads")}
|
||||
/>
|
||||
<FeedContent
|
||||
loading={listLoading}
|
||||
@@ -476,9 +424,6 @@ export default function MainFeed() {
|
||||
activeNav={activeNav}
|
||||
searchPrompt={searchPrompt}
|
||||
showAds={showAds}
|
||||
liked={liked}
|
||||
likeCountAdj={likeCountAdj}
|
||||
onLike={actions.toggleLike}
|
||||
onEdit={handleEdit}
|
||||
onDelete={actions.handleDelete}
|
||||
onMarkFound={actions.handleMarkFound}
|
||||
|
||||
Reference in New Issue
Block a user