deleted full likes
This commit is contained in:
@@ -3,19 +3,15 @@ import { useTranslation } from "react-i18next";
|
||||
import { API_URL } from "../config/authConstants";
|
||||
import { apiFetch } from "../api/apiClient";
|
||||
import { useAuthContext } from "../context/AuthContext";
|
||||
import { useFavorites } from "../hooks/useFavorites";
|
||||
import PostOnFeed from "../pages/PostOnFeed";
|
||||
import CloseIcon from "./icons/CloseIcon";
|
||||
|
||||
export default function PostDetailModal({ postId, onClose, onImageClick, onLocationClick, onAuthRequired }) {
|
||||
const { t } = useTranslation();
|
||||
const { user, isAuthenticated } = useAuthContext();
|
||||
const { toggleFavorite } = useFavorites();
|
||||
const { user } = useAuthContext();
|
||||
const [post, setPost] = useState(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState(null);
|
||||
const [liked, setLiked] = useState(false);
|
||||
const [likeCountAdj, setLikeCountAdj] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
if (!postId) return;
|
||||
@@ -30,8 +26,6 @@ export default function PostDetailModal({ postId, onClose, onImageClick, onLocat
|
||||
const data = await res.json();
|
||||
if (!cancelled) {
|
||||
setPost({ ...data, type: data.type ? data.type.toLowerCase() : "loss" });
|
||||
setLiked(!!data.liked);
|
||||
setLikeCountAdj(0);
|
||||
}
|
||||
} catch (e) {
|
||||
if (!cancelled) setError(e.message);
|
||||
@@ -44,21 +38,6 @@ export default function PostDetailModal({ postId, onClose, onImageClick, onLocat
|
||||
return () => { cancelled = true; };
|
||||
}, [postId]);
|
||||
|
||||
const handleLike = async (id) => {
|
||||
if (!isAuthenticated) {
|
||||
if (onAuthRequired) onAuthRequired();
|
||||
return;
|
||||
}
|
||||
const prev = liked;
|
||||
setLiked((v) => !v);
|
||||
setLikeCountAdj((v) => (prev ? v - 1 : v + 1));
|
||||
const result = await toggleFavorite(id);
|
||||
if (!result.success) {
|
||||
setLiked(prev);
|
||||
setLikeCountAdj((v) => (prev ? v + 1 : v - 1));
|
||||
}
|
||||
};
|
||||
|
||||
const isOwner = post && user && (post.authorId === user.id || post.userId === user.id);
|
||||
|
||||
return (
|
||||
@@ -82,9 +61,6 @@ export default function PostDetailModal({ postId, onClose, onImageClick, onLocat
|
||||
{post && (
|
||||
<PostOnFeed
|
||||
ad={post}
|
||||
liked={liked}
|
||||
likeCountAdj={likeCountAdj}
|
||||
onLike={handleLike}
|
||||
isOwner={isOwner}
|
||||
onImageClick={onImageClick}
|
||||
onLocationClick={onLocationClick}
|
||||
|
||||
@@ -16,7 +16,7 @@ export default function RightSidebar({ ads, profileData, isAuthenticated, onProf
|
||||
const { t } = useTranslation();
|
||||
|
||||
const suggestions = [...(ads || [])]
|
||||
.sort((a, b) => (b.likeCount || 0) - (a.likeCount || 0))
|
||||
.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))
|
||||
.slice(0, 4);
|
||||
|
||||
const profileName = isAuthenticated
|
||||
|
||||
@@ -44,7 +44,7 @@ export default function Sidebar({
|
||||
const HelpIcon = NavIcons.help;
|
||||
|
||||
const handleNavItem = (itemKey) => {
|
||||
if (!isAuthenticated && (itemKey === "myads" || itemKey === "favorites")) {
|
||||
if (!isAuthenticated && itemKey === "myads") {
|
||||
onLoginClick();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -13,9 +13,6 @@ export default function FeedContent({
|
||||
filteredAds,
|
||||
activeNav,
|
||||
searchPrompt,
|
||||
liked,
|
||||
likeCountAdj,
|
||||
onLike,
|
||||
onEdit,
|
||||
onDelete,
|
||||
onMarkFound,
|
||||
@@ -26,7 +23,7 @@ export default function FeedContent({
|
||||
t,
|
||||
}) {
|
||||
// Реклама вставляется только на главной ленте (showAds). useMemo — чтобы
|
||||
// при ре-рендерах (виждет-обновления, лайки и т.п.) позиции слотов не
|
||||
// при ре-рендерах (виджет-обновления и т.п.) позиции слотов не
|
||||
// пересчитывались и уже загруженные объявления не терялись.
|
||||
const feedItems = useMemo(
|
||||
() => withAds(filteredAds, showAds ? AD_EVERY : 0),
|
||||
@@ -66,9 +63,7 @@ export default function FeedContent({
|
||||
if (!filteredAds.length) {
|
||||
const emptyMsg = activeNav === "myads"
|
||||
? { title: t('feed.emptyMyAdsTitle'), sub: t('feed.emptyMyAdsSub') }
|
||||
: activeNav === "favorites"
|
||||
? { title: t('feed.emptyFavoritesTitle'), sub: t('feed.emptyFavoritesSub'), icon: "❤️" }
|
||||
: citySearchActive
|
||||
: citySearchActive
|
||||
? { title: t('feed.emptyCityTitle'), sub: t('feed.emptyCitySub') }
|
||||
: { title: t('feed.emptyAllTitle'), sub: t('feed.emptyAllSub') };
|
||||
|
||||
@@ -90,9 +85,6 @@ export default function FeedContent({
|
||||
<PostOnFeed
|
||||
key={item.data.id}
|
||||
ad={item.data}
|
||||
liked={liked.has(item.data.id)}
|
||||
likeCountAdj={likeCountAdj[item.data.id] || 0}
|
||||
onLike={onLike}
|
||||
onEdit={activeNav === "myads" ? onEdit : undefined}
|
||||
onDelete={activeNav === "myads" ? onDelete : undefined}
|
||||
onMarkFound={activeNav === "myads" ? onMarkFound : undefined}
|
||||
|
||||
Reference in New Issue
Block a user