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}
|
||||
|
||||
Reference in New Issue
Block a user