deleted full likes

This commit is contained in:
SlimusMinus
2026-09-24 00:20:41 +03:00
parent 1d4c0c169c
commit 58352267fa
11 changed files with 18 additions and 265 deletions

View File

@@ -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}